/// <summary> /// Draws the node editor and all of its components /// </summary> /// <param name="nodeEditorArea">The rectangle that defines the editor area</param> protected virtual void Draw(Rect nodeEditorArea) { NodeEditorRect = zoomArea.BeginZoomArea(nodeEditorArea); if (OnDrawBackground != null && Event.current.type == EventType.Repaint) { OnDrawBackground(NodeEditorRect.AddPosition(zoomArea.CurrentPanOffset)); } ProcessInputRenders(true); foreach (Connector connector in Connectors) { connector.Draw(zoomArea.CurrentPanOffset); } foreach (Node node in Nodes) { node.Draw(zoomArea.CurrentPanOffset); } ProcessInputRenders(false); zoomArea.EndZoomArea(); }
public void DoLayout(GUIStyle style, bool isEnabled = true) { canExpand = isEnabled; Button.DoLayout(style, null, selectedItemName); if (Event.current.type == EventType.Repaint) { drawRect.position = GUILayoutUtility.GetLastRect().position; drawRect = drawRect.AddPosition(buttonOffset); } }
/// <summary> /// Gets the rectangle that defines the nodes area at the /// provided pan offset /// </summary> /// <param name="offset">Node editors' pan offset</param> /// <returns>The rectangle of the node at the provided offset</returns> public virtual Rect GetNodeRect(Vector2 offset) { return(NodeRect.AddPosition(offset)); }
ReorderableList CreateList(SerializedObject obj, SerializedProperty prop) { ReorderableList list = new ReorderableList(obj, prop, true, true, true, true); list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Pools"); }; list.drawElementCallback = (rect, index, active, focused) => { Rect standardRect = new Rect(rect.position, new Vector2(rect.width, LineHeight)).AddPosition(new Vector2(5, 2.5f)); EditorGUI.indentLevel++; SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index); poolsList[index].name = poolsList[index].poolObjectType.ToString(); poolFoldouts.AddUntil(index); poolFoldouts[index] = EditorGUI.Foldout(standardRect, poolFoldouts[index], poolsList[index].name, true); if (poolFoldouts[index]) { EditorGUI.indentLevel++; SerializedProperty prefabsProp = element.FindPropertyRelative("prefabs"); poolsList[index].poolObjectType = (PoolObjectType)EditorGUI.EnumPopup(standardRect.AddPosition(Vector2.up * LineHeight * 1), "Pool Object Type", poolsList[index].poolObjectType); poolsList[index].size = EditorGUI.IntField(standardRect.AddPosition(Vector2.up * LineHeight * 2), "Pool Size", poolsList[index].size); prefabsFoldouts.AddUntil(index); prefabsFoldouts[index] = EditorGUI.PropertyField(standardRect.AddPosition(Vector2.up * LineHeight * 3), prefabsProp, new GUIContent("Prefabs"), false); if (prefabsFoldouts[index]) { EditorGUI.indentLevel++; prefabsProp.arraySize = EditorGUI.IntField(standardRect.AddPosition(Vector2.up * LineHeight * 4), "Size", prefabsProp.arraySize); for (int i = 0; i < prefabsProp.arraySize; i++) { EditorGUI.PropertyField(standardRect.AddPosition(Vector2.up * LineHeight * (5 + i)), prefabsProp.GetArrayElementAtIndex(i)); } EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } EditorGUI.indentLevel--; }; list.elementHeightCallback = (index) => { Repaint(); float height = LineHeight + 5; poolFoldouts.AddUntil(index); prefabsFoldouts.AddUntil(index); if (poolFoldouts[index]) { int lineCount = 3; height += lineCount * LineHeight; if (prefabsFoldouts[index]) { int prefabCount = poolsList[index].prefabs.Count; height += (prefabCount + 1) * LineHeight; } } return(height); }; list.onAddDropdownCallback = (rect, li) => { serializedObject.Update(); li.serializedProperty.arraySize++; prefabsFoldouts.AddUntil(li.serializedProperty.arraySize); serializedObject.ApplyModifiedProperties(); }; list.onRemoveCallback = (li) => { serializedObject.Update(); li.serializedProperty.DeleteArrayElementAtIndex(list.index); serializedObject.ApplyModifiedProperties(); }; return(list); }