示例#1
0
 // Unity functions
 private void Awake()
 {
     NormalState     = new NormalState(this);
     BigState        = new BigState(this);
     ShootingState   = new ShootingState(this);
     InvincibleState = new InvincibleState(this);
 }
    void Start()
    {
        m_R2D      = GetComponent <Rigidbody2D>();
        m_Anim     = GetComponent <Animator>();
        m_Render   = GetComponent <SpriteRenderer>();
        m_State    = PlayerState.norman;
        m_BigState = BigState.norman;
        m_oldPos   = transform.position;
        GameObject soundManager = GameObject.FindGameObjectWithTag("sound");

        if (soundManager)
        {
            m_soundControl = soundManager.GetComponent <SoundController>();
        }
    }
    bool CheckXoay()
    {
        if (m_currentLoc)
        {
            m_State = PlayerState.xoay;
            m_Anim.SetTrigger(m_State.ToString());
            if (m_BigState != BigState.norman)
            {
                m_IsClimb_1 = false;
                m_IsClimb_2 = false;
                HoldExit();
                m_BigState = BigState.norman;
            }

            return(true);
        }
        return(false);
    }
示例#4
0
        public void LogBigStates(BigState state, string reason)
        {
            try
            {
                StateChangeEvent Event = new StateChangeEvent();
                switch (state)
                {
                case BigState.Ready:
                    currState.IsReady = true;
                    Event.Datetime    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    Event.Exten       = Extension;
                    Event.Name        = LoginName;
                    Event.State       = state.ToString();
                    Event.Reason      = "NIL";
                    break;

                case BigState.NotReady:
                    currState.IsReady = false;
                    currState.ACW     = false;
                    currState.Idle    = false;
                    currState.OnCall  = false;
                    Event.Datetime    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    Event.Exten       = Extension;
                    Event.Name        = LoginName;
                    Event.State       = state.ToString();
                    Event.Reason      = reason;
                    break;

                default:
                    break;
                }
                dataContext.StateChangeEvents.InsertOnSubmit(Event);
                dataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.ToString(), "Error# 4012: " + ex.Message);
            }
        }
    bool UpdateBigState()
    {
        switch (m_BigState)
        {
        case BigState.norman:
            //climb_1
            if (m_HeadDetect.m_Collision && !m_IsClimb_1 && m_R2D.velocity.y > 0 && m_IsPressUp)
            {
                m_BigState = BigState.climb_1;
                m_State    = PlayerState.climb_1;
                m_Anim.SetTrigger(m_State.ToString());
                m_IsClimb_1 = true;
                FixPosition(0, m_Step);
                HoldEnter();
                return(true);
            }
            //climb_2
            if (m_FontDetect.m_Collision && m_IsPressJump && !m_IsClimb_2 && m_DirectX != 0)
            {
                if (m_FootDetect.m_Collision)
                {
                    FixPosition(0, m_Step);
                }
                m_BigState = BigState.climb_2;
                m_State    = PlayerState.climb_2;
                m_Anim.SetTrigger(m_State.ToString());
                m_IsClimb_2 = true;
                FixPosition(m_Step * transform.localScale.x, 0);
                HoldEnter();
                return(true);
            }
            return(false);

        case BigState.climb_1:
            if (m_IsClimb_1)
            {
                //norman
                if (m_IsPressJump)
                {
                    m_BigState = BigState.norman;
                    m_State    = PlayerState.norman;
                    m_Anim.SetTrigger(m_State.ToString());
                    m_IsClimb_1 = false;
                    HoldExit();
                    return(true);
                }

                //climb_2
                if ((!m_HeadDetect.m_Collision && !m_FontDetect.m_Collision && m_DirectY == 0) ||
                    (m_FontDetect.m_Collision && m_DirectX * transform.localScale.x > 0 && !m_IsPressUp))
                {
                    if (!m_FontDetect.m_Collision)
                    {
                        FixPosition(0, 2 * m_Step);
                        transform.localScale = new Vector3(-1 * transform.localScale.x, 1, 1);
                    }
                    else
                    {
                        FixPosition(2 * m_Step * transform.localScale.x, -m_Step);
                    }
                    m_BigState = BigState.climb_2;
                    m_State    = PlayerState.climb_2;
                    m_Anim.SetTrigger(m_State.ToString());
                    m_IsClimb_1 = false;
                    HoldExit();
                    m_IsClimb_2 = true;
                    HoldEnter();
                    return(true);
                }

                //fix bug tu dong roi
                if (!m_HeadDetect.m_Collision && !m_BackDetect.m_Collision)
                {
                    transform.position = m_oldPos;
                    return(false);
                }
            }
            return(false);

        case BigState.climb_2:
            if (m_IsClimb_2)
            {
                //climb_1
                if ((m_HeadDetect.m_Collision && m_DirectX == 0 && m_IsPressUp) || (!m_FontDetect.m_Collision && m_IsPressDown && !m_FootDetect.m_Collision))
                {
                    if (!m_FontDetect.m_Collision && m_IsPressDown && !m_FootDetect.m_Collision)
                    {
                        FixPosition(m_Step * transform.localScale.x, 0);
                    }
                    else
                    {
                        transform.localScale = new Vector3(-1 * transform.localScale.x, 1, 1);
                        FixPosition(0, m_Step);
                    }
                    m_BigState = BigState.climb_1;
                    m_State    = PlayerState.climb_1;
                    m_Anim.SetTrigger(m_State.ToString());
                    m_IsClimb_2 = false;
                    HoldExit();
                    m_IsClimb_1 = true;
                    HoldEnter();
                    return(true);
                }
                //norman
                if (m_IsPressJump || (!m_HeadDetect.m_Collision && !m_FontDetect.m_Collision && m_IsPressUp) || m_FootDetect.m_Collision)
                {
                    if (!m_IsPressJump)
                    {
                        FixPosition(m_Step * transform.localScale.x, 0);
                    }
                    m_BigState = BigState.norman;
                    m_State    = PlayerState.norman;
                    m_Anim.SetTrigger(m_State.ToString());
                    m_IsClimb_2 = false;
                    HoldExit();
                    return(true);
                }
            }
            return(false);

        default:
            return(false);
        }
    }