コード例 #1
0
        public void Init(float animalAnimationSpeed, float animalMoveSpeed, int idxInTeam,
                         float animalAcceleration, float rotateSpeed)
        {
            this.animalAnimationSpeed = animalAnimationSpeed;
            this.moveSpeed            = animalMoveSpeed * 0.001f;
            this.moveSpeedBak         = this.moveSpeed;
            this.animalAccelerationMS = animalAcceleration * 0.001f;
            this.rotateSpeedMS        = rotateSpeed * 0.001f;
            this.idxInTeam            = idxInTeam;
            isMoving             = false;
            isPassedRoad         = false;
            isArrivedNextRoadPos = false;
            arrivedLastPos       = false;
            isRotateback         = false;
            isRotateForward      = false;
            rotateAngle          = 0f;
            waitFrameCount       = 0;

            //var a = roadModel.animalRoadSegment[roadModel.animalRoadSegment.Count - 1];
            //var b = roadModel.crossRoadRectArea[roadModel.animalRoadSegment.Count - 1].height;
            //Debug.LogError(a + b * Vector3.forward + Vector3.forward * standardAnimalBoxSize.z);
            if (fsm == null)
            {
                fsm = new FSMCrossRoadAnimal(this);
                fsm.AddState(new StateCrossRoadAnimalIdle((int)FSMCrossRoadAnimalState.Idle, fsm));
                fsm.AddState(new StateCrossRoadAnimalCrossRoad((int)FSMCrossRoadAnimalState.CrossRoad, fsm));
                fsm.AddState(new StateCrossRoadRunToEndPoint((int)FSMCrossRoadAnimalState.RunToEndPoint, fsm));
            }
            fsm.GotoState((int)FSMCrossRoadAnimalState.Idle);
            fsm.Run();

            DebugFile.GetInstance().MarkGameObject(mainGameObject, "Animal-{0}", idxInTeam);
        }
コード例 #2
0
ファイル: FSMTest.cs プロジェクト: GITHUB243884919/COCSLG
 void Start()
 {
     machine = new FSMMachineTest();
     state1  = new FSMState1("state1", machine);
     state2  = new FSMState2("state2", machine);
     machine.AddState(state1);
     machine.AddState(state2);
     machine.GotoState("state1");
 }
