private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Esempio n. 2
0
    public static IEnumerator CreateMap()
    {
        int throttle = 0;

        for (int y = 0; y < SlicesInY; y++)
        {
            for (int x = 0; x < SlicesInXZ; x++)
            {
                for (int z = 0; z < SlicesInXZ; z++)
                {
                    Slice slice = Generator_Terrain.GenerateSlice(x, y, z);
                    Instance.Slices[x, y, z] = slice;

                    // Create the visualization offset from the array and connect it to the slice.
                    Instance.Slices[x, y, z].SetSliceMeshSides(Instance.CreateSliceMesh(slice, x * VoxelsInXZ, y, z * VoxelsInXZ));

                    // Track which slices are visible on map creation.
                    if (SliceRenderMode == SliceRenderMode.Full)
                    {
                        SetSliceVisible(slice);
                    }
                    else if (SliceRenderMode == SliceRenderMode.Adaptive && slice.Y - YOffset <= CameraMovementManager.CurrentYPosition)
                    {
                        SetSliceVisible(slice);
                    }
                    else if (SliceRenderMode == SliceRenderMode.Slice && slice.Y - YOffset == CameraMovementManager.CurrentYPosition)
                    {
                        SetSliceVisible(slice);
                    }

                    throttle++;
                    if (throttle >= Throttle_Generation)
                    {
                        throttle = 0;
                        yield return(null);
                    }
                }
            }
        }

        mapCreated = true;

        yield return(null);                    // wait for instantiation of all slice meshes before accessing any.

        foreach (var slice in Instance.Slices) // Hide the slices that are not visible.
        {
            if (IsSliceHidden(slice))
            {
                slice.SetHidden();
            }

            for (int x = 0; x < VoxelsInXZ; x++)
            {
                for (int z = 0; z < VoxelsInXZ; z++)
                {
                    Voxel v = slice.GetVoxel(slice.X + x, slice.Y + 1, slice.Z + z);
                    if (v == null || v.IsTransparent()) // A TEMPORARY IMPLEMENTATION OF GRASS - HACK MODE
                    {
                        slice.Voxels[x, z].SetUnobstructedAbove();
                    }
                }
            }
        }
    }