Пример #1
0
 public static void Update(Components.BufferedInputs inputs)
 {
     if (UnityEngine.Input.GetButtonDown("Forward"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Up, Enums.KeyState.Down));
     }
     else if (UnityEngine.Input.GetButtonUp("Forward"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Up, Enums.KeyState.Up));
     }
     if (UnityEngine.Input.GetButtonDown("Backward"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Down, Enums.KeyState.Down));
     }
     else if (UnityEngine.Input.GetButtonUp("Backward"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Down, Enums.KeyState.Up));
     }
     if (UnityEngine.Input.GetButtonDown("Left"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Left, Enums.KeyState.Down));
     }
     else if (UnityEngine.Input.GetButtonUp("Left"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Left, Enums.KeyState.Up));
     }
     if (UnityEngine.Input.GetButtonDown("Right"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Right, Enums.KeyState.Down));
     }
     else if (UnityEngine.Input.GetButtonUp("Right"))
     {
         inputs.buffered.Add(new BufferedInput(Enums.Key.Right, Enums.KeyState.Up));
     }
 }
Пример #2
0
        public static void Update(GenericDictionary <Components.Controllable> controllables, Components.BufferedInputs inputs)
        {
            foreach (KeyValuePair <int, Components.Controllable> controllable in controllables)
            {
                for (int i = 0; i < inputs.buffered.Count; i++)
                {
                    float x = controllable.Value.inputAxis.x;
                    float y = controllable.Value.inputAxis.y;

                    if (inputs.buffered[i].key == Enums.Key.Up &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        y += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Up &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        y -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Down &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        y -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Down &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        y += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Left &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        x -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Left &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        x += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Right &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        x += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Right &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        x -= 1.0f;
                    }
                    x = Mathf.Clamp(x, -1.0f, 1.0f);
                    y = Mathf.Clamp(y, -1.0f, 1.0f);
                    controllable.Value.inputAxis.x = x;
                    controllable.Value.inputAxis.y = y;
                }
            }
            inputs.buffered.Clear();
        }