コード例 #1
0
 public void CreateTree(RainGridController grid, RainGridNode parent, int numRows, int numCols)
 {
     this.grid = grid;
     this.parent = parent;
     numChildren = numRows;
     RainGridNode temp = null;
     children = new RainGridNode[numChildren];
     float tempZFloat = grid.startZ;
     float tempXFloat = grid.startX;
     Vector3 tempLocation;
     for (int i = 0; i < numChildren; i++){
         temp = (RainGridNode)ScriptableObject.CreateInstance ("RainGridNode");
         if (this.parent == null)
         {
             //tempZFloat += grid.zStep;
             // Assume this is a direct child of the root. Update z steps
             tempLocation = new Vector3(location[0],location[1],tempZFloat + i*grid.xStep);
             temp.Init (tempLocation);
         }
         else if (this.parent.parent == null)
         {
             //tempXFloat += grid.xStep;
             // Assume this is a direct child of the root. Update z steps
             tempLocation = new Vector3(tempXFloat + i*grid.xStep,location[1],location[2]);
             temp.Init (tempLocation);
         }
         else
         {
             Debug.LogError ("Impossible case, this RainGridNode has no parent pointer AND no parent.parent pointer");
         }
         //temp.Init (location);
         temp.CreateTree(grid,this,numCols,0);
         children[i] = temp;
     }
 }
コード例 #2
0
    // 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;
        on = onSwitch.GetComponent<Toggle> ();
        intensity = IntensitySlider.GetComponent<Slider> ();

        // Initialize the random number generator
        // Use any integer seed value to track your procedural rainfall
        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 = (RainGridNode)ScriptableObject.CreateInstance("RainGridNode");
        // Give it a base location Vector3 (the center point of the rain grid)
        location = new Vector3 (centerX, 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, numXSteps);
        // Now prime the pump by adding drops to the available drops queue
        StartCoroutine (PopulateDrops());
        // And now start dropping them on a regular timer
        StartCoroutine (StartDropping ());
        // Implied: Gravity is included in the drop prefab - Rain will begin with the instantion of this script.
    }