// Every MonoBehavior has a Start function which is called upon instantiation into the Scene / Hierarchy void Start() { // Set class specific constants origin = new Vector3 (0, 0, 0); identity = Quaternion.identity; InitialVelocity = origin; // Initialize the random number generator // Use any integer seed value to track your procedural river creation seed = new Seed (); // Initialize drop pool and living drop counter. // Ideally numDropsAvailable will track how many drops have not been processed into rain. // This should end up being slightly less than or equal to the current size of the Queue in any given frame. availableDrops = new Queue<GameObject>(); numDropsAvailable = 0; // Create the root node of the showerhead tree root = (RiverGridNode)ScriptableObject.CreateInstance("RiverGridNode"); // Give it a base location Vector3 (the center point of the river grid) location = new Vector3 (startX, centerY, centerZ); root.Init (location); // Recursively create the showerhead tree with a pointer to the following objects: // This class, a null parent, and the dimensions of the tree. root.CreateTree (this, null, numZSteps, numYSteps); // Now prime the pump by adding drops to the available drops queue StartCoroutine (PopulateDrops()); // And now start dropping them on a regular timer dropping = StartDropping (); StartCoroutine (dropping); // Implied: Gravity and constant force is included in the drop prefab - River will begin with the instantion of this script. }
public void UpdateRiverTree() { bool wasOn = on.isOn; root.Kill (); root = null; if (wasOn == true) { StopCoroutine (dropping); on.isOn = false; } // Create the root node of the showerhead tree root = (RiverGridNode)ScriptableObject.CreateInstance("RiverGridNode"); // Give it a base location Vector3 (the center point of the river grid) location = new Vector3 (startX, centerY, startZ); //Debug.LogError ("Creating riverGridNodes at center: " + location [0] + "," + location [1] + "," + location [2]); root.Init (location); // Recursively create the showerhead tree with a pointer to the following objects: // This class, a null parent, and the dimensions of the tree. root.CreateTree (this, null, numZSteps, numYSteps); if (wasOn == true) { on.isOn = true; } }