bool DrawRiverNodes(int i, int max) { bool bDirty = false; EditorGUILayout.BeginHorizontal(); if (i < max) { RiverNodeObject curNode = riverScript.nodeObjects[i]; Vector4 posw = new Vector4(curNode.position.x, curNode.position.y, curNode.position.z, curNode.width); posw = EditorGUILayout.Vector4Field("" + i + ":", posw); curNode.position = new Vector3(posw.x, posw.y, posw.z); curNode.width = posw.w; if (GUILayout.Button("-")) { riverScript.nodeObjects.Remove(curNode); bDirty = true; } } if (GUILayout.Button("+")) { RiverNodeObject newNode = new RiverNodeObject(); if (riverScript.nodeObjects == null) { riverScript.nodeObjects = new List <RiverNodeObject>(); riverScript.curRiverNodeToPosite = 0; } else if (i >= max) { newNode.position = riverScript.nodeObjects[max - 1].position; newNode.width = riverScript.nodeObjects[max - 1].width; } else { newNode.position = riverScript.nodeObjects[i].position; newNode.width = riverScript.nodeObjects[i].width; } riverScript.nodeObjects.Insert(i, newNode); riverScript.curRiverNodeToPosite = i; bDirty = true; } EditorGUILayout.EndHorizontal(); return(bDirty); }
void OnSceneGUI() { Event currentEvent = Event.current; if (riverScript.nodeObjects != null && riverScript.nodeObjects.Length != 0 && !riverScript.finalized) { int n = riverScript.nodeObjects.Length; for (int i = 0; i < n; i++) { RiverNodeObject node = riverScript.nodeObjects[i]; node.position = Handles.PositionHandle(node.position, Quaternion.identity); } } if (riverScript.riverNodeMode == true) { if (currentEvent.isKey && currentEvent.character == 'r') { Vector3 riverNode = GetTerrainCollisionInEditor(currentEvent, KeyCode.R); TerrainCell riverNodeCell = new TerrainCell(); riverNodeCell.position.x = riverNode.x; riverNodeCell.position.y = riverNode.z; riverNodeCell.heightAtCell = riverNode.y; riverScript.CreateRiverNode(riverNodeCell); riverScript.riverNodeMode = false; } } if (GUI.changed) { if (!riverScript.finalized) { EditorUtility.SetDirty(riverScript); riverScript.CreateMesh(riverScript.riverSmooth, false); } } }
void OnSceneGUI() { Event currentEvent = Event.current; if (riverScript.nodeObjects != null && riverScript.nodeObjects.Count != 0 && !riverScript.finalized) { int n = riverScript.nodeObjects.Count; for (int i = 0; i < n; i++) { RiverNodeObject node = riverScript.nodeObjects[i]; node.position = Handles.PositionHandle(node.position, Quaternion.identity); Handles.Label(node.position + Vector3.up, "[" + i + "]"); } } if (riverScript.curRiverNodeToPosite >= 0) { if (currentEvent.isKey && currentEvent.character == 'r') { /* * if(riverScript.nodeObjects.Count > riverScript.curRiverNodeToPosite) * { * RiverNodeObject curRiverNode = riverScript.nodeObjects[riverScript.curRiverNodeToPosite]; * curRiverNode.position = GetTerrainCollisionInEditor(currentEvent, true); * curRiverNode.position.y += riverScript.defRiverDepth; * curRiverNode.width = riverScript.defRiverWidth; * } */ riverScript.curRiverNodeToPosite = -1; EditorUtility.SetDirty(riverScript); riverScript.CreateMesh(riverScript.riverSmooth); } } else if (GUI.changed) { EditorUtility.SetDirty(riverScript); riverScript.CreateMesh(riverScript.riverSmooth); } }
public void AddNode(Vector3 position, float width) { RiverNodeObject newRiverNodeObject = new RiverNodeObject(); int nNodes; if (nodeObjects == null) { nodeObjects = new RiverNodeObject[0]; nNodes = 1; newRiverNodeObject.position = position; } else { nNodes = nodeObjects.Length + 1; newRiverNodeObject.position = position; } RiverNodeObject[] newNodeObjects = new RiverNodeObject[nNodes]; newRiverNodeObject.width = width; int n = newNodeObjects.Length; for (int i = 0; i < n; i++) { if (i != n - 1) { newNodeObjects[i] = nodeObjects[i]; } else { newNodeObjects[i] = newRiverNodeObject; } } nodeObjects = newNodeObjects; }
public void AddNode(Vector3 position, float width) { RiverNodeObject newRiverNodeObject = new RiverNodeObject(); int nNodes; if(nodeObjects == null) { nodeObjects = new RiverNodeObject[0]; nNodes = 1; newRiverNodeObject.position = position; } else { nNodes = nodeObjects.Length + 1; newRiverNodeObject.position = position; } RiverNodeObject[] newNodeObjects = new RiverNodeObject[nNodes]; newRiverNodeObject.width = width; int n = newNodeObjects.Length; for (int i = 0; i < n; i++) { if (i != n - 1) { newNodeObjects[i] = nodeObjects[i]; } else { newNodeObjects[i] = newRiverNodeObject; } } nodeObjects = newNodeObjects; }