Пример #1
0
        private void Start()
        {
            Plant plant = GetComponent <Plant>();

            GenericSeedState       seedState       = new GenericSeedState(_dailySeedGrowthChance, Random.Range((int)(_averageSeedSurvivalDays - _maxSeedSurvivalVariation), (int)(_averageSeedSurvivalDays + _maxSeedSurvivalVariation + 1)));
            GenericGrowingState    growingState    = new GenericGrowingState();
            GenericFullyGrownState fullyGrownState = new GenericFullyGrownState();

            StateTransition seedToGrowing = new StateTransition
                                                ((originObject, originState)
                                                =>
            {
                if (!(originState as GenericSeedState).WillGrow)
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_SWAP);
            });

            seedToGrowing.TargetState = growingState;
            seedState.Transitions.Add(seedToGrowing);

            StateTransition growingToGrown = new StateTransition
                                                 ((originObject, originState)
                                                 =>
            {
                if (!(originState as GenericGrowingState).HasReachedTarget())
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_SWAP);
            });

            growingToGrown.TargetState = fullyGrownState;
            growingState.Transitions.Add(growingToGrown);

            _stateMachine = new StateMachine(this, seedState);
        }
Пример #2
0
        public TestPlantLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, TestPlant TestPlant, float shadowAtPos, bool firstLeaf)
        {
            ShadowAtLocation = shadowAtPos;
            Position         = position;

            GameObject               model           = null;
            TestPlantSeedState       seedState       = new TestPlantSeedState(model, dailySeedGrowthChance, Random.Range((int)(averageSeedSurvivalDays - maxSeedSurvivalVariation), (int)(averageSeedSurvivalDays + maxSeedSurvivalVariation + 1)), this, firstLeaf);
            TestPlantGrowingState    growingState    = new TestPlantGrowingState(this);
            TestPlantFullyGrownState fullyGrownState = new TestPlantFullyGrownState(this);
            TestPlantDormantState    dormantState    = new TestPlantDormantState(this);

            StateTransition seedToGrowing = new StateTransition
                                                ((originObject, originState)
                                                =>
            {
                if (!(originState as TestPlantSeedState).WillGrow)
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_SWAP);
            });

            seedToGrowing.TargetState = growingState;
            seedState.Transitions.Add(seedToGrowing);

            StateTransition growingToGrown = new StateTransition
                                                 ((originObject, originState)
                                                 =>
            {
                if (!(originState as TestPlantGrowingState).HasReachedTarget())
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_SWAP);
            });

            growingToGrown.TargetState = fullyGrownState;
            growingState.Transitions.Add(growingToGrown);

            StateTransition toDormant = new StateTransition
                                            ((originObject, originState)
                                            =>
            {
                if (SeasonChanger.Instance.GetSeason() == Season.Autumn)
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_PUSH);
            });

            toDormant.TargetState = dormantState;
            growingState.Transitions.Add(toDormant);
            fullyGrownState.Transitions.Add(toDormant);
            seedState.Transitions.Add(toDormant);

            StateTransition leaveDormancy = new StateTransition
                                                ((originObject, originState)
                                                =>
            {
                if (SeasonChanger.Instance.GetSeason() != Season.Autumn)
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_POP);
            });

            leaveDormancy.TargetState = null;
            dormantState.Transitions.Add(leaveDormancy);


            _stateMachine = new StateMachine(TestPlant, seedState);
        }