void OnDestroy() { EditorApplication.update -= UpdateGraphEditorWindow; _graphObject = null; titleContent.text = "Graph Editor"; Repaint(); }
private void SetObject(IDirectedGraphObjectConfig graphObject) { Vector2 adjust; Rect rect = new Rect(0f, 0f, NODE_WIDTH, NODE_HEIGHT); _graphObject = graphObject; _scrollRect = new Rect(); _graphObject.GraphObject.Update(); _nodes = _graphObject.GraphProperty.FindPropertyRelative("Nodes"); _links = _graphObject.GraphProperty.FindPropertyRelative("Links"); _linkData = _graphObject.GraphProperty.FindPropertyRelative("LinkData"); _positions = _graphObject.GraphProperty.FindPropertyRelative("Positions"); if (_nodes.arraySize == 0) { CreateNewNode(Vector2.zero); } _positions.arraySize = _nodes.arraySize; adjust = _positions.GetArrayElementAtIndex(0).vector2Value; for (int i = _positions.arraySize - 1; i >= 0; i--) { rect.center = _positions.GetArrayElementAtIndex(i).vector2Value -= adjust; AdjustScrollRect(rect, SCROLL_PADDING); } _graphObject.GraphObject.ApplyModifiedProperties(); _isNode = true; _selection = -1; _scroll = new Vector2((position.width - _scrollRect.xMin) * .5f, -position.height - _scrollRect.yMin * .5f); Repaint(); }
public static GraphEditorWindow Show(IDirectedGraphObjectConfig graphObject) { if (graphObject is ScriptableObject) { string str = (graphObject as ScriptableObject).name; GraphEditorWindow window = GetWindow <GraphEditorWindow>(str + " | Graph Editor"); window.SetObject(graphObject); EditorApplication.update -= window.UpdateGraphEditorWindow; EditorApplication.update += window.UpdateGraphEditorWindow; return(window); } return(null); }
public static bool DeleteSelected(IDirectedGraphObjectConfig graphObject, int index, bool isNode) { if (index < 0 || graphObject == null || graphObject.GraphProperty == null) { return(false); } SerializedProperty links = graphObject.GraphProperty.FindPropertyRelative("Links"); SerializedProperty graphProperty = graphObject.GraphProperty; if (isNode) { SerializedProperty nodes = graphProperty.FindPropertyRelative("Nodes"); if (nodes == null || nodes.arraySize <= 1) { return(false); } DeleteIndex(graphProperty, "Positions", index); if (!DeleteIndex(graphProperty, "Nodes", index)) { return(false); } Vector2Int ln; for (int i = links.arraySize - 1; i >= 0; i--) { ln = links.GetArrayElementAtIndex(i).vector2IntValue; if (ln.x == index || ln.y == index) { DeleteIndex(graphProperty, "Links", i); DeleteIndex(graphProperty, "LinkData", i); } else { if (ln.x > index) { ln.x--; } if (ln.y > index) { ln.y--; } links.GetArrayElementAtIndex(i).vector2IntValue = ln; } } } else { DeleteIndex(graphProperty, "LinkData", index); if (!DeleteIndex(graphProperty, "Links", index)) { return(false); } } graphObject.Select(-1, false); GraphEditorWindow window = GetWindow <GraphEditorWindow>(((ScriptableObject)graphObject).name + " | Graph Editor", false); window._isNode = false; window._selection = -1; graphObject.GraphObject.ApplyModifiedProperties(); return(true); }