public static bool GetTouch() { if (AndroidInput.touchCountSecondary > 0) { UnityEngine.Touch touch = AndroidInput.GetSecondaryTouch(0); return(touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary); } else { return(false); } }
public static bool GetTouchUp() { if (AndroidInput.touchCountSecondary > 0) { UnityEngine.Touch touch = AndroidInput.GetSecondaryTouch(0); return(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled); } else { return(false); } }
public static bool GetTouchDown() { if (AndroidInput.touchCountSecondary > 0) { UnityEngine.Touch touch = AndroidInput.GetSecondaryTouch(0); return(touch.phase == TouchPhase.Began); } else { return(false); } }
public static bool GetKutiButtonUp(EKutiButton button) { if (AndroidInput.isInitialized) { return(AndroidInput.GetKutiButtonUp(button)); } #if !ANDROID if (Input.GetKeyUp(GetButtonMapping(button))) { return(true); } #endif return(false); }
public override void OnEnter() { #if UNITY_ANDROID Touch touch = AndroidInput.GetSecondaryTouch(index.Value); if (!position.IsNone) { position.Value = touch.position; } if (!deltaPosition.IsNone) { deltaPosition.Value = touch.deltaPosition; } if (!deltaTime.IsNone) { deltaTime.Value = touch.deltaTime; } if (!tapCount.IsNone) { tapCount.Value = touch.tapCount; } #endif Finish(); }
static Vector2 GetStick(float zeroX, float zeroY) // Result has a magnitude of max 1. X -1 is left, +1 is right. Y -1 is down, +1 is up. { if (AndroidInput.secondaryTouchEnabled && KeypadAvailable) { for (int i = 0; i < AndroidInput.touchCountSecondary; i++) { Vector2 touchPosition = AndroidInput.GetSecondaryTouch(i).position; if (touchPosition.x < zeroX || touchPosition.x > zeroX + AndroidInput.secondaryTouchHeight) { continue; } return(new Vector2( ((touchPosition.x - zeroX) / AndroidInput.secondaryTouchHeight) * 2.0f - 1.0f, // Height is the radius, so we use that for X as well (((touchPosition.y - zeroY) / AndroidInput.secondaryTouchHeight) * 2.0f - 1.0f) * -1.0f )); } } return(Vector2.zero); }
private void SetInputBasedOnPlatform() { IGameInput gameInput; #if UNITY_ANDROID gameInput = new AndroidInput(this.acceleratorPedal, this.leftButton, this.rightButton, this.brakeButton); #endif #if UNITY_STANDALONE gameInput = new PcInput(); #endif #if UNITY_EDITOR gameInput = new PcInput(); #endif foreach (var system in this.entityManager.World.Systems) { if (system is InputSystem inputSystem) { inputSystem.GameInput = gameInput; inputSystem.InputSnapshots = this.InputSnapshots = new InputSnapshots(); } } }
public void Update() { if (!pl) { return; } padTouch.enabled = pad.enabled = Loader.controls == Contr.mouse; rocketLauncher.enabled = _Player.curWeapon.bullets > 0; bool keys = Loader.controls == Contr.keys; left.enabled = right.enabled = keys; //nitro.enabled = pl.nitro > 0; //Log("Android Mouse " + mouse + " Taps" + Input.touchCount); mouse = Vector3.Lerp(mouse, Vector3.zero, Time.deltaTime * 10); bool padDown = false; if (Loader.controls == Contr.acel) { mouse = new Vector2(Mathf.Clamp(Input.acceleration.x * 2, -1, 1), 0); } else if (Loader.controls == Contr.mouse) { foreach (var touch in Input.touches) { Vector3 mpos = touch.position; Vector3 pp = pad.inversePos; pp.x *= Screen.width; pp.y *= Screen.height; if (mpos.x < Screen.width / 2f && pp.x < Screen.width / 2f || mpos.x > Screen.width / 2f && pp.x > Screen.width / 2f) { Vector3 mouseTmp = (pp - mpos) / (pad.size.x / 2f) * (InputManager.secondPlayer ? 1 : -1); mouseTmp.x = Mathf.Clamp(mouseTmp.x, -1, 1); mouseTmp.y = Mathf.Clamp(mouseTmp.y, -1, 1); if (!InputManager.splitScreen || mpos.y > Screen.height / 2f && InputManager.secondPlayer || mpos.y < Screen.height / 2f && !InputManager.secondPlayer) { mouse = mouseTmp; padTouch.screenPos = mpos; padDown = true; } } } #if UNITY_ANDROID if (AndroidInput.secondaryTouchEnabled && AndroidInput.touchCountSecondary > 0) { Vector2 p = AndroidInput.GetSecondaryTouch(0).position; p.x /= AndroidInput.secondaryTouchWidth; p.x -= .5f; p.x = Mathf.Clamp(p.x * 2, -1, 1); mouse = p; } #endif if (!padDown) { padTouch.tr.position = pad.tr.position; } } if (_Game.editControls) { if (Input.touchCount == 1) { foreach (KeyHudBool a in dict.Values) { Touch?touch = HitTest(a); if (touch != null) { last = a; Vector2 mpos = touch.Value.position; mpos = camera.ScreenToViewportPoint(mpos); a.archor.inversePos = mpos; a.posx = mpos.x; a.posy = mpos.y; } } } else if (last != null) { last.scale += GetDoubleTouch() * 0.01f; last.scale = Mathf.Max(.7f, last.scale); last.UpdateScale(); } } if (!_Game.editControls) { if (keys && !InputManager.splitScreen) { foreach (KeyHudBool a in dict.Values) { a.hitTest = null; } foreach (Touch b in touches) { Vector2 pos = b.position; pos.x /= Screen.width; pos.y /= Screen.height; KeyHudBool d = FirstOrDefault(pos); //print(d.guitext.name); if (d != null) { d.hitTest = b; } } } else { foreach (KeyHudBool a in dict.Values) { a.hitTest = HitTest(a); } } foreach (KeyHudBool a in dict.Values) { TouchPhase ph = a.hitTest.HasValue ? a.hitTest.Value.phase : ((TouchPhase)221); a.hold = ph == TouchPhase.Stationary || ph == TouchPhase.Moved; a.up = ph == TouchPhase.Canceled || ph == TouchPhase.Ended; a.down = ph == TouchPhase.Began; if (!InputManager.splitScreen) { a.hudColor = padDown && a.archor == pad || a.hold ? Color.white : Color.white / 2f; } } } }
// The input mapping here is preliminary and subject to change.. void OnGUI() { if (GUILayout.Button("Exit")) { Application.LoadLevel(0); } if (Input.GetKey(KeyCode.LeftShift)) { GUI.Button(new Rect(0.2f * scr_w, 0.1f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.LeftShift"); } if (Input.GetKey(KeyCode.RightShift)) { GUI.Button(new Rect(0.6f * scr_w, 0.1f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.RightShift"); } if (Input.GetKey(KeyCode.UpArrow)) { GUI.Button(new Rect(0.2f * scr_w, 0.2f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.UpArrow"); } if (Input.GetKey(KeyCode.LeftArrow)) { GUI.Button(new Rect(0.1f * scr_w, 0.3f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.LeftArrow"); } if (Input.GetKey(KeyCode.RightArrow)) { GUI.Button(new Rect(0.3f * scr_w, 0.3f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.RightArrow"); } if (Input.GetKey(KeyCode.DownArrow)) { GUI.Button(new Rect(0.2f * scr_w, 0.4f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.DownArrow"); } if (Input.GetKey("joystick button 2")) { GUI.Button(new Rect(0.6f * scr_w, 0.2f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "\"joystick button 2\""); } if (Input.GetKey("joystick button 1")) { GUI.Button(new Rect(0.5f * scr_w, 0.3f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "\"joystick button 1\""); } if (Input.GetKey("joystick button 3")) { GUI.Button(new Rect(0.7f * scr_w, 0.3f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "\"joystick button 3\""); } if (Input.GetKey("joystick button 0")) { GUI.Button(new Rect(0.6f * scr_w, 0.4f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "\"joystick button 0\""); } if (Input.GetKey(KeyCode.F2)) { GUI.Button(new Rect(0.8f * scr_w, 0.1f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.F2"); } if (Input.GetKey(KeyCode.Menu)) { GUI.Button(new Rect(0.8f * scr_w, 0.3f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.Menu"); } if (Input.GetKey(KeyCode.Escape)) { GUI.Button(new Rect(0.8f * scr_w, 0.7f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.Escape"); } if (Input.GetKey(KeyCode.Menu)) { GUI.Button(new Rect(0.2f * scr_w, 0.8f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.Menu"); } if (Input.GetKey(KeyCode.Pause)) { GUI.Button(new Rect(0.4f * scr_w, 0.8f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.Pause"); } if (Input.GetKey(KeyCode.Return)) { GUI.Button(new Rect(0.6f * scr_w, 0.8f * scr_h, 0.2f * scr_w, 0.1f * scr_h), "KeyCode.Return"); } for (int i = 0; i < Input.touchCount; ++i) { Touch touch = Input.GetTouch(i); GUI.Button(new Rect((touch.position.x - 120.0f), (scr_h - touch.position.y - 85.0f), 150.0f, 20.0f), "GetTouch(" + i + ")"); } if (!AndroidInput.secondaryTouchEnabled) { return; } // Based on http://developer.android.com/reference/android/content/res/Configuration.html const int NAVIGATIONHIDDEN_UNDEFINED = 0; const int NAVIGATIONHIDDEN_NO = 1; const int NAVIGATIONHIDDEN_YES = 2; string nav_str = null; int nav = currentConfig.Get <int>("navigationHidden"); if (nav == NAVIGATIONHIDDEN_NO) { nav_str = "NAVIGATIONHIDDEN_NO"; } else if (nav == NAVIGATIONHIDDEN_YES) { nav_str = "NAVIGATIONHIDDEN_YES"; } if (nav != NAVIGATIONHIDDEN_UNDEFINED) { GUI.Button(new Rect(0.35f * scr_w, 0.0f * scr_h, 0.3f * scr_w, 0.1f * scr_h), nav_str); } GUILayout.Label("Pad W: " + pad_w); GUILayout.Label("Pad H: " + pad_h); for (int i = 0; i < AndroidInput.touchCountSecondary; ++i) { Touch touch = AndroidInput.GetSecondaryTouch(i); // normalize float x = touch.position.x / pad_w; float y = touch.position.y / pad_h; GUILayout.Label(string.Format( "GetSecondaryTouch ({0}) : ({1:f2}, {2:f2})", i, x, y )); // center on screen x = scr_w * (0.25f + x * 0.5f); y = scr_h * (0.25f + y * 0.5f); GUI.Button(new Rect((x - 120.0f), (y - 85.0f), 150.0f, 20.0f), "GetSecondaryTouch (" + i + ")"); } }
public void Update() { #if !UNITY_FLASH padTouch.enabled = pad.enabled = _Loader.controls == Contr.mouse; bool keys = _Loader.controls == Contr.keys; left.enabled = right.enabled = keys; nitro.enabled = pl.nitro > 0; //Log("Android Mouse " + mouse + " Taps" + Input.touchCount); mouse = Vector3.Lerp(mouse, Vector3.zero, Time.deltaTime * 10); bool padDown = false; if (_Loader.accelometer) { mouse = new Vector2(Input.acceleration.x, 0) * 2; } else if (_Loader.enableMouse) { foreach (var touch in Input.touches) { Vector3 mpos = touch.position; Vector3 pp = pad.inversePos; pp.x *= Screen.width; pp.y *= Screen.height; if (mpos.x < Screen.width / 2f && pp.x < Screen.width / 2f || mpos.x > Screen.width / 2f && pp.x > Screen.width / 2f) { Vector3 mouseTmp = (pp - mpos) / (pad.size.x / 2f) * (pl.secondPlayer ? 1 : -1); mouseTmp.x = Mathf.Clamp(mouseTmp.x, -1, 1); mouseTmp.y = Mathf.Clamp(mouseTmp.y, -1, 1); if (!splitScreen || mpos.y > Screen.height / 2f && pl.secondPlayer || mpos.y < Screen.height / 2f && !pl.secondPlayer) { mouse = mouseTmp; padTouch.screenPos = mpos; padDown = true; } } } #if UNITY_ANDROID if (AndroidInput.secondaryTouchEnabled && AndroidInput.touchCountSecondary > 0) { Vector2 p = AndroidInput.GetSecondaryTouch(0).position; p.x /= AndroidInput.secondaryTouchWidth; p.x -= .5f; p.x = Mathf.Clamp(p.x, -1, 1) * 2; mouse = p; } #endif if (!padDown) { padTouch.transform.position = pad.transform.position; } } if (_Game.editControls) { if (Input.touchCount == 1) { foreach (KeyHudBool a in dict.Values) { Touch?touch = HitTest(a); if (touch != null) { last = a; Vector2 mpos = touch.Value.position; mpos = pl.hud.camera.ScreenToViewportPoint(mpos); a.guitext.inversePos = mpos; a.posx = mpos.x; a.posy = mpos.y; } } } else if (last != null) { last.scale += GetDoubleTouch() * 0.01f; last.scale = Mathf.Max(.7f, last.scale); last.UpdateScale(); } } if (!_Game.editControls) { if (keys && !splitScreen) { foreach (KeyHudBool a in dict.Values) { a.hitTest = null; } foreach (Touch b in touches) { Vector2 pos = b.position; pos.x /= Screen.width; pos.y /= Screen.height; KeyHudBool d = dict.Values.Where(a => a.guitext.enabled).OrderBy(a => Vector2.Distance(pos, a.guitext.pos)).FirstOrDefault(); //print(d.guitext.name); d.hitTest = b; } } else { foreach (KeyHudBool a in dict.Values) { a.hitTest = HitTest(a); } } foreach (KeyHudBool a in dict.Values) { TouchPhase ph = a.hitTest.HasValue ? a.hitTest.Value.phase : ((TouchPhase)221); a.hold = ph == TouchPhase.Stationary || ph == TouchPhase.Moved; a.up = ph == TouchPhase.Canceled || ph == TouchPhase.Ended; a.down = ph == TouchPhase.Began; if (!splitScreen) { a.hudColor = padDown && a.guitext == pad || a.hold ? new Color(.5f, .5f, .5f, .5f) : new Color(0, 0, 0, 0); } } } #endif }