bool ParseAction(KeyAction a, KeyCode key)
 {
     if (android)
     {
         KeyHudBool val;
         if (dict != null && dict.TryGetValue((int)key, out val))
         {
             KeyHudBool keyHudBool = val;
             if (keyHudBool.down && a == KeyAction.KeyDown)
             {
                 return(true);
             }
             if (keyHudBool.up && a == KeyAction.KeyUp)
             {
                 return(true);
             }
             if (keyHudBool.hold && a == KeyAction.Key)
             {
                 return(true);
             }
         }
         if (key >= KeyCode.Mouse0 && key < KeyCode.Mouse6)
         {
             return(false);
         }
     }
     return(a == KeyAction.Key ? Input.GetKey(key) : a == KeyAction.KeyDown ? Input.GetKeyDown(key) : Input.GetKeyUp(key));
 }
 private void keyhudAdd(KeyHudBool keyHudBool)
 {
     if (!keyHudBool.archor.gameObject.activeSelf)
     {
         return;
     }
     keyHudBool.LoadPos();
     dict.Add((int)keyHudBool.key, keyHudBool);
 }
 private Touch?HitTest(KeyHudBool hud)
 {
     foreach (Touch b in Input.touches)
     {
         var pos = b.position;
         if (hud.archor.HitTest(pos))
         {
             return(b);
         }
     }
     return(null);
 }
    private KeyHudBool FirstOrDefault(Vector2 pos)
    {
        KeyHudBool min = null;

        foreach (KeyHudBool a in dict.Values)
        {
            if (a.archor.enabled)
            {
                a.dist = Vector2.Distance(pos, a.archor.pos);
                if (a.dist < .1f * a.scale)
                {
                    if (min == null || a.dist < min.dist)
                    {
                        min = a;
                    }
                }
            }
        }
        return(min);
        //return dict.Values.Slinq().Where(a => a.archor.enabled && (a.dist = Vector2.Distance(pos, a.archor.pos)) < .1f * a.scale).OrderBy(a => a.dist).FirstOrDefault();
    }
    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;
                }
            }
        }
    }
 private void keyhudAdd(KeyHudBool keyHudBool)
 {
     keyHudBool.LoadPos();
     dict.Add(keyHudBool.key, keyHudBool);
 }
    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
    }
 private Touch? HitTest(KeyHudBool hud)
 {
     foreach (Touch b in Input.touches)
     {
         var pos = b.position;
         if (hud.guitext.HitTest(pos)) return b;
     }
     return null;
 }
예제 #9
0
    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
    }
예제 #10
0
 private void keyhudAdd(KeyHudBool keyHudBool)
 {
     keyHudBool.LoadPos();
     dict.Add(keyHudBool.key, keyHudBool);
 }
    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;
            }
        }
    }
 private void keyhudAdd(KeyHudBool keyHudBool)
 {
     if(!keyHudBool.archor.gameObject.activeSelf)return;
     keyHudBool.LoadPos();
     dict.Add((int)keyHudBool.key, keyHudBool);
 }