Beispiel #1
0
 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);
 }
Beispiel #2
0
        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);
        }