public override void SetComponent(Component comp) { if (comp.ClassId == block.ClassId) { block = (EnemyBlock)comp; } else { throw new Exception("You passed a wrong component to the " + GetType().Name + " class"); } }
public override void SetUp() { block = new EnemyBlock(0, 0, 0, 0); }
public override void DisposeNode() { block = null; }
public override void OnInspectorGUI() { //不需要base.OnInspectorGUI (); EditorGUILayout.BeginVertical(); bool oldUpperLayer = voxelMap.isUpperLayer; voxelMap.isUpperLayer = EditorGUILayout.Toggle("is up layer:", voxelMap.isUpperLayer); if (oldUpperLayer != voxelMap.isUpperLayer) { //ChangeActiveLayer (); } EditorGUILayout.BeginHorizontal(); bool oldDispUpeerLayerGizmo = voxelMap.displayUpperGizmo; voxelMap.displayUpperGizmo = EditorGUILayout.Toggle("Switch Gizmo Upper / Lower :", voxelMap.displayUpperGizmo); if (oldDispUpeerLayerGizmo != voxelMap.displayUpperGizmo) { //ChangeActiveLayer (); } EditorGUILayout.EndHorizontal(); //如果旧的地图尺寸和新的不同,则进行 Vector2 oldSize = voxelMap.mapSize; voxelMap.mapSize = EditorGUILayout.Vector2Field("Voxel Map Size", voxelMap.mapSize); if (oldSize != voxelMap.mapSize) { UpdateCalculations(); } //如果基准方块被改变则重新建立笔刷 GameObject oldBasicBlock = voxelMap.basicBlock; voxelMap.basicBlock = (GameObject)EditorGUILayout.ObjectField("Basic Object:", voxelMap.basicBlock, typeof(GameObject), false); if (oldBasicBlock != voxelMap.basicBlock) { UpdateCalculations(); voxelMap.blockID = 0; CreateBrush(); } //选择需要加入保存的方块类型 blockType = (BlockType)EditorGUILayout.EnumPopup("Block Type", blockType); //输入对于方块合适的名字 blockName = (string)EditorGUILayout.TextField("New Blcok Name", blockName); if (GUILayout.Button("Add New Blcoksd")) { //必须命名 if (blockName != "") { if (blockType != BlockType.None) { switch (blockType) { case BlockType.Floor: FloorBlock floorBlock = new FloorBlock(blockName); //为了防止反序列化时没有数据恢复,需要手动赋值一次 floorBlock.BlockType = BlockType.Floor; voxelMap.allBlocks.Add(floorBlock); break; case BlockType.Wall: WallBlock wallBlock = new WallBlock(blockName); wallBlock.BlockType = BlockType.Wall; voxelMap.allBlocks.Add(wallBlock); break; case BlockType.Player: PlayerBlock playerBlock = new PlayerBlock(blockName); playerBlock.BlockType = BlockType.Player; voxelMap.allBlocks.Add(playerBlock); break; case BlockType.Enemy: EnemyBlock enemyBlock = new EnemyBlock(blockName); enemyBlock.BlockType = BlockType.Enemy; voxelMap.allBlocks.Add(enemyBlock); break; case BlockType.Door: DoorBlock doorBlock = new DoorBlock(blockName); doorBlock.BlockType = BlockType.Door; voxelMap.allBlocks.Add(doorBlock); break; } blockType = BlockType.None; } } } //保存所有的类型进入对应的数组 //QuickSort (voxelMap.allBlocks, 0, voxelMap.allBlocks.Count); //List<BasicBlock> tmp = new List<BasicBlock> (); //tmp [1] = new FloorBlock ("hy"); //tmp [0] = new //QuickSorting.QuickSort (); //显示现在保存的方块类型 for (int i = 0; i < voxelMap.allBlocks.Count; i++) { EditorGUILayout.BeginHorizontal(); voxelMap.allBlocks [i].m_gameobject = (GameObject)EditorGUILayout.ObjectField(voxelMap.allBlocks [i].m_name + " " + voxelMap.allBlocks [i].GetType(), voxelMap.allBlocks [i].m_gameobject, typeof(GameObject), false); //删除预设方块 if (GUILayout.Button("Delete")) { Debug.Log("Delete" + i + voxelMap.allBlocks [i].m_name); voxelMap.allBlocks.Remove(voxelMap.allBlocks [i]); } EditorGUILayout.EndHorizontal(); } //refresh brush mesh to new brush, UpdateBrush(voxelMap.GetBlockBrush.m_gameobject.GetComponentInChildren <MeshFilter> (), voxelMap.GetBlockBrush.m_gameobject.GetComponentInChildren <MeshRenderer> ()); if (GUILayout.Button("Clear Blocks")) { if (EditorUtility.DisplayDialog("Clear map's blocks?", "Are you sure?", "Clear", "Do not clear")) { ClearMap(); } } EditorGUILayout.EndVertical(); }