public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(zoneId, new GUIContent("区域ID")); EditorGUILayout.PropertyField(propType, new GUIContent("区域类型")); EditorGUILayout.PropertyField(propCountryflag, new GUIContent("阵营标识")); int origWidth = propWidth.intValue; int origHeight = propHeight.intValue; EditorGUILayout.PropertyField(propWidth, new GUIContent("宽")); EditorGUILayout.PropertyField(propHeight, new GUIContent("高")); if (origHeight != propHeight.intValue || origWidth != propWidth.intValue) { //Debug.Log("width or height changed:" + propWidth.intValue + ",height:" + propHeight.intValue); updateMesh(propWidth.intValue, propHeight.intValue); } MapZoneView view = (MapZoneView)target; Quaternion rotat = view.gameObject.transform.localRotation; if (view.gameObject.transform.hasChanged) { Vector3 pos = view.gameObject.transform.localPosition; IntPoint logic = PathUtilEdit.Real2Logic(pos); if (logic.x != propX.intValue || logic.y != propY.intValue) { //pos = PathUtilEdit.LogicCenter2Real(logic); //Debug.Log("npc pos changed:" + logic.x + " != " + propX.intValue + "," + logic.y+" != "+propY.intValue); if (EditorData.terrainMan != null) { pos.y = EditorData.terrainMan.GetHeight(pos.x, pos.z); view.gameObject.transform.localPosition = pos; } } propX.intValue = logic.x; propY.intValue = logic.y; propEulerangles.stringValue = rotat.eulerAngles.x.ToString() + "," + rotat.eulerAngles.y.ToString() + "," + rotat.eulerAngles.z.ToString(); } EditorGUILayout.LabelField("X:\t" + propX.intValue); EditorGUILayout.LabelField("Y:\t" + propY.intValue); if (propType.intValue == 32) { EditorGUILayout.PropertyField(propZoneIndex, new GUIContent("区域刷怪次序")); } serializedObject.ApplyModifiedProperties(); }
void updateMesh(int width, int height) { MapZoneView view = (MapZoneView)target; MeshFilter mf = view.gameObject.GetComponent <MeshFilter>(); Mesh mesh = mf.sharedMesh; float x = PathUtilEdit.Logic2RealLen(width / 2f); float z = PathUtilEdit.Logic2RealLen(height / 2f); List <Vector3> verts = new List <Vector3>(); //verts.Add(new Vector3(-x, 0, z)); //verts.Add(new Vector3(x, 0, z)); //verts.Add(new Vector3(x, 0, -z)); //verts.Add(new Vector3(-x, 0, -z)); verts.Add(new Vector3(0, 0, 0)); verts.Add(new Vector3(2f * x, 0, 0)); verts.Add(new Vector3(2f * x, 0, -2f * z)); verts.Add(new Vector3(0, 0, -2f * z)); mesh.vertices = verts.ToArray(); }
public GameObject AddMapZone(MapZone zone, Vector3 pos) { GameObject go = new GameObject("mapzone_" + zone.id); MeshFilter mf = go.AddComponent <MeshFilter>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); Mesh mesh = new Mesh(); List <Vector3> verts = new List <Vector3>(); if (zone.regiontype == 0) { float x = PathUtilEdit.Logic2RealLen(zone.width / 2f); float z = PathUtilEdit.Logic2RealLen(zone.height / 2f); //verts.Add(new Vector3(0, 0, 2f*z)); //verts.Add(new Vector3(2f*x, 0, 2f*z)); //verts.Add(new Vector3(2f*x, 0, 0)); //verts.Add(new Vector3(0, 0, 0)); verts.Add(new Vector3(0, 0, 0)); verts.Add(new Vector3(2f * x, 0, 0)); verts.Add(new Vector3(2f * x, 0, -2f * z)); verts.Add(new Vector3(0, 0, -2f * z)); mesh.vertices = verts.ToArray(); mesh.SetTriangles(new int[] { 0, 1, 2, 0, 2, 3 }, 0); Color cl = new Color(0, 0, 1); mesh.colors = new Color[] { cl, cl, cl, cl }; } else { Debug.LogError("暂不支持点列类型的区域"); return(null); } mr.material = Resources.Load("Materials/Ground_tile_material") as Material; mf.mesh = mesh; string subpath = "zone"; Transform parentTrans = getRoot().FindChild(subpath); if (parentTrans == null) { GameObject subroot = new GameObject(subpath); subroot.transform.SetParent(getRoot()); parentTrans = subroot.transform; } go.transform.SetParent(parentTrans); go.transform.localPosition = pos; if (zone.eulerangles != null) { string[] arr = zone.eulerangles.Split(','); if (arr.Length == 3) { //npcObj.transform.Rotate(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2])); go.transform.localRotation = Quaternion.Euler(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2])); } } MapZoneView view = go.AddComponent <MapZoneView>(); view.data = zone; zone.target = go; return(go); }