Ejemplo n.º 1
0
    private void OnClickAttackButtonEvent(IFsm <Hero> fsm, object sender, object userData)
    {
        ClickAttackButtonEventArgs args = (ClickAttackButtonEventArgs)userData;

        fsm.SetData <VarInt>("AttackType", (int)args.AttackType);
        fsm.SetData <VarInt>("WeaponID", args.WeaponID);
        ChangeState <HeroAtkState> (fsm);
    }
Ejemplo n.º 2
0
        public override void OnUpdate(IFsm <IProcedureManager> procedureOwner)
        {
            if (m_StartGame)
            {
                procedureOwner.SetData(Constant.ProcedureData.NextSceneId, new VarInt(GameEntry.Config.GetInt("Scene.Main")));
                procedureOwner.SetData(Constant.ProcedureData.GameMode, new VarInt((int)GameMode.Survival));

                RuntimeProcedure.ChangeProcedure <HotProcedureChangeScene>(procedureOwner);
            }
        }
Ejemplo n.º 3
0
        protected void ChangeScene <TState>(IFsm fsm, string sceneName) where TState : FsmState
        {
            fsm.SetData <VarString>("SceneName", sceneName);
            fsm.SetData <VarString>("TargetProcedure", typeof(TState).Name);
            Fsm fsmImplement = (Fsm)fsm;

            if (fsmImplement == null)
            {
                throw new GameFrameworkException("FSM is invalid.");
            }
            fsmImplement.ChangeState <ProcedureChangeScene>();
        }
Ejemplo n.º 4
0
        public static async CTask ChangeScene <TState>(this IFsm fsm, string sceneName) where TState : FsmState
        {
            await LoadingUI.Show();

            Mgr.UI.CloseAllOpenUi();
            fsm.SetData <VarString>("SceneName", sceneName);
            fsm.SetData <VarString>("TargetProcedure", typeof(TState).Name);
            Fsm fsmImplement = (Fsm)fsm;

            if (fsmImplement == null)
            {
                throw new GameFrameworkException("FSM is invalid.");
            }
            fsmImplement.ChangeState <ProcedureChangeScene>();
        }
        protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
            //1 产生管道职能
            //管道产生计时器    经过的秒
            m_PipeSpawnTimer += elapseSeconds;
            // 如果管道产生计时器 大于等于 管道产生时间间隔
            if (m_PipeSpawnTimer >= m_PipeSpawnTime)
            {
                m_PipeSpawnTimer = 0;//计时器清零
                //随机设置管道产生时间 在3到5之间
                m_PipeSpawnTime = Random.Range(3f, 5f);

                //产生管道
                GameEntry.Entity.ShowPipe(new PipeData(GameEntry.Entity.GenerateSerialId(), 2, 1f));
            }

            //2 切换场景职能
            if (m_IsReturnMenu)//如果返回主菜单的标志值为true
            {
                m_IsReturnMenu = false;
                procedureOwner.SetData <VarInt>(Constant.ProcedureData.NextSceneId, GameEntry.Config.GetInt("Scene.Menu"));
                ChangeState <ProcedureChangeScene>(procedureOwner);
            }
        }
Ejemplo n.º 6
0
    private void OnApplyDamageEvent(IFsm <Monster> fsm, object sender, object userData)
    {
        int damageHP = (int)userData;

        fsm.SetData <VarInt>(Constant.EntityData.DamageHP, damageHP);
        ChangeState <MonsterHurtState>(fsm);
    }
Ejemplo n.º 7
0
 private void InitFsm()
 {
     m_fsm = GameEntry.Fsm.CreateFsm(Utility.Text.GetFullName(GetType(), Id.ToString())
                                     , this, GameEntry.fsmMgr.GetAllFsmState <Avatar>());
     m_fsm.Start <StateIdle>();
     m_fsm.SetData(fsmNextData, null);
     m_flag       = new StateFlag();
     m_changeFlag = false;
 }
 protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
 {
     base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
     if (isLoad)
     {
         procedureOwner.SetData <VarString>("NextScene", "CreateRoleScene");
         ChangeState <ProcedureLoad>(procedureOwner);
     }
 }
 protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
 {
     if (!IsStart)
     {
         IsStart = true;
         procedureOwner.SetData("NextSceneId", new VarInt(GameEntry.Config.GetInt("Scene.Menu")));
         ChangeState <HotProcedureChangeScene>(procedureOwner);
     }
 }
Ejemplo n.º 10
0
 protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
 {
     base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
     if (IsStartGame)
     {
         //切换到主要场景
         procedureOwner.SetData <VarInt>(Constant.ProcedureData.NextSceneId, GameEntry.Config.GetInt("Scene.Main"));
         ChangeState <ProcedureChangeScene>(procedureOwner);
     }
 }
