public override void Update(MonoBehaviour origin)
        {
            WillGrow = WillGrow || (Random.value <= _spawnOddsPerDay);
            if (WillGrow)
            {
                Vector3Int dir         = Vector3Int.zero;
                TestPlant  originPlant = (origin as TestPlant);
                Plant      plant       = originPlant.GetComponent <Plant>();
                Plant      hit         = plant.VegetationSys.GetOccupationNear(_leaf.Position, ref dir);

                if (hit)
                {
                    if (hit.GetComponent <TestPlant>() != null)
                    {
                        originPlant.DeregisterLeaf(_leaf, false);
                        Object.Destroy(_model);
                        return;
                    }
                    hit.OnAttemptDestroy(dir);
                }
                if (!plant.VegetationSys.AttemptOccupy(origin.transform.position, plant))
                {
                    originPlant.DeregisterLeaf(_leaf, false);
                    Object.Destroy(_model);
                }
                return;
            }

            if (--_survivalDaysLeft == 0)
            {
                (origin as TestPlant).DeregisterLeaf(_leaf, false);
                Object.Destroy(_model);
            }
        }
        public override void Update(MonoBehaviour origin)
        {
            if (Random.Range(0f, 1f) <= _chanceToSpawn)
            {
                Vector3 targetPos   = _leaf.Position;
                float   randomAngle = Random.Range(0f, Mathf.PI * 2f);
                targetPos += new Vector3(Mathf.Cos(randomAngle) * _distanceSpawned, 0f, Mathf.Sin(randomAngle) * _distanceSpawned);
                TestPlant plant = origin as TestPlant;
                plant.AddTestPlantToSystem(targetPos, _leaf.Position);

                if (--_amountSpawned == 0)
                {
                    plant.DeregisterLeaf(_leaf, true);
                }
            }
        }
        public override void Enter(MonoBehaviour origin)
        {
            TestPlant TestPlant = origin as TestPlant;

            _leaf.CurrentModel = Object.Instantiate(TestPlant.GetLeafModel(), _leaf.Position, TestPlant.GetLeafModel().transform.rotation, TestPlant.transform);
            _mesh = _leaf.CurrentModel.GetComponentInChildren <MeshFilter>().mesh;
            Vector3[] vertices = _mesh.vertices;
            _colours = new Color32[vertices.Length];

            Color32 colour = new Color32(255, 255, 255, 255);

            for (int i = 0, length = vertices.Length; i < length; ++i)
            {
                _colours[i] = colour;
            }
            _mesh.colors32 = _colours;

            Vector3 rotation = _leaf.CurrentModel.transform.localEulerAngles;

            rotation.y = Random.Range(0f, 359.9999f);
            _leaf.CurrentModel.transform.localEulerAngles = rotation;
        }
        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);
        }
 public TestPlantLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, TestPlant TestPlant, bool firstLeaf)
     : this(position, dailySeedGrowthChance, averageSeedSurvivalDays, maxSeedSurvivalVariation, TestPlant, TestPlant.gameObject.GetComponent <Plant>().ShadowFactor, firstLeaf)
 {
 }