コード例 #3
0
ファイル: SLGTurnSystem.cs プロジェクト: yening520/SLGGame
        public override void OnInitialize(IResourceLoader loader, params object[] pars)
        {
            TurnAgent agent = pars[0] as TurnAgent;

            m_TurnFSM = new FSMMachine();
            m_TurnFSM.AddState(new SLGTransitionTurn(agent));
            m_TurnFSM.AddState(new SLGPlayerTurn(agent));
            m_TurnFSM.AddState(new SLGOppositeTurn(agent));
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: GITHUB243884919/COCSLG
        public void Awake()
        {
            Logger.LogWarp.Log("GameApp Awake");
            FSMState stateUpdate = new StateUpdate("Update", gameFSMMachine);
            FSMState stateLogin  = new StateLogin("Login", gameFSMMachine);
            FSMState stateHome   = new StateHome("Home", gameFSMMachine);

            gameFSMMachine.AddState(stateUpdate);
            gameFSMMachine.AddState(stateLogin);
            gameFSMMachine.AddState(stateHome);
            gameFSMMachine.SetDefaultState("Update");
        }
コード例 #5
0
        public void Launch()
        {
            m_ResLoader   = new ResourceLoader();
            m_UIManager   = CreateSystem <UIManager>();
            m_InputSystem = InputSystem.Instance;

            m_SceneFSM = new FSMMachine();
            m_SceneFSM.AddState(new StartScene());
            m_SceneFSM.AddState(new FightingScene());
            m_SceneFSM.SetDefaultState(SceneDefines.SCENE_START);

            GameCamera.Instance.Camera = Camera.main;
        }
コード例 #6
0
        void Start()
        {
            _fsm = new FSMMachine();

            IdleState   idle      = new IdleState();
            SelectState selecting = new SelectState();
            ViewState   viewing   = new ViewState();
            UploadState uploading = new UploadState();

            _fsm.AddState(idle);
            _fsm.AddState(selecting);
            _fsm.AddState(viewing);
            _fsm.AddState(uploading);

            _fsm.initialCurrentState = idle;
        }
コード例 #7
0
    // Start is called before the first frame update
    void Start()
    {
        idle          = new State("Idle");
        idle.OnEnter += (IState state) => {
            Debug.Log("进入Idle状态");
        };

        move           = new State("Move");
        move.OnUpdate += (float deltaTime) => {
            transform.position += transform.forward * speed;
        };

        idle2Move          = new Transition(idle, move);
        idle2Move.OnCheck += () => {
            return(isMove);
        };
        idle.AddTransition(idle2Move);

        move2idle          = new Transition(move, idle);
        move2idle.OnCheck += () => {
            return(!isMove);
        };

        move.AddTransition(move2idle);

        fSMMachine = new FSMMachine("Root", idle);
        fSMMachine.AddState(move);
    }
コード例 #8
0
    /// <summary>
    /// 初始化状态机
    /// </summary>
    private void InitFSM()
    {
        changeIntensity          = new State("ChangeIntensity");
        changeIntensity.OnEnter += (IState state) => {
            isReset     = true;
            isAnimation = true;
        };
        changeIntensity.OnUpdate += (float f) => {
            if (isAnimation)
            {
                if (isReset)
                {
                    if (FadeTo(MaxIntensity))
                    {
                        isReset     = false;
                        isAnimation = false;
                    }
                }
                else
                {
                    if (FadeTo(target))
                    {
                        isReset = true;
                    }
                }
            }
            else
            {
                target      = Random.Range(0.3f, 0.7f);
                isAnimation = true;
            }
        };

        changeColor          = new State("ChangeColor");
        changeColor.OnEnter += (IState state) => {
            isAnimation = false;
        };
        changeColor.OnUpdate += (float f) => {
            if (isAnimation)
            {
                if (colorTimer >= 1f)
                {
                    isAnimation = false;
                }
                else
                {
                    colorTimer   += Time.deltaTime * 1f;
                    myLight.color = Color.Lerp(startColor, targetColor, colorTimer);
                }
            }
            else
            {
                float r = Random.Range(0f, 1f);
                float g = Random.Range(0f, 1f);
                float b = Random.Range(0f, 1f);
                targetColor = new Color(r, g, b);
                startColor  = myLight.color;
                colorTimer  = 0f;
                isAnimation = true;
            }
        };

        color2Intensity          = new Transition(changeColor, changeIntensity);
        color2Intensity.OnCheck += () => {
            return(!isChangeColor);
        };
        changeColor.AddTransition(color2Intensity);

        intensity2color          = new Transition(changeIntensity, changeColor);
        intensity2color.OnCheck += () => {
            return(isChangeColor);
        };
        changeIntensity.AddTransition(intensity2color);

        open = new FSMMachine("Open", changeIntensity);
        open.AddState(changeColor);

        open.OnEnter += (IState state) => {
            myLight.intensity = MaxIntensity;
        };
        close          = new State("Close");
        close.OnEnter += (IState state) => {
            myLight.intensity = 0f;
        };

        open2Close          = new Transition(open, close);
        open2Close.OnCheck += () =>
        {
            return(!isOpen);
        };
        open2Close.OnTransition += () =>
        {
            return(FadeTo(0f));
        };
        open.AddTransition(open2Close);


        close2Open          = new Transition(close, open);
        close2Open.OnCheck += () =>
        {
            return(isOpen);
        };
        close2Open.OnTransition += () =>
        {
            return(FadeTo(MaxIntensity));
        };
        close.AddTransition(close2Open);

        lightFSM = new FSMMachine("LightFSM", open);
        lightFSM.AddState(close);
    }