Ejemplo n.º 11
0
    protected override void OnEnter(IFsm <ProcedureGame> procedureOwner)
    {
        base.OnEnter(procedureOwner);
        Log.Info("StateBuildFenceArea OnEnter");
        GameEntry.Event.Subscribe(EvtClickScene.EventId, OnEvtClickScene);
        ZooController.Inst.SwipeGesture.onBegin.Add(OnSwipeMove);
        ZooController.Inst.SwipeGesture.onMove.Add(OnSwipeMove);

        procedureOwner.SetData <VarInt>("EditState", ProcedureGame.Editing);
        ZooController.Inst.EnableSwipe = false;
    }
Ejemplo n.º 12
0
    protected internal override void OnUpdate(IFsm <ProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);

        //Log.Debug("procedure preload update " + elapseSeconds + "  " + realElapseSeconds);
        if (exitGame)
        {
            exitGame = false;
            procedureOwner.SetData <bool>("fromGame", true);
            ChangeState <ProcedureMMain>(procedureOwner);
            //SceneManager.UnloadSceneAsync("Game");

            GameEntry.Scene.UnloadScene(SceneId.Game);
        }
    }
Ejemplo n.º 13
0
    protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);

        if (isLoad)
        {
            procedureOwner.SetData <VarString>("NextScene", "HomeScene");
            ChangeState <ProcedureLoad>(procedureOwner);
        }

        float mouseX = Input.GetAxis("Mouse X");

        if (Input.GetKey(KeyCode.Mouse1))
        {
            foreach (Entity item in ModelManger.Instance._EntityComponent.GetAllLoadedEntities())
            {
                item.transform.Rotate(Vector3.down * mouseX * 10);
            }
        }
    }
        public override void OnUpdate(IFsm <IProcedureManager> procedureOwner)
        {
            if (m_CurrentGame != null && !m_CurrentGame.IsGameOver)
            {
                m_CurrentGame.Update(HotfixEntry.deltaTime, HotfixEntry.unscaleDeltaTime);
                return;
            }

            if (!m_GotoMenu)
            {
                m_GotoMenu             = true;
                m_GotoMenuDelaySeconds = 0f;
            }

            m_GotoMenuDelaySeconds += HotfixEntry.deltaTime;
            if (m_GotoMenuDelaySeconds >= GameOverDelayedSeconds)
            {
                procedureOwner.SetData <VarInt>(Constant.ProcedureData.NextSceneId, new VarInt(GameEntry.Config.GetInt("Scene.Menu")));
                RuntimeProcedure.ChangeProcedure <HotProcedureChangeScene>(procedureOwner);
            }
        }
Ejemplo n.º 15
0
        protected override void OnUpdate(IFsm <IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);

            m_PipeSpawnTimer += elapseSeconds;

            if (m_PipeSpawnTimer >= m_PipeSpawnTime)
            {
                m_PipeSpawnTimer = 0;
                m_PipeSpawnTime  = Random.Range(3f, 5f);
                GameEntry.Entity.ShowPipe(new PipeData(GameEntry.Entity.GenerateSerialId(), 2, 1f));
            }


            if (m_IsReturnMenu)
            {
                m_IsReturnMenu = false;

                procedureOwner.SetData <VarInt32>(Constant.ProcedureData.NextSceneId, GameEntry.Config.GetInt("Scene.Menu"));
                ChangeState <ProcedureChangeScene>(procedureOwner);
            }
        }
Ejemplo n.º 16
0
    protected override void OnEnter(IFsm <ProcedureGame> procedureOwner)
    {
        base.OnEnter(procedureOwner);
        Log.Info("StateBuild OnEnter");
        GameEntry.Event.Subscribe(EvtEditRotation.EventId, OnEvtEditRotation);
        GameEntry.Event.Subscribe(EvtEditRestore.EventId, OnEvtEditRestore);
        GameEntry.Event.Subscribe(EvtClickScene.EventId, OnEvtClickScene);
        GameEntry.Event.Subscribe(EvtChangeTouchState.EventId, OnEvtChangeTouchState);
        ZooController.Inst.SwipeGesture.onMove.Add(OnSwipeMove);
        ZooController.Inst.SwipeGesture.onBegin.Add(OnSwipeBegin);
        ZooController.Inst.SwipeGesture.onEnd.Add(OnSwipeEnd);

        m_Fsm = GameEntry.Fsm.CreateFsm(this,
                                        new StateBuildInEditModeUnSel(),
                                        new StateBuildInEditModeSel(),
                                        new StateBuildInBuildMode());
        m_Fsm.Start <StateBuildInBuildMode>();

        procedureOwner.SetData <VarInt>("EditState", ProcedureGame.Editing);
        UIZooView.Inst.UI.m_BtnHand.visible = true;
        GameEntry.TempData.ObjectScene.DirtyList.Clear();
    }
