Esempio n. 1
0
        private void MarkAndTraverseParent(Model.ConfigGraph saveData, Model.NodeData current, List <Model.ConnectionData> visitedConnections, List <Model.NodeData> visitedNode)
        {
//			Assert.IsNotNull(current);
            if (current == null)
            {
                return;
            }

            // if node is visited from other route, just quit
            if (visitedNode.Contains(current))
            {
                return;
            }

            var connectionsToParents = saveData.Connections.FindAll(con => con.ToNodeId == current.Id);

            foreach (var c in connectionsToParents)
            {
                if (visitedConnections.Contains(c))
                {
                    throw new NodeException("Looped connection detected. Please fix connections to avoid loop.", current.Id);
                }

                visitedConnections.Add(c);

                var parentNode = saveData.Nodes.Find(node => node.Id == c.FromNodeId);
                if (parentNode != null)
                {
                    // parentNode may be null while deleting node
                    MarkAndTraverseParent(saveData, parentNode, visitedConnections, visitedNode);
                }
            }

            visitedNode.Add(current);
        }
Esempio n. 2
0
        public static Model.ConfigGraph ImportJSONToGraphFromDialog(Model.ConfigGraph graph)
        {
            string fileSelected = EditorUtility.OpenFilePanelWithFilters("Select JSON files to import", Application.dataPath, new string[] { "JSON files", "json", "All files", "*" });

            if (string.IsNullOrEmpty(fileSelected))
            {
                return(null);
            }

            string name = Path.GetFileNameWithoutExtension(fileSelected);

            var jsonContent = File.ReadAllText(fileSelected, System.Text.Encoding.UTF8);

            if (graph != null)
            {
                Undo.RecordObject(graph, "Import");
                EditorJsonUtility.FromJsonOverwrite(jsonContent, graph);
            }
            else
            {
                graph = ScriptableObject.CreateInstance <Model.ConfigGraph>();
                EditorJsonUtility.FromJsonOverwrite(jsonContent, graph);
                var newAssetFolder = CreateFolderForImportedAssets();
                var graphPath      = FileUtility.PathCombine(newAssetFolder, string.Format("{0}.asset", name));
                AssetDatabase.CreateAsset(graph, graphPath);
            }
            return(graph);
        }
Esempio n. 3
0
        public void BuildGraphFromSaveData(Model.ConfigGraph graph, BuildTarget target, PerformGraph old)
        {
            m_target = target;

            ValidateLoopConnection(graph);

            m_nodes.Clear();
            m_streams.Clear();

            foreach (var n in graph.Nodes)
            {
                SetupNode(n);
            }

            foreach (var c in graph.Connections)
            {
                SetupStream(c);
            }

            /*
             * All nodes needs revisit when target has changed.
             * Do modification check only when targeting the same build target
             * from last one.
             */
            if (m_target == old.m_target)
            {
                CompareAndMarkModified(old);
            }
        }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            Model.ConfigGraph graph = target as Model.ConfigGraph;

            using (new EditorGUILayout.HorizontalScope()) {
                GUILayout.Label(graph.name, "BoldLabel");
                if (GUILayout.Button(Styles.kEDITBUTTON, GUILayout.Width(150f), GUILayout.ExpandWidth(false)))
                {
                    // Get the target we are inspecting and open the graph
                    var window = EditorWindow.GetWindow <AssetBundleGraphEditorWindow>();
                    window.OpenGraph(graph);
                }
            }

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                EditorGUILayout.LabelField("Version", graph.Version.ToString());
                EditorGUILayout.LabelField("Last Modified", graph.LastModified.ToString());
                using (new EditorGUILayout.HorizontalScope()) {
                    GUILayout.Label("Description", GUILayout.Width(100f));
                    string newdesc = EditorGUILayout.TextArea(graph.Descrption, GUILayout.MaxHeight(100f));
                    if (newdesc != graph.Descrption)
                    {
                        graph.Descrption = newdesc;
                    }
                }
                GUILayout.Space(2f);
            }
        }
