Exemplo n.º 1
0
    IEnumerator GenerateSpheres()
    {
        Debug.Log("Generating Camera Space Spheres ...");

        // Find a good sphere size


        // Make sure our bounds have updated positions
        CameraBoundary Bounds = GetComponent <CameraBoundary>();

        Bounds.CalcPositons();

        // Compute how much we move each step between spheres
        float Delta = 2f * (MaxSphereSize - Overlap);

        Debug.Assert(2f * (MinSphereSize - Overlap) > 1f, "Gap between spheres can become very small!");

        // The sum unit offsets between nodes
        Vector3 Offset = new Vector3(Delta, Delta, Delta);

        Debug.Assert(Delta > 0f);

        // Compute our starting and ending sphere positions
        Vector3 StartSpherePos = Bounds.FrontTopLeft;
        Vector3 EndSpherePos   = Bounds.BackBottomRight + 0.5f * Offset;

        Debug.Log("Placing Nodes from " + StartSpherePos + " to " + EndSpherePos);

        // Loop through all space in the camera bounds
        // and plop a sphere node down
        Vector3 CurrentSpherePos = StartSpherePos;

        int id = 0;

        // Loop on X
        for (CurrentSpherePos.x = StartSpherePos.x; // (Redundant)
             CurrentSpherePos.x <= EndSpherePos.x;
             CurrentSpherePos.x += Delta)
        {
            // Loop on Z
            for (CurrentSpherePos.z = StartSpherePos.z;
                 CurrentSpherePos.z <= EndSpherePos.z;
                 CurrentSpherePos.z += Delta)
            {
                // Loop on Y
                for (CurrentSpherePos.y = StartSpherePos.y;
                     CurrentSpherePos.y >= EndSpherePos.y;
                     CurrentSpherePos.y -= Delta) // Note the subtraction here -- we want our spheres to be connected vertically
                {
                    id++;
                    // Debug.Log("Adding node " + " at " + CurrentSpherePos);

                    float Radius = CheckNodeSize(CurrentSpherePos, MaxSphereSize);

                    if (Radius != 0f)
                    {
                        CameraGraphSphereNode Node = InstantiateNode(CurrentSpherePos, id);
                        Node.Radius = Radius;

                        Spheres.Add(Node);

                        if (ShouldOperationYield())
                        {
                            yield return(new WaitForEndOfFrame());
                        }

                        // Compute how much we move each step between spheres
                        Delta = 2f * (Radius - Overlap);
                    }
                }
            }
        }

        Debug.Log("Created " + Spheres.Count + " Spheres");
        yield return(null);
    }