123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- public class MyGridMapEditor : EditorWindow
- {
- static GameObject selectObj;
- static MyGridMap gridMap;
- int row = 10;
- int col = 10;
- int w = 20;
- int h = 20;
- bool isShow = false;
- static int uiState = 0;
- // Start is called before the first frame update
- void Start()
- {
- }
- void OnGUI()
- {
- GUILayout.Label("目标地形预制体");
- gridMap = EditorGUILayout.ObjectField(gridMap, typeof(MyGridMap), true) as MyGridMap;
- switch(uiState)
- {
- case 1:
- GUILayout.Label("碰撞盒参数");
- row = EditorGUILayout.IntField(row);
- col = EditorGUILayout.IntField(col);
- w = EditorGUILayout.IntField(w);
- h = EditorGUILayout.IntField(h);
- MyGridMap.Row = row;
- MyGridMap.Col = col;
- MyGridMap.W = w;
- MyGridMap.H = h;
- if (GUILayout.Button("生成"))
- {
- selectObj = Selection.activeGameObject;
- gridMap = selectObj.GetOrAddComponent<MyGridMap>();
- for (int i = 0; i < row; ++i)
- {
- for (int j = 0; j < col; ++j)
- {
- gridMap.AddMyGrid(i, j, w, h);
- }
- }
- }
- break;
- case 2:
- if (GUILayout.Button("第一次匹配到网格"))
- {
- selectObj = Selection.activeGameObject;
- gridMap.MateObjToGrid(selectObj);
- }
- break;
- case 3:
- if (GUILayout.Button("添加到网格"))
- {
- selectObj = Selection.activeGameObject;
- gridMap.AddSubObjToGrid(selectObj);
- }
- break;
- case 4:
- if (GUILayout.Button("优化地形"))
- {
- selectObj = Selection.activeGameObject;
- gridMap.OptimizeTerrain(selectObj);
- }
- break;
- case 5:
- if (GUILayout.Button("去除碰撞"))
- {
- selectObj = Selection.activeGameObject;
- OnRmoveCollider(selectObj);
- }
- break;
- case 6:
- if (GUILayout.Button("显示/隐藏"))
- {
- selectObj = Selection.activeGameObject;
- OnShowOrHide(selectObj);
- }
- break;
- }
- }
- [MenuItem("地图/---网格创建---")]
- public static void CreateGridCollider()
- {
- uiState = 1;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- [MenuItem("地图/---第一次网格匹配---")]
- public static void MateGrid()
- {
- uiState = 2;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- [MenuItem("地图/---添加匹配---")]
- public static void AddGrid()
- {
- uiState = 3;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- [MenuItem("地图/---优化地形---")]
- public static void OptimizeTerrain()
- {
- uiState = 4;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- [MenuItem("地图/---去除碰撞---")]
- public static void RemoveCollider()
- {
- uiState = 5;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- [MenuItem("地图/---显隐场景---")]
- public static void ShowOrHide()
- {
- uiState = 6;
- EditorWindow.GetWindow(typeof(MyGridMapEditor));
- }
- public void OnRmoveCollider(GameObject obj)
- {
- Collider[] cs = obj.GetComponentsInChildren<Collider>(true);
- for (int i = 0; i < cs.Length; ++i)
- {
- DestroyImmediate(cs[i]);
- }
- }
- public void OnShowOrHide(GameObject obj)
- {
- isShow = !isShow;
- MySplitTerrainTile[] cs = obj.GetComponentsInChildren<MySplitTerrainTile>(true);
- for (int i = 0; i < cs.Length; ++i)
- {
- cs[i].ShowOrHide(isShow);
- }
- }
- }
|