Esempio n. 5
0
        /*
         * Verify nodes does not create cycle
         */
        private void ValidateLoopConnection(Model.ConfigGraph saveData)
        {
            var leaf = saveData.CollectAllLeafNodes();

            foreach (var leafNode in leaf)
            {
                MarkAndTraverseParent(saveData, leafNode, new List <Model.ConnectionData>(), new List <Model.NodeData>());
            }
        }
 public AssetBundleGraphController(Model.ConfigGraph graph)
 {
     m_targetGraph    = graph;
     m_nodeExceptions = new List <NodeException>();
     m_streamManager  = new AssetReferenceStreamManager(m_targetGraph);
     m_performGraph   = new PerformGraph[] {
         new PerformGraph(m_streamManager),
         new PerformGraph(m_streamManager)
     };
     gIndex = 0;
 }
Esempio n. 7
0
        public NodeGUI(AssetBundleGraphController controller, Model.NodeData data)
        {
            m_nodeWindowId = 0;
            m_graph        = controller.TargetGraph;
            m_data         = data;

            m_baseRect = new Rect(m_data.X, m_data.Y, Model.Settings.GUI.NODE_BASE_WIDTH, Model.Settings.GUI.NODE_BASE_HEIGHT);

            m_nodeSyle           = data.Operation.Object.InactiveStyle;
            Inspector.controller = controller;
        }
Esempio n. 8
0
        public static ConfigGraph CreateNewGraphFromImport(string pathToSave)
        {
            // try load from v1.
            try {
                V1.SaveData v1       = V1.SaveData.Data;
                ConfigGraph newGraph = CreateNewGraph(pathToSave);
                newGraph.Import(v1);

                return(newGraph);
            } catch (Exception e) {
                LogUtility.Logger.LogError(LogUtility.kTag, "Failed to import graph from previous version." + e);
            }

            return(null);
        }
Esempio n. 9
0
        public static void ExportGraphToJSONFromDialog(Model.ConfigGraph graph)
        {
            string path =
                EditorUtility.SaveFilePanelInProject(
                    string.Format("Export {0} to JSON file", graph.name),
                    graph.name, "json",
                    "Export to:");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            string jsonString = EditorJsonUtility.ToJson(graph, true);

            File.WriteAllText(path, jsonString, System.Text.Encoding.UTF8);
        }
Esempio n. 10
0
        /// <summary>
        /// Executes the graph.
        /// </summary>
        /// <returns>The graph.</returns>
        /// <param name="target">Target.</param>
        /// <param name="graph">Graph.</param>
        public static ExecuteGraphResult ExecuteGraph(BuildTarget target, Model.ConfigGraph graph)
        {
            string assetPath = AssetDatabase.GetAssetPath(graph);

            LogUtility.Logger.LogFormat(LogType.Log, "Executing graph:{0}", assetPath);

            AssetBundleGraphController c = new AssetBundleGraphController(graph);

            // perform setup. Fails if any exception raises.
            c.Perform(target, false, true, null);

            // if there is error reported, then run
            if(c.IsAnyIssueFound) {
                return new ExecuteGraphResult(graph, c.Issues);
            }

            Model.NodeData lastNodeData = null;
            float lastProgress = 0.0f;

            Action<Model.NodeData, string, float> updateHandler = (Model.NodeData node, string message, float progress) => {
                if(node != null && lastNodeData != node) {
                    lastNodeData = node;
                    lastProgress = progress;

                    LogUtility.Logger.LogFormat(LogType.Log, "Processing {0}", node.Name);
                }
                if(progress > lastProgress) {
                    if(progress <= 1.0f) {
                        LogUtility.Logger.LogFormat(LogType.Log, "{0} Complete.", node.Name);
                    } else if( (progress - lastProgress) > 0.2f ) {
                        LogUtility.Logger.LogFormat(LogType.Log, "{0}: {1} % : {2}", node.Name, (int)progress*100f, message);
                    }
                    lastProgress = progress;
                }
            };

            // run datas.
            c.Perform(target, true, true, updateHandler);

            AssetDatabase.Refresh();

            return new ExecuteGraphResult(graph, c.Issues);
        }
