示例#1
0
        /// <summary>
        /// Loads the editorStates found in the nodeCanvas asset file at path
        /// </summary>
        public static List <NodeEditorState> LoadEditorStates(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(null);
            }
        #if UNITY_EDITOR
            Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(path);
        #else
            Object[] objects = Resources.LoadAll(path);
        #endif
            if (objects.Length == 0)
            {
                return(null);
            }

            // Obtain the editorStates in that asset file
            List <NodeEditorState> editorStates = new List <NodeEditorState> ();
            for (int cnt = 0; cnt < objects.Length; cnt++)
            {
                if (objects [cnt].GetType() == typeof(NodeEditorState))
                {
                    editorStates.Add(objects [cnt] as NodeEditorState);
                    NodeEditorCallbacks.IssueOnLoadEditorState(editorStates[editorStates.Count - 1]);
                }
            }

        #if UNITY_EDITOR
            UnityEditor.AssetDatabase.Refresh();
        #endif

            return(editorStates);
        }
示例#2
0
        /// <summary>
        /// Loads the editorStates found in the nodeCanvas asset file at path
        /// </summary>
        public static List <NodeEditorState> LoadEditorStates(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(new List <NodeEditorState> ());
            }
                        #if UNITY_EDITOR
            Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(path);
                        #else
            Object[] objects = Resources.LoadAll(path);
                        #endif
            if (objects.Length == 0)
            {
                return(new List <NodeEditorState> ());
            }

            // Obtain the editorStates in that asset file
            List <NodeEditorState> editorStates = new List <NodeEditorState> ();
            NodeCanvas             nodeCanvas   = null;
            for (int cnt = 0; cnt < objects.Length; cnt++)
            {
                Object obj = objects [cnt];
                if (obj.GetType() == typeof(NodeEditorState))
                {
                    NodeEditorState editorState = obj as NodeEditorState;
                    editorStates.Add(editorState);
                    NodeEditorCallbacks.IssueOnLoadEditorState(editorState);
                }
                else if (obj.GetType() == typeof(NodeCanvas))
                {
                    nodeCanvas = obj as NodeCanvas;
                }
            }

            if (nodeCanvas == null)
            {
                return(new List <NodeEditorState> ());
            }

            for (int stateCnt = 0; stateCnt < editorStates.Count; stateCnt++)
            {
                editorStates[stateCnt] = GetWorkingCopy(editorStates[stateCnt], nodeCanvas);
            }

                        #if UNITY_EDITOR
            UnityEditor.AssetDatabase.Refresh();
                        #endif

            return(editorStates);
        }
示例#3
0
        /// <summary>
        /// Loads the editorStates found in the nodeCanvas asset file at path and optionally creates a working copy of it before returning
        /// </summary>
        public static List <NodeEditorState> LoadEditorStates(string path, bool createWorkingCopy)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new UnityException("Cannot load NodeEditorStates: No path specified to load the EditorStates from!");
            }

            // Fetch all objects in the save file
            ScriptableObject[] objects = ResourceManager.LoadResources <ScriptableObject> (path);
            if (objects == null || objects.Length == 0)
            {
                throw new UnityException("Cannot load NodeEditorStates: The specified path '" + path + "' does not point to a save file!");
            }

            // Obtain the editorStates in that asset file and create a working copy of them
            List <NodeEditorState> editorStates = objects.OfType <NodeEditorState> ().ToList();

        #if UNITY_EDITOR
            if (createWorkingCopy)
            {
                for (int cnt = 0; cnt < editorStates.Count; cnt++)
                {
                    NodeEditorState state = editorStates[cnt];
                    CreateWorkingCopy(ref state);
                    editorStates[cnt] = state;
                    if (state == null)
                    {
                        throw new UnityException("Failed to create a working copy for an NodeEditorState at path '" + path + "' during the loading process!");
                    }
                }
            }
        #endif

            // Perform Event and Database refresh
            for (int cnt = 0; cnt < editorStates.Count; cnt++)
            {
                NodeEditorCallbacks.IssueOnLoadEditorState(editorStates[cnt]);
            }
        #if UNITY_EDITOR
            UnityEditor.AssetDatabase.Refresh();
        #endif
            return(editorStates);
        }