private ScaredPlant DeepCopy() { ScaredPlant other = (ScaredPlant)this.MemberwiseClone(); other.runningDirection = this.runningDirection; other.KeepRunning = this.KeepRunning; other.isRunning = this.isRunning; return(other); }
// Why does Instantiate(prefab) clear values from the class I'm giving it? Is there a interface I can override or w.e to do this automatically?? public override void Initialize(CellController parent) { base.Initialize(parent); ScaredPlant scaredParent = parent as ScaredPlant; if (scaredParent) { runningDirection = scaredParent.runningDirection; } }
public override bool Grow() { bool hasGrown = false; if (isRunning && KeepRunning) { CellController neighbour = this.Grid.GetCellInDirection(this.X, this.Y, runningDirection); if (CanClaim(neighbour)) { neighbour.Claim(this); hasGrown = true; } } foreach (GridDirection direction in DirectionsToRunFrom) { CellController neighbour = this.Grid.GetCellInDirection(this.X, this.Y, direction); if (NeighbourIsPlant(neighbour)) { CellController oppositeNeighbour = this.Grid.GetCellInDirection(this.X, this.Y, direction.Opposite()); if (CanClaim(oppositeNeighbour)) { if (!isRunning) { isRunning = true; runningDirection = direction.Opposite(); } ScaredPlant copy = DeepCopy(); copy.runningDirection = direction.Opposite(); oppositeNeighbour.Claim(copy); hasGrown = true; } } } return(hasGrown); }