Esempio n. 11
0
        /**
         * Build from commandline - entrypoint.
         */
        public static void BuildFromCommandline()
        {
            try {
                var arguments = new List <string>(System.Environment.GetCommandLineArgs());

                Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);

                BuildTarget target = EditorUserBuildSettings.activeBuildTarget;

                int targetIndex = arguments.FindIndex(a => a == "-target");

                if (targetIndex >= 0)
                {
                    var targetStr = arguments[targetIndex + 1];
                    LogUtility.Logger.Log("Target specified:" + targetStr);

                    var newTarget = BuildTargetUtility.BuildTargetFromString(arguments[targetIndex + 1]);
                    if (!BuildTargetUtility.IsBuildTargetSupported(newTarget))
                    {
                        throw new AssetBundleGraphException(newTarget + " is not supported to build with this Unity. Please install platform support with installer(s).");
                    }

                    if (newTarget != target)
                    {
                                                #if UNITY_5_6 || UNITY_5_6_OR_NEWER
                        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetUtility.TargetToGroup(newTarget), newTarget);
                                                #else
                        EditorUserBuildSettings.SwitchActiveBuildTarget(newTarget);
                                                #endif
                        target = newTarget;
                    }
                }

                int graphIndex      = arguments.FindIndex(a => a == "-graph");
                int collectionIndex = arguments.FindIndex(a => a == "-collection");

                if (graphIndex >= 0 && collectionIndex >= 0)
                {
                    LogUtility.Logger.Log("-graph and -collection can not be used at once. Aborting...");
                    return;
                }

                Model.ConfigGraph graph = null;

                if (graphIndex >= 0)
                {
                    var graphPath = arguments[graphIndex + 1];
                    LogUtility.Logger.Log("Graph path:" + graphPath);

                    graph = AssetDatabase.LoadAssetAtPath <Model.ConfigGraph>(graphPath);

                    LogUtility.Logger.Log("AssetReference bundle building for:" + BuildTargetUtility.TargetToHumaneString(target));

                    if (graph == null)
                    {
                        LogUtility.Logger.Log("Graph data not found. To specify graph to execute, use -graph [path]. Aborting...");
                        return;
                    }

                    var result = AssetBundleGraphUtility.ExecuteGraph(target, graph);

                    if (result.IsAnyIssueFound)
                    {
                        LogUtility.Logger.Log("Building asset bundles terminated because of following errors. Please fix issues by opening editor.");
                        foreach (var e in result.Issues)
                        {
                            LogUtility.Logger.LogError(LogUtility.kTag, e.reason);
                        }
                    }
                }

                if (collectionIndex >= 0)
                {
                    var collectionName = arguments[collectionIndex + 1];
                    LogUtility.Logger.Log("Collection Name:" + collectionName);

                    LogUtility.Logger.Log("AssetReference bundle building for:" + BuildTargetUtility.TargetToHumaneString(target));

                    if (collectionName == null)
                    {
                        LogUtility.Logger.Log("Collection name not specified. To specify collection to execute, use -collection [name]. Aborting...");
                        return;
                    }
                    BatchBuildConfig.GraphCollection c = BatchBuildConfig.GetConfig().Find(collectionName);
                    if (c == null)
                    {
                        LogUtility.Logger.Log("Collection not found. Please open project and configure graph collection. Aborting...");
                        return;
                    }

                    var result = AssetBundleGraphUtility.ExecuteGraphCollection(target, c);

                    foreach (var r in result)
                    {
                        if (r.IsAnyIssueFound)
                        {
                            foreach (var e in r.Issues)
                            {
                                LogUtility.Logger.LogError(LogUtility.kTag, r.Graph.name + ":" + e.reason);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                LogUtility.Logger.LogError(LogUtility.kTag, e);
                LogUtility.Logger.LogError(LogUtility.kTag, "Building asset bundles terminated due to unexpected error.");
            } finally {
                LogUtility.Logger.Log("End of build.");
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Executes the graph.
 /// </summary>
 /// <returns>The graph.</returns>
 /// <param name="graph">Graph.</param>
 public static ExecuteGraphResult ExecuteGraph(Model.ConfigGraph graph)
 {
     return ExecuteGraph(EditorUserBuildSettings.activeBuildTarget, graph);
 }
Esempio n. 13
0
 public ExecuteGraphResult(Model.ConfigGraph g, List<NodeException> issues)
 {
     this.graph  = g;
     this.issues = issues;
 }
 public AssetReferenceStreamManager(Model.ConfigGraph graph)
 {
     m_connectionStreamMap = new Dictionary <string, Dictionary <string, List <AssetReference> > >();
     m_targetGraph         = graph;
 }