private void SetClass <T>(T cls, Type type) { if (type == BoundType) { boundCalculator = cls as BoundCalculator; } else if (type == CoroutineType) { coroutine = cls as Coroutine; } else if (type == MeshOperationType) { meshOperation = cls as MeshOperation; } else if (type == ObjectPoolType) { objectPool = cls as ObjectPool; } else if (type == VectorOperationType) { vectorOperation = cls as VectorOperation; } }
public static void UndoAdd(HexCell centerCell, TerrainBrush brush) { List <HexCell> cellList = new List <HexCell>(); int centerX = centerCell.coordinates.X; int centerZ = centerCell.coordinates.Z; for (int l = 0, z = centerZ; z >= centerZ - brush.brushRange + 1; l++, z--) { for (int x = centerX - brush.brushRange + 1 + l; x <= centerX + brush.brushRange - 1; x++) { if (HexGrid.instance.GetCell(new HexCoordinates(x, z)) != null) { cellList.Add(HexGrid.instance.GetCell(new HexCoordinates(x, z))); } } } for (int l = 1, z = centerZ + 1; z <= centerZ + brush.brushRange - 1; l++, z++) { for (int x = centerX - brush.brushRange + 1; x <= centerX + brush.brushRange - 1 - l; x++) { if (HexGrid.instance.GetCell(new HexCoordinates(x, z)) != null) { cellList.Add(HexGrid.instance.GetCell(new HexCoordinates(x, z))); } } } List <UndoRedoOperation.UndoRedoInfo> undoRedoInfoList = new List <UndoRedoOperation.UndoRedoInfo>(); for (int i = 0; i < cellList.Count; i++) { UndoRedoOperation.UndoRedoInfo undoRedoInfo = new UndoRedoOperation.UndoRedoInfo(); undoRedoInfo.hexCell = cellList[i]; switch (brush.m_editorType) { case EditorType.HeightEditor: undoRedoInfo.parma = new object[] { cellList[i].Elevation }; break; case EditorType.WaterEditor: undoRedoInfo.parma = new object[] { cellList[i].WaterLevel }; break; case EditorType.EdgeEditor: undoRedoInfo.parma = new object[] { cellList[i].isStepDirection[0], cellList[i].isStepDirection[1], cellList[i].isStepDirection[2], cellList[i].isStepDirection[3], cellList[i].isStepDirection[4], cellList[i].isStepDirection[5] }; break; case EditorType.MaterialEditor: if (HexMetrics.instance.isEditorTexture) { undoRedoInfo.parma = new object[] { cellList[i].TerrainTypeIndex }; } else { undoRedoInfo.parma = new object[] { cellList[i].color }; } break; } undoRedoInfoList.Add(undoRedoInfo); } string name = ""; if (brush.m_editorType == EditorType.HeightEditor || brush.m_editorType == EditorType.WaterEditor || brush.m_editorType == EditorType.EdgeEditor) { MeshOperation.OperationType operationType = MeshOperation.OperationType.HeightEdit; switch (brush.m_editorType) { case EditorType.HeightEditor: name = "高度编辑"; operationType = MeshOperation.OperationType.HeightEdit; break; case EditorType.WaterEditor: name = "水平线编辑"; operationType = MeshOperation.OperationType.WaterLevelEdit; break; case EditorType.EdgeEditor: name = "边界编辑"; operationType = MeshOperation.OperationType.EdgeEdit; break; } MeshOperation meshOperation = new MeshOperation(operationType, name, undoRedoInfoList); undoStack.Push(meshOperation); } else if (brush.m_editorType == EditorType.MaterialEditor) { MaterialOperation.OperationType operationType = MaterialOperation.OperationType.WholeCellEdit; name = "材质编辑"; MaterialOperation materialOperation = new MaterialOperation(operationType, name, undoRedoInfoList); undoStack.Push(materialOperation); } LimitStackCount(); }