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; } } } }
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 }