Exemplo n.º 1
0
        // ---------------
        protected bool SendMoveEventToSelectedObject()
        {
            GamepadManager g = GamepadManager.activeManager;

            if (g == null)
            {
                return(false);
            }

            JoystickState
                leftStick = g.GetCombinedGamepad().GetStick(GamepadManager.GamepadStick.LeftAnalog),
                dpad      = g.GetCombinedGamepad().GetStick(GamepadManager.GamepadStick.Dpad);

            Dir dir = Dir.N;

            if (leftStick.JustReleasedDir4(Dir.N))
            {
                dir = leftStick.GetDir4();
            }
            else if (dpad.JustReleasedDir4(Dir.N))
            {
                dir = dpad.GetDir4();
            }

            Vector2 dirVec = CFUtils.DirToVector(dir, false);

            Vector2 keyboardVec = new Vector2(
                (ControlFreak2.CF2Input.GetKeyDown(KeyCode.RightArrow)  ? 1.0f : ControlFreak2.CF2Input.GetKeyDown(KeyCode.LeftArrow) ? -1.0f : 0),
                (ControlFreak2.CF2Input.GetKeyDown(KeyCode.UpArrow)             ? 1.0f : ControlFreak2.CF2Input.GetKeyDown(KeyCode.DownArrow) ? -1.0f : 0));


            dirVec.x = CFUtils.ApplyDeltaInput(dirVec.x, keyboardVec.x);
            dirVec.y = CFUtils.ApplyDeltaInput(dirVec.y, keyboardVec.y);

            if (dirVec.sqrMagnitude < 0.00001f)
            {
                return(false);
            }


            var axisEventData = GetAxisEventData(dirVec.x, dirVec.y, 0.3f);

            ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);

            if ((this.eventSystem.currentSelectedGameObject != null))
            {
                this.eventSystem.firstSelectedGameObject = this.eventSystem.currentSelectedGameObject;
            }

            return(axisEventData.used);
        }
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
#if UNITY_EDITOR
            if (!UnityEditor.EditorApplication.isPlaying)
            {
                //this.CheckHierarchy();
                //return;
            }
#endif

            TouchJoystick joystick = (TouchJoystick)this.sourceControl;

            if ((joystick == null) || (this.image == null))
            {
                return;
            }


            JoystickState joyState = joystick.GetState();     //false); //this.useVirtualJoystickState);



            SpriteConfig sprite = null;

            if ((this.spriteMode == SpriteMode.FourWay) || (this.spriteMode == SpriteMode.EightWay))
            {
                Dir curDir = Dir.N;

                if (this.spriteMode == SpriteMode.FourWay)
                {
                    curDir = joyState.GetDir4();
                }
                else if (this.spriteMode == SpriteMode.EightWay)
                {
                    curDir = joyState.GetDir8();
                }

                switch (curDir)
                {
                case Dir.U: sprite = this.spriteUp; break;

                case Dir.UR: sprite = this.spriteUpRight; break;

                case Dir.R: sprite = this.spriteRight; break;

                case Dir.DR: sprite = this.spriteDownRight; break;

                case Dir.D: sprite = this.spriteDown; break;

                case Dir.DL: sprite = this.spriteDownLeft; break;

                case Dir.L: sprite = this.spriteLeft; break;

                case Dir.UL: sprite = this.spriteUpLeft; break;
                }
            }


            if (joystick.Pressed() && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutralPressed;
            }


            if (((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutral;
            }


            if (!CFUtils.editorStopped && !this.IsIllegallyAttachedToSource())
            {
                Vector2 joyVec = joyState.GetVectorEx((joystick.shape == TouchControl.Shape.Rectangle) || (joystick.shape == TouchControl.Shape.Square));


                if (this.animateTransl)
                {
                    this.extraOffset = CFUtils.SmoothTowardsVec2(this.extraOffset, Vector2.Scale(joyVec, this.moveScale),
                                                                 this.translationSmoothingTime, CFUtils.realDeltaTimeClamped, 0.0001f);
                }
                else
                {
                    this.extraOffset = Vector2.zero;
                }


                if (this.rotationMode != RotationMode.Disabled)
                {
                    float targetAngle = 0;

                    if (joystick.Pressed())
                    {
                        Vector2 v = joyState.GetVector();

                        if (this.rotationMode == RotationMode.Compass)
                        {
                            if (v.sqrMagnitude > 0.0001f)
                            {
                                this.lastSafeCompassAngle = joyState.GetAngle();          //CFUtils.VecToAngle(v.normalized);
                            }
                            targetAngle = -this.lastSafeCompassAngle;                     //targetRotation = Quaternion.Euler(0, 0, -this.lastSafeCompassAngle);
                        }
                        else
                        {
                            targetAngle = ((this.rotationMode == RotationMode.SimpleHorizontal) ? v.x : v.y) * -this.simpleRotationRange;
                        }
                    }
                    else
                    {
                        this.lastSafeCompassAngle = 0;
                        targetAngle = 0;
                    }


                    this.extraRotation = CFUtils.SmoothTowardsAngle(this.extraRotation, targetAngle,
                                                                    this.rotationSmoothingTime, CFUtils.realDeltaTimeClamped, 0.0001f);
                }
            }



            this.BeginSpriteAnim(sprite, skipAnim);

            this.UpdateSpriteAnimation(skipAnim);
        }