예제 #1
0
        public void AddGlobalUndo()
        {
            TerrainUndoStep[] steps = undoSteps.Peek();
            if (steps.Length != terrains.Length)
            {
                Debug.LogWarning("Undo terrains mismatch"); return;
            }

            for (int t = 0; t < terrains.Length; t++)
            {
                if (steps[t] == null)
                {
                    steps[t] = new TerrainUndoStep()
                    {
                        terrain = terrains[t]
                    }
                }
                ;
                if (steps[t].terrain != terrains[t])
                {
                    Debug.LogWarning("Undo terrains mismatch"); return;
                }
                steps[t].Add(terrain.transform.position + terrain.terrainData.size / 2f, terrain.terrainData.size.x + 1);
            }
        }
예제 #2
0
        public void AddUndo(Vector3 pos, float radius)
        {
            TerrainUndoStep[] steps = undoSteps.Peek();
            if (steps.Length != terrains.Length)
            {
                Debug.LogWarning("Undo terrains mismatch"); return;
            }

            for (int t = 0; t < terrains.Length; t++)
            {
                if (steps[t] == null)
                {
                    steps[t] = new TerrainUndoStep()
                    {
                        terrain = terrains[t]
                    }
                }
                ;
                if (steps[t].terrain != terrains[t])
                {
                    Debug.LogWarning("Undo terrains mismatch"); return;
                }
                steps[t].Add(pos, radius);
            }
        }
예제 #3
0
 public void TestUndo(Vector3 pos, float radius)
 {
     TerrainUndoStep[] terrainUndoSteps = new TerrainUndoStep[terrains.Length];
     for (int t = 0; t < terrains.Length; t++)
     {
         terrainUndoSteps[t]         = new TerrainUndoStep();
         terrainUndoSteps[t].terrain = terrains[t];
         terrainUndoSteps[t].Add(pos, radius);
     }
     for (int t = 0; t < terrains.Length; t++)
     {
         terrainUndoSteps[t].Perform();
     }
 }
예제 #4
0
        public void PerformUndo()
        {
            if (currentUndoState < referenceUndoState)                     //performing undo
            {
                if (undoSteps.Count == 0)
                {
                    return;
                }

                TerrainUndoStep[] steps = undoSteps.Pop();

                //saving current state for redo
                TerrainUndoStep[] rSteps = new TerrainUndoStep[steps.Length];
                for (int t = 0; t < steps.Length; t++)
                {
                    rSteps[t] = new TerrainUndoStep();
                    rSteps[t].GetCurrentState(steps[t]);
                }
                redoSteps.Push(rSteps);

                //performing undo
                for (int t = 0; t < steps.Length; t++)
                {
                    steps[t].Perform();
                }
            }
            else if (currentUndoState > referenceUndoState)                     //performing redo
            {
                if (redoSteps.Count == 0)
                {
                    return;
                }

                TerrainUndoStep[] steps = redoSteps.Pop();
                for (int t = 0; t < steps.Length; t++)
                {
                    steps[t].Perform();
                }
            }

            //if (currentUndoState == referenceUndoState) //non-brush update, doing nothing

            referenceUndoState = currentUndoState;
        }
예제 #5
0
            public void GetCurrentState(TerrainUndoStep reference)
            {
                terrain = reference.terrain;

                //heights
                if (reference.heights != null)
                {
                    heights = new Matrix2 <float[, ]>(reference.heights.rect);
                    for (int x = 0; x < heights.rect.size.x; x++)
                    {
                        for (int z = 0; z < heights.rect.size.z; z++)
                        {
                            if (reference.heights[x, z] != null)
                            {
                                heights[x, z] = terrain.terrainData.SafeGetHeights(x * cellSize, z * cellSize, cellSize, cellSize);
                            }
                        }
                    }
                }

                //splats
                if (reference.splats != null)
                {
                    splats = new Matrix2 <float[, , ]>(reference.splats.rect);
                    for (int x = 0; x < splats.rect.size.x; x++)
                    {
                        for (int z = 0; z < splats.rect.size.z; z++)
                        {
                            if (reference.splats[x, z] != null)
                            {
                                splats[x, z] = terrain.terrainData.SafeGetAlphamaps(x * cellSize, z * cellSize, cellSize, cellSize);
                            }
                        }
                    }
                }
            }