private void Start() { JoyStickEvent joyStickEvent = m_MoveRect.GetComponent <JoyStickEvent>(); if (joyStickEvent == null) { joyStickEvent = m_MoveRect.gameObject.AddComponent <JoyStickEvent>(); } joyStickEvent.pointerDownHandler = OnPointerDown; joyStickEvent.beginDragHandler = BeginDrag; joyStickEvent.dragHandler = OnDrag; joyStickEvent.pointerUpHandler = OnPointerUp; m_BackgroundRect.GetWorldCorners(m_BackgroundRectCorners); Canvas canvas = m_Joystick.GetComponentInParent <Canvas>(); m_UiCamera = canvas.worldCamera; //半径 = (摇杆底部宽度的一半 - 摇杆宽度的一半) * 缩放系数 m_JoystickMoveRadius = (m_BackGround.rect.width * 0.5f - m_Joystick.rect.width * 0.5f) * m_JoystickRadiusFactor; m_JoyStickDefaultPosition = m_BackGround.transform.localPosition; if (m_Direction && m_Direction.gameObject.activeSelf) { m_Direction.gameObject.SetActive(false); } m_Initalize = true; }
static bool PovMoved(JoyStickEvent arg, int pov) { Console.Write("\n" + arg.device.Vendor() + ". POV" + pov + " "); if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.North) != 0) //Going up { Console.Write("North"); } else if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.South) != 0) //Going down { Console.Write("South"); } if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.East) != 0) //Going right { Console.Write("East"); } else if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.West) != 0) //Going left { Console.Write("West"); } if (arg.state.get_mPOV(pov).direction == Pov_NativePtr.Centered) //stopped/centered out { Console.Write("Centered"); } return(true); }
static bool AxisMoved(JoyStickEvent arg, int axis) { //Provide a little dead zone Axis_NativePtr axiscls = arg.state.GetAxis(axis); if (axiscls.abs > 2500 || axiscls.abs < -2500) Console.Write("\n" + arg.device.Vendor() + ". Axis # " + axis + " Value: " + axiscls.abs); return true; }
static bool Vector3Moved(JoyStickEvent arg, int index) { Vector3 vec = arg.state.GetVector(index); Console.Write("\n" + arg.device.Vendor() + ". Orientation # " + index + " X Value: " + vec.x + " Y Value: " + vec.y + " Z Value: " + vec.z); return(true); }
static bool AxisMoved(JoyStickEvent arg, int axis) { //Provide a little dead zone Axis_NativePtr axiscls = arg.state.GetAxis(axis); if (axiscls.abs > 2500 || axiscls.abs < -2500) { Console.Write("\n" + arg.device.Vendor() + ". Axis # " + axis + " Value: " + axiscls.abs); } return(true); }
bool joystick_ButtonReleased(JoyStickEvent arg, int button) { if (button.Equals(KeyMap.Instance.JoystickEscape)) { CloseControlChangeWindow(); return(false); } String langKey = GetLanguageKeyById(currentKeyId); // check for conflicts bool noconflict = true; string property = null; // keys if (langKey.Equals(LanguageKey.Engine)) { property = "JoystickEngine"; } if (langKey.Equals(LanguageKey.Gear)) { property = "JoystickGear"; } if (langKey.Equals(LanguageKey.Gun)) { property = "JoystickGun"; } if (langKey.Equals(LanguageKey.Bombs)) { property = "JoystickRocket"; } if (langKey.Equals(LanguageKey.Spin)) { property = "JoystickSpin"; } if (langKey.Equals(LanguageKey.Camera)) { property = "JoystickCamera"; } if (langKey.Equals(LanguageKey.BulletTimeEffect)) { property = "JoystickBulletiTimeEffect"; } if (langKey.Equals(LanguageKey.Back)) { property = "JoystickEscape"; } if (langKey.Equals(LanguageKey.OK)) { property = "JoystickEnter"; } if (property == null) { return(false); } String[] exceptions; if (!langKey.Equals(LanguageKey.OK) && !langKey.Equals(LanguageKey.Back)) { exceptions = new String[] { "JoystickEscape", "JoystickEnter" }; } else { exceptions = new String[] { "JoystickEscape", "JoystickEnter" }; } if (!langKey.Equals(LanguageKey.Pitch) && !langKey.Equals(LanguageKey.AccelerateBreakTurn)) { KeyMap.ClearOtherControlsWithSameKey(property, button, TypeOfControl.Joystick, exceptions); KeyMap.UpdateProperty(property, button, TypeOfControl.Joystick); } CloseControlChangeWindow(); // notify parent to refresh if (onControlsChanged != null) { onControlsChanged(); } return(true); }
bool joystick_ButtonPressed(JoyStickEvent arg, int button) { return(true); }
static bool JoyButtonPressed(JoyStickEvent arg, int button) { Console.Write("\n" + arg.device.Vendor() + ". Button Pressed # " + button); return(true); }
private void Joy_OnKey(object sender, JoyStickEvent key) { switch (key.key) { case JoyKey.RUP: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.BodyUp(); } }); break; case JoyKey.RDOWN: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.BodyDown(); } }); break; case JoyKey.RLEFT: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { }); break; case JoyKey.RRIGHT: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { }); break; case JoyKey.L1: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartRotage(true); } else { motion.EndRotage(); } }); break; case JoyKey.R1: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartRotage(false); } else { motion.EndRotage(); } }); break; case JoyKey.LUP: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartWalk1(WalkDirection.Up); } else { motion.EndWalk1(); } }); break; case JoyKey.LDOWN: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartWalk1(WalkDirection.Down); } else { motion.EndWalk1(); } }); break; case JoyKey.LLEFT: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartWalk1(WalkDirection.Left); } else { motion.EndWalk1(); } }); break; case JoyKey.LRIGHT: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.StartWalk1(WalkDirection.Right); } else { motion.EndWalk1(); } }); break; case JoyKey.Start: Application.Current.Dispatcher.BeginInvoke((Action) delegate() { if (key.Value == 128) { motion.TestLeg(); } //motion.Cal90Up(); }); break; } }
static bool Vector3Moved(JoyStickEvent arg, int index) { Vector3 vec = arg.state.GetVector(index); Console.Write("\n" + arg.device.Vendor() + ". Orientation # " + index + " X Value: " + vec.x + " Y Value: " + vec.y + " Z Value: " + vec.z); return true; }
static bool PovMoved(JoyStickEvent arg, int pov) { Console.Write("\n" + arg.device.Vendor() + ". POV" + pov + " "); if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.North) != 0) //Going up Console.Write("North"); else if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.South) != 0) //Going down Console.Write("South"); if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.East) != 0) //Going right Console.Write("East"); else if ((arg.state.get_mPOV(pov).direction & Pov_NativePtr.West) != 0) //Going left Console.Write("West"); if (arg.state.get_mPOV(pov).direction == Pov_NativePtr.Centered) //stopped/centered out Console.Write("Centered"); return true; }
static bool JoyButtonReleased(JoyStickEvent arg, int button) { Console.Write("\n" + arg.device.Vendor() + ". Button Released # " + button); return true; }