public bool addConn(KeyVector2 v) { if (v.x == v.y) { return(false); } foreach (KeyVector2 item in connList) { if (item.isEqual(v)) { return(false); } } connList.Add(v); return(true); }
protected override void drawSceneGUI() { int index = 0; Event e = Event.current; bool isMouseUp = false; if (e.type == EventType.MouseUp) { isMouseUp = true; } bool isShift = e.shift; Vector3 newPos; Handles.color = Color.white; Vector3 center = new Vector3(mTarget.center.x, 0, mTarget.center.y); float size = HandleUtility.GetHandleSize(center) * controlSize; int len = mTarget.list.Count; int[] pointerHosControl = new int[len]; for (int j = 0; j < len; j++) { Vector2 point = mTarget.list[j].getVector2(); Vector3 position = new Vector3(point.x, 0, point.y) + center; newPos = Handles.FreeMoveHandle(position, Quaternion.identity, size / 2, Vector3.zero, (int controlID, Vector3 pos, Quaternion rotation, float s, EventType eventType) => { pointerHosControl[j] = controlID; Handles.SphereHandleCap(controlID, pos, rotation, s, eventType); }); if (GUIUtility.hotControl == pointerHosControl[j] && isShift) { Vector2 v = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(v); Vector3 rayPoint = ray.origin; Handles.DrawLine(position, rayPoint); if (isMouseUp) { RefVector2 refVector2 = mTarget.getNearRefVector2(new Vector2(rayPoint.x, rayPoint.z)); if (refVector2 != null) { KeyVector2 intVector2 = new KeyVector2(); intVector2.x = mTarget.list[j].getGUID(); intVector2.y = refVector2.getGUID(); mTarget.addConn(intVector2); } isMouseUp = false; } } Handles.Label(position, j + "", headStyle.text); if (position != newPos && isShift == false) { Vector3 te = newPos - center; mTarget.list[j].reset(te.x, te.z); Undo.RecordObject(mTarget, "movePath"); //serializedObject.ApplyModifiedProperties(); } if (j == 0) { string name = mTarget.name; if (string.IsNullOrEmpty(name)) { name = ""; } Handles.Label(position, "path" + index + "#" + name, headStyle.box2); } } Handles.color = Color.green; List <KeyVector2> todoRemove = new List <KeyVector2>(); foreach (KeyVector2 item in mTarget.connList) { RefVector2 a = mTarget.getRefVector2ByGUID(item.x); RefVector2 b = mTarget.getRefVector2ByGUID(item.y); if (a == null || b == null) { todoRemove.Add(item); continue; } Handles.DrawLine(new Vector3(a.x, 0, a.y) + center, new Vector3(b.x, 0, b.y) + center); } if (todoRemove.Count > 0) { foreach (KeyVector2 item in todoRemove) { int tIndex = mTarget.connList.IndexOf(item); if (tIndex != -1) { mTarget.connList.RemoveAt(tIndex); } } serializedObject.ApplyModifiedProperties(); } index++; }
protected override void drawSceneGUI() { List <SpawersZoneVO> list = mTarget.list; if (list == null || list.Count <= 0) { return; } Event e = Event.current; bool isMouseUp = false; if (e.type == EventType.MouseUp) { isMouseUp = true; } bool isShift = e.shift; Vector3 position; int len = list.Count; bool isCurrentZoom = false; bool isCurrentWave = false; Color color = Color.red; float centerY = 0; int[] zoomHosControl = new int[len]; for (int i = 0; i < len; i++) { isCurrentZoom = zoomIndex == i; SpawersZoneVO spawersZoneVo = list[i]; Rect rect = spawersZoneVo.rect; position = new Vector3(rect.center.x, 0, rect.center.y); if (isCurrentZoom == false) { color.a = 0.3f; } else { color.a = 1.0f; } Handles.color = color; GUI.color = color; Vector3 rectCenter = new Vector3(rect.x, 0, rect.y); //Vector3 rectSize = new Vector3(rect.width, 0, rect.height); verts[0] = new Vector3(rect.x - rect.width / 2f, centerY, rect.y - rect.height / 2f); verts[1] = new Vector3(rect.x + rect.width / 2f, centerY, rect.y - rect.height / 2f); verts[2] = new Vector3(rect.x + rect.width / 2f, centerY, rect.y + rect.height / 2f); verts[3] = new Vector3(rect.x - rect.width / 2f, centerY, rect.y + rect.height / 2f); Handles.DrawSolidRectangleWithOutline(verts, rectSolideColor, Color.gray); float size = HandleUtility.GetHandleSize(rectCenter) * controlSize; Vector3 newPos; newPos = Handles.FreeMoveHandle(rectCenter, Quaternion.identity, size / 2, Vector3.zero, (controlID, p, rotation, s, evenType) => { zoomHosControl[i] = controlID; Handles.DotHandleCap(controlID, p, rotation, s, evenType); }); if (GUIUtility.hotControl == zoomHosControl[i]) { if (isShift) { Vector2 v = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(v); Vector3 rayPoint = ray.origin; Handles.DrawLine(rectCenter, rayPoint); if (isMouseUp) { SpawersZoneVO refVector2 = mTarget.getNearSpawersZoneCfg(new Vector2(rayPoint.x, rayPoint.z)); if (refVector2 != null) { KeyVector2 intVector2 = new KeyVector2(); intVector2.x = spawersZoneVo.getGUID(); intVector2.y = refVector2.getGUID(); mTarget.addConn(intVector2); } isMouseUp = false; } } else if (GUIUtility.hotControl != 0) { zoomIndex = i; Repaint(); } } if (rectCenter != newPos && isCurrentZoom && isShift == false) { Undo.RecordObject(mTarget, "ZoneMove"); rect.x = newPos.x; rect.y = newPos.z; spawersZoneVo.rect = rect; } int jLen = spawersZoneVo.list.Count; for (int j = 0; j < jLen; j++) { WaveCFG waveCfg = spawersZoneVo.list[j]; isCurrentWave = isCurrentZoom && (j == waveIndex); int kLen = waveCfg.list.Count; int[] monsterHosControl = new int[kLen]; for (int k = 0; k < kLen; k++) { MonsterCFG monsterCfg = waveCfg.list[k]; position = rectCenter + new Vector3(monsterCfg.position.x, 0, monsterCfg.position.y); if (isCurrentWave && isShift == false) { size = HandleUtility.GetHandleSize(position) * controlSize; newPos = Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero, (int controlID, Vector3 pos, Quaternion rotation, float s, EventType et) => { monsterHosControl[k] = controlID; if (k == monsterIndex) { Handles.color = Color.green; } Handles.SphereHandleCap(controlID, pos, rotation, s, et); Handles.color = color; }); if (GUIUtility.hotControl == monsterHosControl[k] && GUIUtility.hotControl != 0) { monsterIndex = k; Repaint(); } Quaternion q = Quaternion.Euler(0, monsterCfg.euler, 0); Handles.ArrowHandleCap(0, position, q, size, Event.current.type); if (position != newPos) { Undo.RecordObject(mTarget, "MonsterMove"); Vector3 p = newPos - rectCenter; monsterCfg.position = new Vector2(p.x, p.z); } } Color oldColor = GUI.color; GUI.color = Color.white; string monsterId = monsterCfg.id; if (string.IsNullOrEmpty(monsterId)) { monsterId = "#" + (j + 1) + "#"; } Handles.Label(position, monsterId); GUI.color = oldColor; } } GUI.color = Color.white; Handles.Label(rectCenter, "Zone" + (i + 1), headStyle.zoomText); } GUI.color = Color.white; Handles.color = Color.green; List <KeyVector2> todoRemove = new List <KeyVector2>(); foreach (KeyVector2 item in mTarget.connList) { SpawersZoneVO a = mTarget.getSpawersZoneCfgByGUID(item.x); SpawersZoneVO b = mTarget.getSpawersZoneCfgByGUID(item.y); if (a == null || b == null) { todoRemove.Add(item); continue; } Handles.DrawLine(new Vector3(a.rect.x, 0, a.rect.y), new Vector3(b.rect.x, 0, b.rect.y)); } if (todoRemove.Count > 0) { foreach (KeyVector2 item in todoRemove) { int tIndex = mTarget.connList.IndexOf(item); if (tIndex != -1) { mTarget.connList.RemoveAt(tIndex); } } serializedObject.ApplyModifiedProperties(); } }