Пример #1
0
        public CustomActionList(Game game, GraphicSettings setting, CustomWorld world, Tracker tracker)
            : base(game, setting)
        {
            _world                   = world;
            _tracker                 = tracker;
            PlayerForward            = new ActionVoid(this.PlayerMoveForward);
            PlayerRight              = new ActionVoid(this.PlayerMoveRight);
            PlayerBackward           = new ActionVoid(this.PlayerMoveBackward);
            PlayerLeft               = new ActionVoid(this.PlayerMoveLeft);
            CameraRotation           = new ActionFloatFloat(this.RotateCamera);
            RotateCameraHorizontally = new ActionFloat(this.M_RotateCameraX);
            RotateCameraVertically   = new ActionFloat(this.M_RotateCameraY);
            Pause = new ActionVoid(this.M_Pause);

            Shoot = new ActionVoid(this.MethodShoot);
        }
Пример #2
0
 protected void BindAxisDelta(MouseAxis axis, ActionFloat action, float sensibilite)
 {
     axisActionMap.Add(axis, new Tuple <ActionFloat, float>(action, sensibilite));
 }
Пример #3
0
        public sealed override void Update()
        {
            MouseState mouseState = Mouse.GetState();

            if (mouseState == null)
            {
                return;
            }

            /*
             * if(!CursorLocked && _bindingMap.MousePositionAction != null){
             *  ActionFloatFloat action = _bindingMap.MousePositionAction.Item1;
             *  float sensibilite = _bindingMap.MousePositionAction.Item2;
             *  action.Execute(mouseState.Position.X * sensibilite, mouseState.Position.Y * sensibilite);
             * }
             */

            if (CursorLocked)
            {
                int deltaX = mouseState.Position.X - _mouseLockedPosition.X;
                int deltaY = mouseState.Position.Y - _mouseLockedPosition.Y;

                /*
                 * if (_bindingMap.MouseDeltaPositionAction != null)
                 * {
                 *  ActionFloatFloat actionXY = _bindingMap.MouseDeltaPositionAction.Item1;
                 *  float sensibiliteXY = _bindingMap.MouseDeltaPositionAction.Item2;
                 *  actionXY.Execute(deltaX * sensibiliteXY, deltaY * sensibiliteXY);
                 * }
                 */

                Tuple <ActionFloat, float> tuple;

                if ((tuple = _bindingMap.GetAction(MouseAxis.X)) != null)
                {
                    ActionFloat actionX      = tuple.Item1;
                    float       sensibiliteX = tuple.Item2;
                    actionX.Execute(deltaX * sensibiliteX);
                }

                if ((tuple = _bindingMap.GetAction(MouseAxis.Y)) != null)
                {
                    ActionFloat actionY      = tuple.Item1;
                    float       sensibiliteY = tuple.Item2;
                    actionY.Execute(deltaY * sensibiliteY);
                }

                SetCursorPosition(_mouseLockedPosition.X, _mouseLockedPosition.Y);
            }

            List <MouseButton> _currentButtonPressed = new List <MouseButton>();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                _currentButtonPressed.Add(MouseButton.LeftButton);
            }

            if (mouseState.MiddleButton == ButtonState.Pressed)
            {
                _currentButtonPressed.Add(MouseButton.MiddleButton);
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                _currentButtonPressed.Add(MouseButton.RightButton);
            }

            foreach (MouseButton button in Enum.GetValues(typeof(MouseButton)))
            {
                if (_currentButtonPressed.Contains(button))
                {
                    if (_previousButtonPressed.Contains(button))
                    {
                        ExecuteAction(button, ButtonState3.Hold);
                    }
                    else
                    {
                        ExecuteAction(button, ButtonState3.JustPressed);
                    }
                }
                else
                {
                    if (_previousButtonPressed.Contains(button))
                    {
                        ExecuteAction(button, ButtonState3.JustReleased);
                    }
                }
            }

            _previousButtonPressed = _currentButtonPressed;
        }
Пример #4
0
    private static IEnumerator FloatFadeCoroutine(float fromValue, float toValue, float duration, FunctionFloat function, ActionFloat update, UnityAction end)
    {
        float t = 0f;

        while (t < 1f)
        {
            t += Time.deltaTime / duration; if (t > 1f)
            {
                t = 1f;
            }

            float value = Mathf.Lerp(fromValue, toValue, function(t));

            update(value);

            yield return(null);
        }

        if (end != null)
        {
            end.Invoke();
        }
    }
Пример #5
0
    public static Coroutine FloatFadeInOut(this MonoBehaviour script, float fromValue, float toValue, float duration, ActionFloat update, UnityAction end = null)
    {
        FunctionFloat f = (t) =>
        {
            float x = t * 2f - 1f;
            float y = Mathf.Sign(x) * Mathf.Pow(Mathf.Abs(x), 0.5f);
            return((y + 1f) * 0.5f);
        };

        return(script.StartCoroutine(FloatFadeCoroutine(fromValue, toValue, duration, f, update, end)));
    }
Пример #6
0
    public static Coroutine FloatFadeOut(this MonoBehaviour script, float fromValue, float toValue, float duration, ActionFloat update, UnityAction end = null)
    {
        FunctionFloat f = (t) =>
        {
            return(1f - Mathf.Pow(1f - t, 2f));
        };

        return(script.StartCoroutine(FloatFadeCoroutine(fromValue, toValue, duration, f, update, end)));
    }