private CanvasGestureSource(string serialNumber, EGesture gestureType) : base(getID(serialNumber, gestureType), getDisplayName(gestureType), getCategory(serialNumber)) { Communication.StaticOnGestureEvent += ExternalControlEndpoint_StaticOnGestureEvent; SerialNumber = serialNumber; GestureType = gestureType; CurrentValue = beatValue; }
// Use this for initialization void Start () { loseTime = 0; score = 0; started = false; deathChallenge = false; lastChange = Time.time; // not actually an EGesture value. BUT, it works passably as "no-value". currentGesture = (EGesture)100; challengeGestures = new EGesture[challengeIcons.Length]; challengePanel.SetActive (false); normalPanel.SetActive (false); print (Input.GetJoystickNames () [0]); }
private static string getDisplayName(EGesture part) { return(part.ToString()); }
private static string getID(string serialNumber, EGesture part) { return($"Nanoleaf-{serialNumber}-Gesture:{part}"); }
private void wm_WiiMoteChanged(object sender, WiiMoteChangedEventArgs args) { if (!_Active) { return; } WiiMoteStatus ws = args.WiiMoteState; Point p = ws.IRState.Position; p.X = 1023 - p.X; //key events bool alt = false; bool shift = false; bool ctrl = false; bool pressed = false; char unicode = char.MinValue; EGesture gesture = _Gesture.GetGesture(p); bool lb = false; bool rb = gesture == EGesture.Back; Keys key = Keys.None; if (ws.ButtonState.A && !_ButtonStates[0]) { lb = true; } else if (ws.ButtonState.B && !_ButtonStates[1]) { _Gesture.SetLockPosition(p); } else if (!ws.ButtonState.B && _ButtonStates[1]) { _Gesture.Reset(); } else if (ws.ButtonState.Down && !_ButtonStates[2]) { key = Keys.Right; } else if (ws.ButtonState.Up && !_ButtonStates[3]) { key = Keys.Left; } else if (ws.ButtonState.Left && !_ButtonStates[4]) { key = Keys.Down; } else if (ws.ButtonState.Right && !_ButtonStates[5]) { key = Keys.Up; } else if (ws.ButtonState.Home && !_ButtonStates[6]) { key = Keys.Space; } else if (ws.ButtonState.Minus && !_ButtonStates[7]) { key = Keys.PageDown; } else if (ws.ButtonState.Plus && !_ButtonStates[8]) { key = Keys.PageUp; } else if (ws.ButtonState.One && !_ButtonStates[9]) { key = Keys.Enter; } else if (ws.ButtonState.Two && !_ButtonStates[10]) { key = Keys.Escape; } _ButtonStates[0] = ws.ButtonState.A; _ButtonStates[1] = ws.ButtonState.B; _ButtonStates[2] = ws.ButtonState.Down; _ButtonStates[3] = ws.ButtonState.Up; _ButtonStates[4] = ws.ButtonState.Left; _ButtonStates[5] = ws.ButtonState.Right; _ButtonStates[6] = ws.ButtonState.Home; _ButtonStates[7] = ws.ButtonState.Minus; _ButtonStates[8] = ws.ButtonState.Plus; _ButtonStates[9] = ws.ButtonState.One; _ButtonStates[10] = ws.ButtonState.Two; if (alt || shift || ctrl || pressed || unicode != char.MinValue || key != Keys.None) { KeyEvent pool = new KeyEvent(ESender.WiiMote, alt, shift, ctrl, pressed, unicode, key); lock (_KeyCopyLock) { _KeysPool.Add(pool); } } //mouse events float reducing = 0.15f; float factor = 1f / (1f - reducing * 2f); float rx = (((float)p.X / 1024f) - reducing) * factor; float ry = (((float)p.Y / 768f) - reducing) * factor; int x = (int)(rx * (float)CSettings.iRenderW); int y = (int)(ry * (float)CSettings.iRenderH); bool ld = false; bool lbh = !lb && ws.ButtonState.A; bool rbh = false; bool mb = false; bool mbh = false; int wheel = 0; if (gesture == EGesture.ScrollUp) { wheel = -1; } if (gesture == EGesture.ScrollDown) { wheel = 1; } MouseEvent mpool = new MouseEvent(); bool trigger = false; if (!lb && !rb && (p.X != _OldPosition.X || p.Y != _OldPosition.Y)) { mpool = new MouseEvent(ESender.WiiMote, alt, shift, ctrl, x, y, false, false, false, wheel, lbh, rbh, false, mbh); trigger = true; } else if (lb || rb) { mpool = new MouseEvent(ESender.WiiMote, alt, shift, ctrl, x, y, lb, ld, rb, wheel, false, false, mb, false); trigger = true; } if (trigger) { lock (_MouseCopyLock) { _MousePool.Add(mpool); } } _OldPosition.X = p.X; _OldPosition.Y = p.Y; }
// Update is called once per frame void Update () { if (Input.GetKeyDown ("joystick button 6")) { SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex); } if (!started) { if (Input.GetKeyDown ("joystick button 7")) { started = true; int livingPlayers = 0; foreach (GameObject p in players) { PlayerKillController killer = p.GetComponent<PlayerKillController> (); if (!killer.playing) { killer.gameObject.SetActive (false); } else { livingPlayers += 1; } } winThreshold = 45 + (30 * livingPlayers); scoreDisplay.text = score + " / " + winThreshold; GetComponent<AudioSource> ().Play (); startScreen.SetActive (false); normalPanel.SetActive (true); lastChange = Time.time; startTime = Time.time; currentGesture = RandomGesture (EGesture.Forward); nextGesture = RandomGesture (currentGesture); ShowGesture (currentGestureIcon, currentGesture); } } else if (!won) { timeDisplay.text = Mathf.Ceil (60 - Time.time + startTime) + "s"; if (loseTime != 0) { if (loseTime + 3f < Time.time) { SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex); } } else if (deathChallenge) { HandleDeathMode (); } else { HandleNormalMode (); } } else { if (Input.GetKeyDown ("joystick button 7")) { SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex); } } }
EGesture RandomGesture(EGesture lastGesture = EGesture.Down) { EGesture gesture; do { gesture = (EGesture)Random.Range (0, System.Enum.GetValues (typeof(EGesture)).Length); } while (gesture == lastGesture); return gesture; }
string GetGestureText(EGesture gesture) { switch (gesture) { case EGesture.Forward: return "A"; case EGesture.Wide: return "B"; case EGesture.Middle: return "X"; case EGesture.Down: return "Y"; default: return "?"; } }
Color32 GetGestureColor(EGesture gesture, byte alpha = 255) { switch (gesture) { case EGesture.Forward: return new Color32 (0, 255, 33, alpha); case EGesture.Wide: return new Color32 (255, 33, 0, alpha); case EGesture.Middle: return new Color32 (0, 0, 255, alpha); case EGesture.Down: return new Color32 (200, 160, 0, alpha); default: return new Color32 (0, 0, 0, alpha); } }
void ShowGesture(GameObject icon, EGesture gesture, byte alpha = 255) { icon.GetComponent<Image>().color = GetGestureColor(gesture, alpha); icon.GetComponentInChildren<Text> ().text = GetGestureText (gesture); icon.GetComponentInChildren<Text> ().color = new Color32 (0, 0, 0, alpha); }
void HandleNormalMode() { int matchCount = 0; int livingPlayers = 0; foreach (GameObject p in players) { if (p.activeInHierarchy) { GestureScript playerScript = p.GetComponent<GestureScript> (); if (playerScript.GetGesture () == currentGesture) { matchCount += 1; } livingPlayers += 1; } } if (livingPlayers == 0) { loseTime = Time.time; } if (matchCount == livingPlayers || lastChange + changeDelay < Time.time) { score += matchCount; scoreDisplay.text = score + " / " + winThreshold; patternRound++; lastChange = Time.time; foreach (GameObject p in players) { if (p.activeInHierarchy) { GestureScript playerScript = p.GetComponent<GestureScript> (); if (playerScript.GetGesture () != currentGesture) { deathChallenge = true; } } } if (deathChallenge) { challengePanel.SetActive (true); normalPanel.SetActive (false); foreach (GameObject p in players) { p.GetComponent<GestureScript> ().StartDeathChallenge (); } for (int i = 0; i < challengeGestures.Length; ++i) { EGesture lastGesture = i == 0 ? currentGesture : challengeGestures [i - 1]; challengeGestures [i] = RandomGesture (lastGesture); ShowGesture (challengeIcons [i], challengeGestures [i]); } } currentGesture = nextGesture; nextGesture = RandomGesture (currentGesture); ShowGesture (currentGestureIcon, currentGesture); } if (score >= winThreshold) { Win (); } // update this every frame so that we can fade it in (with alpha) ShowGesture (nextGestureIcon, nextGesture, (byte)(255 * (Time.time - lastChange) / changeDelay)); }
private void _WmWiiMoteChanged(object sender, CWiiMoteChangedEventArgs args) { if (!_Active) { return; } CWiiMoteStatus ws = args.WiiMoteState; Point p = ws.IRState.Position; p.X = 1023 - p.X; EGesture gesture = _Gesture.GetGesture(p); bool lb = false; bool rb = gesture == EGesture.Back; var key = Keys.None; if (ws.ButtonState.A && !_ButtonStates[0]) { lb = true; } else if (ws.ButtonState.B && !_ButtonStates[1]) { _Gesture.SetLockPosition(p); } else if (!ws.ButtonState.B && _ButtonStates[1]) { _Gesture.Reset(); } else if (ws.ButtonState.Down && !_ButtonStates[2]) { key = Keys.Right; } else if (ws.ButtonState.Up && !_ButtonStates[3]) { key = Keys.Left; } else if (ws.ButtonState.Left && !_ButtonStates[4]) { key = Keys.Down; } else if (ws.ButtonState.Right && !_ButtonStates[5]) { key = Keys.Up; } else if (ws.ButtonState.Home && !_ButtonStates[6]) { key = Keys.Space; } else if (ws.ButtonState.Minus && !_ButtonStates[7]) { key = Keys.Subtract; } else if (ws.ButtonState.Plus && !_ButtonStates[8]) { key = Keys.Add; } else if (ws.ButtonState.One && !_ButtonStates[9]) { key = Keys.Enter; } else if (ws.ButtonState.Two && !_ButtonStates[10]) { key = Keys.Escape; } _ButtonStates[0] = ws.ButtonState.A; _ButtonStates[1] = ws.ButtonState.B; _ButtonStates[2] = ws.ButtonState.Down; _ButtonStates[3] = ws.ButtonState.Up; _ButtonStates[4] = ws.ButtonState.Left; _ButtonStates[5] = ws.ButtonState.Right; _ButtonStates[6] = ws.ButtonState.Home; _ButtonStates[7] = ws.ButtonState.Minus; _ButtonStates[8] = ws.ButtonState.Plus; _ButtonStates[9] = ws.ButtonState.One; _ButtonStates[10] = ws.ButtonState.Two; if (key != Keys.None) { AddKeyEvent(new SKeyEvent(ESender.WiiMote, false, false, false, false, char.MinValue, key)); } //mouse events const float reducing = 0.15f; const float factor = 1f / (1f - reducing * 2f); float rx = ((p.X / 1024f) - reducing) * factor; float ry = ((p.Y / 768f) - reducing) * factor; var x = (int)(rx * CSettings.RenderW); var y = (int)(ry * CSettings.RenderH); bool lbh = !lb && ws.ButtonState.A; int wheel = 0; if (gesture == EGesture.ScrollUp) { wheel = -1; } if (gesture == EGesture.ScrollDown) { wheel = 1; } if (!lb && !rb && (p.X != _OldPosition.X || p.Y != _OldPosition.Y)) { AddMouseEvent(new SMouseEvent(ESender.WiiMote, EModifier.None, x, y, false, false, false, wheel, lbh, false, false, false)); } else if (lb || rb) { AddMouseEvent(new SMouseEvent(ESender.WiiMote, EModifier.None, x, y, lb, false, rb, wheel, false, false, false, false)); } _OldPosition.X = p.X; _OldPosition.Y = p.Y; }