Example #1
0
        public static void TopDown2DVectorTouchControl(
            float rotationAmount,
            float xVelocity,
            float zVelocity,
            bool buttonPressed,
            out Vector3 displacementVector,
            out Vector3 rotationalVector,
            Transform transform                 = null,
            ActionCallback actionCallback       = null,
            AnimationCallback animationCallback = null)
        {
            displacementVector = Vector3.zero;

            if (transform == null)
            {
                rotationalVector = Vector3.zero;
            }
            else
            {
                rotationalVector = transform.rotation.eulerAngles;
            }

            if (animationCallback == null)
            {
                animationCallback = DefaultAnimationCallback;
            }

            if (actionCallback == null)
            {
                actionCallback = DefaultActionCallback;
            }

            if (buttonPressed)
            {
                actionCallback();
                animationCallback(actionAnimation: true);
            }

            rotationalVector.z -= xVelocity * rotationAmount;

            displacementVector = VectorAnalysis.CalculateDisplacementFromAngle2D(rotationalVector) * zVelocity;

            if (displacementVector != Vector3.zero &&
                ((transform != null &&
                  rotationalVector != transform.rotation.eulerAngles) ||
                 rotationalVector != Vector3.zero))
            {
                animationCallback(travelAnimation: true);
            }
            else
            {
                animationCallback(idleAnimation: true);
            }
        }
Example #2
0
        public static void FirstPersonTouchScreenControlHandler(
            float xVelocity,
            float zVelocity,
            bool buttonPressed,
            out Vector3 displacementVector,
            out Vector3 rotationalVector,
            Transform transform                 = null,
            ActionCallback actionCallback       = null,
            AnimationCallback animationCallback = null)
        {
            displacementVector = Vector3.zero;

            if (transform == null)
            {
                rotationalVector = Vector3.zero;
            }
            else
            {
                rotationalVector = transform.rotation.eulerAngles;
            }

            if (animationCallback == null)
            {
                animationCallback = DefaultAnimationCallback;
            }

            if (actionCallback == null)
            {
                actionCallback = DefaultActionCallback;
            }

            if (buttonPressed)
            {
                actionCallback();
                animationCallback(actionAnimation: true);
            }

            rotationalVector.y += xVelocity;

            displacementVector = VectorAnalysis.CalculateDisplacementFromAngle(rotationalVector) * zVelocity;

            if (displacementVector != Vector3.zero &&
                rotationalVector != transform.rotation.eulerAngles)
            {
                animationCallback(travelAnimation: true);
            }
            else
            {
                animationCallback(idleAnimation: true);
            }
        }
Example #3
0
        public static void TopDownTouchScreenControlHandler(
            float xVelocity,
            float zVelocity,
            bool buttonPressed,
            out Vector3 displacementVector,
            out Vector3 rotationalVector,
            Transform transform                 = null,
            ActionCallback actionCallback       = null,
            AnimationCallback animationCallback = null)
        {
            displacementVector = new Vector3(xVelocity, 0, zVelocity);

            if (transform == null)
            {
                rotationalVector = Vector3.zero;
            }
            else
            {
                rotationalVector = transform.rotation.eulerAngles;
            }

            rotationalVector.y = VectorAnalysis.CalculateAngleFromDisplacement(displacementVector);

            if (animationCallback == null)
            {
                animationCallback = DefaultAnimationCallback;
            }

            if (actionCallback == null)
            {
                actionCallback = DefaultActionCallback;
            }

            if (buttonPressed)
            {
                actionCallback();
                animationCallback(actionAnimation: true);
            }

            if (displacementVector != Vector3.zero)
            {
                animationCallback(travelAnimation: true);
            }
            else
            {
                animationCallback(idleAnimation: true);
            }
        }
Example #4
0
        public static void TopDown2DVectorControl(
            float rotationAmount,
            out Vector3 displacement,
            out Vector3 rotation,
            Transform transform                 = null,
            ActionCallback actionCallback       = null,
            AnimationCallback animationCallback = null)
        {
            displacement = Vector3.zero;

            if (transform == null)
            {
                rotation = Vector3.zero;
            }
            else
            {
                rotation = transform.rotation.eulerAngles;
            }

            bool action = false;

            if (animationCallback == null)
            {
                animationCallback = DefaultAnimationCallback;
            }

            if (actionCallback == null)
            {
                actionCallback = DefaultActionCallback;
            }

            if (Input.GetKey(Controls.Forward))
            {
                displacement = VectorAnalysis.CalculateDisplacementFromAngle2D(rotation);
                animationCallback(travelAnimation: true);
            }

            if (Input.GetKey(Controls.Reverse))
            {
                displacement = VectorAnalysis.CalculateDisplacementFromAngle2D(rotation) * -1;
                animationCallback(travelAnimation: true);
            }

            if (Input.GetKey(Controls.Left))
            {
                rotation.z += rotationAmount;
            }

            if (Input.GetKey(Controls.Right))
            {
                rotation.z -= rotationAmount;
            }

            if (Input.GetKey(Controls.Space))
            {
                action = true;
                actionCallback();
                animationCallback(actionAnimation: true);
            }

            if (displacement == Vector3.zero && !action)
            {
                animationCallback(idleAnimation: true);
            }
        }
Example #5
0
        public static void FirstPersonControlHandler(
            out Vector3 displacement,
            out Vector3 rotation,
            Transform transform                 = null,
            ActionCallback actionCallback       = null,
            AnimationCallback animationCallback = null)
        {
            displacement = Vector3.zero;

            if (transform == null)
            {
                rotation = Vector3.zero;
            }
            else
            {
                rotation = transform.rotation.eulerAngles;
            }

            bool action = false;

            if (animationCallback == null)
            {
                animationCallback = DefaultAnimationCallback;
            }

            if (actionCallback == null)
            {
                actionCallback = DefaultActionCallback;
            }

            if (Input.GetKey(Controls.Forward) || Input.GetKey(Controls.ForwardAlt))
            {
                displacement = VectorAnalysis.CalculateDisplacementFromAngle(rotation);
                animationCallback(travelAnimation: true);
            }

            if (Input.GetKey(Controls.Reverse) || Input.GetKey(Controls.ReverseAlt))
            {
                displacement = VectorAnalysis.CalculateDisplacementFromAngle(rotation) * -1;
                animationCallback(travelAnimation: true);
            }

            if (Input.GetKey(Controls.Left))
            {
                rotation.y += -5.0f;
            }

            if (Input.GetKey(Controls.Right))
            {
                rotation.y += 5.0f;
            }

            if (Input.GetKey(Controls.Space))
            {
                action = true;
                actionCallback();
                animationCallback(actionAnimation: true);
            }

            if (displacement == Vector3.zero && !action)
            {
                animationCallback(idleAnimation: true);
            }
        }