-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
public class ControllerTestScript : MonoBehaviour { | ||
|
||
private int m_id; | ||
private HFTGamepad m_gamepad; | ||
private static Dictionary<int, bool> s_ids= new Dictionary<int, bool>(); | ||
// private HFTInput m_hftInput; | ||
|
||
void Start () | ||
{ | ||
// Find an empty id; | ||
bool foo = false; | ||
for (int ii = 0; ii < 1000; ++ii) { | ||
if (!s_ids.TryGetValue(ii, out foo)) { | ||
m_id = ii; | ||
s_ids[ii] = true; | ||
break; | ||
} | ||
} | ||
|
||
m_gamepad = GetComponent<HFTGamepad>(); | ||
// m_hftInput = GetComponent<HFTInput>(); | ||
m_gamepad.NetPlayer.OnDisconnect += OnDisconnect; | ||
} | ||
|
||
void OnDisconnect(object sender, System.EventArgs args) | ||
{ | ||
s_ids.Remove(m_id); | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
int unitWidth = 20; | ||
int unitHeight = 20; | ||
int xx = 10 + 110 * m_id; | ||
int yy = 10; | ||
GUI.Box(new Rect(xx, 10, 100, unitHeight), m_gamepad.Name); | ||
yy += unitHeight; | ||
GUI.Box(new Rect(xx, yy, 100, unitHeight), "buttons"); | ||
yy += unitHeight; | ||
for (int ii = 0; ii < m_gamepad.buttons.Length; ++ii) { | ||
int x = ii % 4; | ||
int y = ii / 4; | ||
GUI.Box(new Rect(xx + x * unitWidth, yy + y * unitHeight, unitWidth, unitHeight), m_gamepad.buttons[ii].pressed ? "*" : ""); | ||
} | ||
yy += unitHeight * ((m_gamepad.buttons.Length + 3) / 4); | ||
|
||
GUI.Box(new Rect(xx, yy, 100, unitHeight), "axes"); | ||
yy += unitHeight; | ||
for (int ii = 0; ii < m_gamepad.axes.Length; ++ii) { | ||
int x = ii % 4; | ||
int y = ii / 4; | ||
GUI.Box(new Rect(xx + x * unitWidth, yy + y * unitHeight, unitWidth, unitHeight), m_gamepad.axes[ii].ToString()); | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class SoundTest : MonoBehaviour { | ||
|
||
void Awake () | ||
{ | ||
m_soundPlayer = GetComponent<HFTSoundPlayer>(); | ||
} | ||
|
||
void Start() | ||
{ | ||
StartCoroutine("Play"); | ||
} | ||
|
||
IEnumerator Play() | ||
{ | ||
while (true) | ||
{ | ||
yield return new WaitForSeconds(1.0f); | ||
m_soundPlayer.PlaySound("explosion"); | ||
yield return new WaitForSeconds(1.0f); | ||
m_soundPlayer.PlaySound("gameover"); | ||
yield return new WaitForSeconds(1.0f); | ||
m_soundPlayer.PlaySound("launch"); | ||
} | ||
} | ||
|
||
private HFTSoundPlayer m_soundPlayer; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using HappyFunTimes; | ||
using HFTSounds; | ||
using UnityEngine; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
public class HFTGlobalSoundHelper : MonoBehaviour { | ||
|
||
public static Sounds GetSounds() { | ||
return s_sounds; | ||
} | ||
|
||
void Awake() | ||
{ | ||
if (s_sounds == null) { | ||
InitSounds(); | ||
} | ||
} | ||
|
||
void InitSounds() | ||
{ | ||
s_sounds = new Sounds(); | ||
string baseFolder = Path.Combine(Path.Combine(Application.dataPath, "WebPlayerTemplates"), "HappyFunTimes"); | ||
string soundFolder = Path.Combine(baseFolder, "sounds"); | ||
if (Directory.Exists(soundFolder)) { | ||
AddSoundFiles(baseFolder, Directory.GetFiles(soundFolder, "*.mp3")); | ||
AddSoundFiles(baseFolder, Directory.GetFiles(soundFolder, "*.wav")); | ||
} | ||
} | ||
|
||
void AddSoundFiles(string baseFolder, string[] filenames) | ||
{ | ||
foreach(string filename in filenames) | ||
{ | ||
string filepath = filename.Substring(baseFolder.Length + 1).Replace("\\", "/"); | ||
s_sounds[Path.GetFileNameWithoutExtension(filename)] = new SoundFile(filepath); | ||
} | ||
} | ||
|
||
private static Sounds s_sounds = null; | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using HappyFunTimes; | ||
using HFTSounds; | ||
using UnityEngine; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
[RequireComponent (typeof (HFTGamepad))] | ||
public class HFTSoundPlayer : MonoBehaviour { | ||
|
||
private class MessageLoadSounds : MessageCmdData { | ||
public MessageLoadSounds(Sounds _sounds) { | ||
sounds = _sounds; | ||
} | ||
public Sounds sounds = null; | ||
} | ||
|
||
private class MessagePlaySound : MessageCmdData { | ||
public MessagePlaySound(string _name, bool _loop = false) { | ||
name = _name; | ||
loop = _loop; | ||
} | ||
public string name; | ||
public bool loop; | ||
} | ||
|
||
void Awake() | ||
{ | ||
try { | ||
HFTGlobalSoundHelper.GetSounds(); | ||
} catch (System.Exception) { | ||
Debug.LogError("No HFTGlobalSoundHelper in scene. Please add one"); | ||
} | ||
m_gamepad = GetComponent<HFTGamepad>(); | ||
} | ||
|
||
void Start() | ||
{ | ||
m_gamepad.NetPlayer.SendCmd("loadSounds", new MessageLoadSounds(HFTGlobalSoundHelper.GetSounds())); | ||
} | ||
|
||
public void PlaySound(string name, bool loop = false) | ||
{ | ||
m_gamepad.NetPlayer.SendCmd("playSound", new MessagePlaySound(name, loop)); | ||
} | ||
|
||
private HFTGamepad m_gamepad; | ||
|
||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.