public override void Enter(MonoBehaviour origin) { Grass grass = origin as Grass; _leaf.CurrentModel = Object.Instantiate(grass.GetLeafModel(), _leaf.Position, grass.GetLeafModel().transform.rotation, grass.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)((((float)i / 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; }
public GrassLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, Grass grass, bool firstLeaf) : this(position, dailySeedGrowthChance, averageSeedSurvivalDays, maxSeedSurvivalVariation, grass, grass.gameObject.GetComponent <Plant>().ShadowFactor, firstLeaf) { }
public GrassLeaf(Vector3 position, float dailySeedGrowthChance, uint averageSeedSurvivalDays, uint maxSeedSurvivalVariation, Grass grass, float shadowAtPos, bool firstLeaf) { ShadowAtLocation = shadowAtPos; Position = position; GameObject model = null; GrassSeedState seedState = new GrassSeedState(model, dailySeedGrowthChance, Random.Range((int)(averageSeedSurvivalDays - maxSeedSurvivalVariation), (int)(averageSeedSurvivalDays + maxSeedSurvivalVariation + 1)), this, firstLeaf); GrassGrowingState growingState = new GrassGrowingState(this); GrassFullyGrownState fullyGrownState = new GrassFullyGrownState(this); GrassDormantState dormantState = new GrassDormantState(this); StateTransition seedToGrowing = new StateTransition ((originObject, originState) => { if (!(originState as GrassSeedState).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 GrassGrowingState).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(grass, seedState); }