Beispiel #1
0
        /// <summary>
        /// 设置新状态
        /// </summary>
        /// <param name="newState"></param>
        /// <returns></returns>
        public virtual bool setState(XLStateBase newState)
        {
            if (newState == null || _currentState == newState)
            {
                return(false);
            }

            if (_preState != null)
            {
                _preState.stop();
            }

            _preState     = _currentState;
            _currentState = newState;

            newState.init();
            return(true);
        }
Beispiel #2
0
    /// <summary>
    /// 初始化
    /// </summary>
    public override void spriteInit()
    {
        //调用父类初始化方法
        base.spriteInit();

        _navmeshAgent = GetComponent<NavMeshAgent>();

        //实例化所需状态
        IdleState = new GeneralIdleState(this);
        MoveState = new GeneralMoveState(this);
        AttackState = new GeneralAttackState(this);
        HurtState = new GeneralHurtState(this);
        DeadState = new GeneralDeadState(this);
        WinState = new GeneralWinState(this);

        _walkState = new GeneralWalkState(this);

        //取得角色动作
        _animator = GetComponent<Animator>();

        #if true
        if (_lifeTestObj == null)//判断血条组件是否为空
        {
            //实例化血条组件
            _lifeTestObj = ResourceManager.getInstance().getGameObject(PanelConfig.BLOOD_BAR);

            //获取当前Canvas下第一个对象
            _lifeTestObj.transform.SetParent(GameObject.Find("Canvas").transform.GetChild(0));
            _lifeTestObj.transform.SetAsFirstSibling();
            //设置缩放比
            _lifeTestObj.transform.localScale = Vector3.one;
            _lifeTestObj.transform.localPosition = Vector3.zero;
        }
        //获取血条脚本
        _lifeLine = _lifeTestObj.GetComponent<LifeTest>();
        //获取场景主摄像机
        _lifeLine._mainCamera = Game.GameEntry.Instance.Cameras.mainCamera;
        //设置士兵
        _lifeLine.soldier = this;
        #endif
    }
Beispiel #3
0
    /// <summary>
    /// 设置新状态-debug-TODO
    /// </summary>
    /// <param name="newState"></param>
    /// <returns></returns>
    public override bool setState(XLStateBase newState)
    {
        walkUnable(transform.position);

        if (_currentState == DeadState)
        {
            return true;
        }

        return base.setState(newState);
    }
Beispiel #4
0
    /// <summary>
    /// 事件通知(来自于状态)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="eventId"></param>
    /// <param name="eventData"></param>
    public bool notifyEvent(XLStateBase sender, int eventId, Object eventData)
    {
        // 行走状态
        if (sender == _walkState)
        {
            if (eventId == GeneralWalkState.EVENT_CHANGE_TO_ATTACK)
            {
                _data.AttackTarget = _walkState.Target;
                setState(AttackState);
                return true;
            }
            return true;
        }

        //攻击状态
        if (sender == AttackState)
        {
            //攻击目标为空或攻击目标不在攻击范围内
            if (eventId == GeneralAttackState.ATTACK_TARGET_IS_NULL || eventId == GeneralAttackState.ATTACK_TARGET_IS_OUT)
            {
                //如果是敌方
                if (_data.Country == Defaults.Country.Enemy)
                {
                    //己方还有士兵,进入锁敌
                    if (SpriteMgr.getInstance().SelfSoldiers.Count > 0)
                    {
                        //进入锁敌状态
                        setState(_walkState);
                    }
                }
                else
                {
                    //如果是己方,敌方还有士兵,进入锁敌
                    if (SpriteMgr.getInstance().EnemySoldiers.Count > 0)
                    {
                        //进入锁敌状态
                        setState(_walkState);
                    }
                }
            }

            return true;
        }

        return false;
    }
Beispiel #5
0
 /// <summary>
 /// 当前状态是否是指定状态
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public bool isCurrentState(XLStateBase state)
 {
     return (_currentState == state);
 }
Beispiel #6
0
        /// <summary>
        /// 设置新状态
        /// </summary>
        /// <param name="newState"></param>
        /// <returns></returns>
        public virtual bool setState(XLStateBase newState)
        {
            if (newState == null || _currentState == newState)
            {
                return false;
            }

            if (_preState != null)
            {
                _preState.stop();
            }

            _preState = _currentState;
            _currentState = newState;

            newState.init();
            return true;
        }
Beispiel #7
0
 /// <summary>
 /// 当前状态是否是指定状态
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public bool isCurrentState(XLStateBase state)
 {
     return(_currentState == state);
 }