Exemplo n.º 1
0
 private void Awake()
 {
     frontState = new FrontState(this);
     backState  = new BackState(this);
     rightState = new RightState(this);
     leftState  = new LeftState(this);
 }
Exemplo n.º 2
0
    private RightState()
    {
        if (instance != null)//If an isntance of this class already exists, return
        {
            return;
        }

        instance = this;
    }
Exemplo n.º 3
0
 public void SetRuler(RightState state, bool includeAllChilren)
 {
     this.RightState = state;
     if (includeAllChilren)
     {
         foreach (RightRuler r in Nodes)
         {
             r.RightState = state;
             if (r.Nodes.Count > 0)
             {
                 SetRuler(r, state, includeAllChilren);
             }
         }
     }
 }
Exemplo n.º 4
0
    void Start()
    {
        //ani = GetComponent<Animation>();

        IdleState   idle   = new IdleState(1, this);
        LeftState   left   = new LeftState(2, this);
        RightState  right  = new RightState(3, this);
        UpState     up     = new UpState(4, this);
        DownState   down   = new DownState(5, this);
        AttackState attack = new AttackState(6, this);

        machine = new StateMachine(idle);
        machine.AddState(left);
        machine.AddState(right);
        machine.AddState(up);
        machine.AddState(down);
        machine.AddState(attack);
    }
Exemplo n.º 5
0
 private void SetRuler(RightRuler ruler, RightState state, bool includeAllChilren)
 {
     ruler.RightState = state;
     if (includeAllChilren)
     {
         foreach (RightRuler r in ruler.Nodes)
         {
             if (r.Nodes.Count > 0)
             {
                 SetRuler(r, state, includeAllChilren);
             }
             else
             {
                 r.RightState = state;
             }
         }
     }
 }
Exemplo n.º 6
0
    public void ResetPos()
    {
        state = RightState.Idle;
        rb.ExitMove();
        rf.ExitMove();
        useMouse = false;
        var exit = new MyEvent()
        {
            type    = MyEvent.EventType.ExitShoot,
            boolArg = !rb.IsCancel(),
        };

        MyEventSystem.myEventSystem.PushEvent(exit);

        /*
         * if (!rb.IsCancel())
         * {
         *  GameInterface.gameInterface.PlayerAttack();
         * }
         */
    }
Exemplo n.º 7
0
        public AbstractState makeState(string stateName, string p1, string p2, string p3, float precision, float grados, string stateType, int posState1, int posState2)
        {
            AbstractState aS;
            AbstractState aS1 = getState(posState1);
            AbstractState aS2 = getState(posState2);

            switch (stateType)
            {
            case "AND": aS = new AndState(aS1, aS2, stateName); break;

            case "ANGLE": aS = new AngleState(p1, p3, p2, grados, precision, stateName); break;

            case "CENTER_X": aS = new CenterStateX(p1, p2, precision, stateName); break;

            case "CENTER_Y": aS = new CenterStateY(p1, p2, precision, stateName); break;

            case "CENTER_Z": aS = new CenterStateZ(p1, p2, precision, stateName); break;

            case "DISTANCE": aS = new DistanceState(p1, p2, precision, stateName); break;

            case "LEFT": aS = new LeftState(p1, p2, precision, stateName); break;

            case "OR": aS = new OrState(aS1, aS2, stateName); break;

            case "OVER": aS = new OverState(p1, p2, precision, stateName); break;

            case "POSITION": aS = new PositionState(p1, precision, stateName); break;

            case "RIGHT": aS = new RightState(p1, p2, precision, stateName); break;

            case "UNDER": aS = new UnderState(p1, p2, precision, stateName); break;

            default: aS = new InvalidState(stateName); break;
            }
            return(aS);
        }
