Exemplo n.º 1
0
        public override void Enter(MonoBehaviour origin)
        {
            BlueGrass BlueGrass = origin as BlueGrass;

            _leaf.CurrentModel = Object.Instantiate(BlueGrass.GetLeafModel(), _leaf.Position, BlueGrass.GetLeafModel().transform.rotation, BlueGrass.transform);
            _initialScale      = _leaf.CurrentModel.transform.localScale;

            Mesh mesh = _leaf.CurrentModel.GetComponentInChildren <MeshFilter>().mesh;

            Vector3[] vertices = mesh.vertices;
            Color32[] colours  = new Color32[vertices.Length];

            for (int i = 0, length = vertices.Length; i < length; i += 10)
            {
                byte    value  = (byte)(((i * 1.5f / length) < _leaf.ShadowAtLocation) ? 255 : 0);
                Color32 colour = new Color32(value, value, value, value);

                for (int j = 0; j < 10; ++j)
                {
                    colours[i + j] = colour;
                }
            }
            mesh.colors32 = colours;

            Vector3 rotation = _leaf.CurrentModel.transform.localEulerAngles;

            rotation.y = Random.Range(0f, 359.9999f);
            _leaf.CurrentModel.transform.localEulerAngles = rotation;
        }
Exemplo n.º 2
0
 public BlueGrassLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, BlueGrass BlueGrass, bool firstLeaf)
     : this(position, dailySeedGrowthChance, averageSeedSurvivalDays, maxSeedSurvivalVariation, BlueGrass, BlueGrass.gameObject.GetComponent <Plant>().ShadowFactor, firstLeaf)
 {
 }
Exemplo n.º 3
0
        public BlueGrassLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, BlueGrass BlueGrass, float shadowAtPos, bool firstLeaf)
        {
            ShadowAtLocation = shadowAtPos;
            Position         = position;

            GameObject               model           = null;
            BlueGrassSeedState       seedState       = new BlueGrassSeedState(model, dailySeedGrowthChance, Random.Range((int)(averageSeedSurvivalDays - maxSeedSurvivalVariation), (int)(averageSeedSurvivalDays + maxSeedSurvivalVariation + 1)), this, firstLeaf);
            BlueGrassGrowingState    growingState    = new BlueGrassGrowingState(this);
            BlueGrassFullyGrownState fullyGrownState = new BlueGrassFullyGrownState(this);
            BlueGrassDormantState    dormantState    = new BlueGrassDormantState(this);

            StateTransition seedToGrowing = new StateTransition
                                                ((originObject, originState)
                                                =>
            {
                if (!(originState as BlueGrassSeedState).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 BlueGrassGrowingState).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.Winter)
                {
                    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.Winter)
                {
                    return(StateTransitionResult.NO_ACTION);
                }
                return(StateTransitionResult.STACK_POP);
            });

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


            _stateMachine = new StateMachine(BlueGrass, seedState);
        }