Ejemplo n.º 17
0
    protected override void OnEnter(IFsm <ProcedureGame> procedureOwner)
    {
        base.OnEnter(procedureOwner);
        Log.Info("StateEdit OnEnter");
        GameEntry.Event.Subscribe(EvtChangeLookState.EventId, OnEvtChangeLookState);
        GameEntry.Event.Subscribe(EvtChangeTouchState.EventId, OnEvtChangeTouchState);
        GameEntry.Event.Subscribe(EvtClickScene.EventId, OnEvtClickScene);
        GameEntry.Event.Subscribe(EvtEditRotation.EventId, OnEvtEditRotation);
        GameEntry.Event.Subscribe(EvtEditRestore.EventId, OnEvtEditRestore);
        GameEntry.Event.Subscribe(EvtConfirmEdit.EventId, OnEvtConfirmEdit);
        ZooController.Inst.SwipeGesture.onMove.Add(OnSwipeMove);
        ZooController.Inst.SwipeGesture.onBegin.Add(OnSwipeBegin);

        m_Fsm = GameEntry.Fsm.CreateFsm(this,
                                        new StateEditInBatchModeUnLock(),
                                        new StateEditInBatchModeLock(),
                                        new StateEditInUnbatchModeUnSel(),
                                        new StateEditInUnbatchModeSel());
        m_Fsm.Start <StateEditInUnbatchModeUnSel>();

        procedureOwner.SetData <VarInt>("EditState", ProcedureGame.Editing);
        GameEntry.TempData.ObjectScene.DirtyList.Clear();
    }
Ejemplo n.º 18
0
        public IEnumerator FsmTestWithEnumeratorPasses()
        {
            // Use the Assert class to test conditions.
            // yield to skip a frame

            AshUnityEntry.New();
            IFsmManager fsmManager = AshEntry.GetModule <IFsmManager>();


            FsmOwer fsmOwer = new FsmOwer();
            Status1 status1 = new Status1();
            Status2 status2 = new Status2();

            //fsmManager.CreateFsm<FsmOwer>( fsmOwer, status1, status2);
            fsmManager.CreateFsm <FsmOwer>("Test", fsmOwer, status1, status2);

            Log.Debug("有限状态机的数量时{0}", fsmManager.Count);
            IFsm <FsmOwer> fsm = fsmManager.GetFsm <FsmOwer> ("Test");

            Assert.IsNotNull(fsm);

            VarString v = new VarString();

            v.SetValue("Variable data");             //			v.Value = "Variable data";
            fsm.SetData("data", v);

            fsm.Start <Status1> ();
            Assert.AreEqual(fsm.CurrentState, status1);

            yield return(new WaitForSeconds(1));

            fsm.FireEvent(this, 1, "userData");
//			Assert.AreEqual (fsm.CurrentState, status2);

            yield return(null);
        }
Ejemplo n.º 19
0
    private void OnEvtFinishEdit(object sender, GameEventArgs e)
    {
        var evt = e as EvtFinishEdit;

        m_Fsm.SetData <VarInt>("EditState", evt.IsConfirmEdit ? ConfirmEdit : CancelEdit);
    }
Ejemplo n.º 20
0
    /// <summary>
    /// 有限状态机状态轮询时调用。
    /// </summary>
    /// <param name="fsm">有限状态机引用。</param>
    /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
    /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
    protected override void OnUpdate(IFsm <Monster> fsm, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(fsm, elapseSeconds, realElapseSeconds);

        if (fsm.Owner.IsAtkCDing || GlobalGame.IsPause)
        {
            return;
        }

        if (fsm.Owner.IsLockingAim)
        {
            FightEntity aim = fsm.Owner.LockingAim;
            if (aim == null || aim.IsDead)
            {
                ChangeState <MonsterIdleState>(fsm);
                return;
            }

            float distance = AIUtility.GetDistance(fsm.Owner, aim);

            /* 进入攻击范围,直接攻击 */
            if (fsm.Owner.CheckInAtkRange(distance))
            {
                fsm.SetData <VarInt> (Constant.EntityData.LockAimID, aim.Entity.Id);
                ChangeState <MonsterAtkState> (fsm);
            }
            /* 在视线范围内,则继续移动 */
            else if (fsm.Owner.CheckInSeekRange(distance))
            {
                if (fsm.CurrentState.GetType() != typeof(MonsterWalkState))
                {
                    ChangeState <MonsterWalkState>(fsm);
                }
            }
            else
            {
                fsm.Owner.UnlockAim();
            }
            return;
        }

        /* 判断是否有敌人进入追踪或攻击范围 */
        CampType camp = fsm.Owner.GetImpactData().Camp;

        GameObject[] aims = GameObject.FindGameObjectsWithTag("Creature");
        foreach (GameObject obj in aims)
        {
            FightEntity aim = obj.GetComponent <FightEntity> ();

            if (aim.IsDead == false &&
                AIUtility.GetRelation(aim.GetImpactData().Camp, camp) == RelationType.Hostile)
            {
                float distance = AIUtility.GetDistance(fsm.Owner, aim);

                /* 进入攻击范围,直接攻击 */
                if (fsm.Owner.CheckInAtkRange(distance))
                {
                    fsm.SetData <VarInt> (Constant.EntityData.LockAimID, aim.Entity.Id);
                    ChangeState <MonsterAtkState> (fsm);
                    break;
                }
                /* 进入追踪范围,向目标移动 */
                else if (fsm.Owner.CheckInSeekRange(distance))
                {
                    fsm.Owner.LockAim(aim);
                    ChangeState <MonsterWalkState>(fsm);
                    break;
                }
            }
        }
    }