Exemplo n.º 8
0
    private void Update()
    {
        if (!CanProcessEvent)
        {
            return;
        }

        if (state == RightState.Idle)
        {
            if (WindowMng.windowMng.IsOtherUIOpen())
            {
                return;
            }

#if UNITY_EDITOR || UNITY_STANDALONE
            if (Input.GetMouseButtonDown(0))
            {
                var mousePos = Input.mousePosition;
                if (mousePos.x > Screen.width / 2)
                {
                    state = RightState.Move;
                    rb.EnterMove();
                    rf.EnterMove();
                    useMouse = true;

                    rb.SetFingerPos(mousePos);
                    rf.SetFingerPos(mousePos);

                    CalculateShootDir();
                    //MyEventSystem.myEventSystem.PushEvent(MyEvent.EventType.EnterShoot);
                    enterTime = Time.time;
                }
            }
            else
#endif
            {
                foreach (var touch in Input.touches)
                {
                    fingerId = touch.fingerId;
                    //if (fingerId > 0 && fingerId < Input.touchCount)
                    if (touch.phase == TouchPhase.Began)
                    {
                        if (Input.GetTouch(fingerId).position.x > Screen.width / 2)
                        {
                            state = RightState.Move;

                            var fp = Input.GetTouch(fingerId).position;
                            rb.EnterMove();
                            rf.EnterMove();
                            useMouse = false;
                            rb.SetFingerPos(fp);
                            rf.SetFingerPos(fp);
                            CalculateShootDir();
                            //MyEventSystem.myEventSystem.PushEvent(MyEvent.EventType.EnterShoot);
                            enterTime = Time.time;
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            if (Time.time - enterTime > 0.0f && enterTime != 0)
            {
                MyEventSystem.myEventSystem.PushEvent(MyEvent.EventType.EnterShoot);
                enterTime = 0;
            }

            if (WindowMng.windowMng.IsOtherUIOpen())
            {
                state = RightState.Idle;
                rb.ExitMove();
                rf.ExitMove();
                useMouse = false;
                MyEventSystem.PushEventStatic(MyEvent.EventType.ExitShoot);
                return;
            }

#if UNITY_EDITOR || UNITY_STANDALONE
            if (useMouse)
            {
                if (!Input.GetMouseButton(0))
                {
                    state = RightState.Idle;
                    rb.ExitMove();
                    rf.ExitMove();
                    useMouse = false;
                    var exit = new MyEvent()
                    {
                        type    = MyEvent.EventType.ExitShoot,
                        boolArg = !rb.IsCancel(),
                    };

                    MyEventSystem.myEventSystem.PushEvent(exit);

                    /*
                     * if (!rb.IsCancel())
                     * {
                     *  //MyEventSystem.PushEventStatic (MyEvent.EventType.Shoot);
                     *  GameInterface.gameInterface.PlayerAttack();
                     * }
                     */
                }
                else
                {
                    var mousePos = Input.mousePosition;
                    rb.SetFingerPos(mousePos);
                    rf.SetFingerPos(mousePos);
                    CalculateShootDir();
                }
            }
            else
#endif
            {
                var   find     = false;
                Touch touch    = new Touch();
                var   getTouch = false;
                foreach (var t in Input.touches)
                {
                    if (t.fingerId == fingerId)
                    {
                        touch    = t;
                        getTouch = true;
                        break;
                    }
                }

                if (getTouch)
                {
                    var phase = touch.phase;
                    find = phase == TouchPhase.Ended || phase == TouchPhase.Canceled;
                }
                else
                {
                    find = true;
                }
                if (find)
                {
                    state = RightState.Idle;
                    rb.ExitMove();
                    rf.ExitMove();

                    var exit = new MyEvent()
                    {
                        type    = MyEvent.EventType.ExitShoot,
                        boolArg = !rb.IsCancel(),
                    };
                    MyEventSystem.myEventSystem.PushEvent(exit);

                    /*
                     * if (!rb.IsCancel())
                     * {
                     *  GameInterface.gameInterface.PlayerAttack();
                     * }
                     */
                }
                else
                {
                    var pos = touch.position;
                    rb.SetFingerPos(pos);
                    rf.SetFingerPos(pos);
                    CalculateShootDir();
                }
            }
        }
    }
Exemplo n.º 9
0
 public RightTransition(Player _player)
 {
     player    = _player;
     nextState = new RightState(_player);
 }