コード例 #1
0
        public void DrawToolBar()
        {
            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) {
                var r = AssetProcessEventRecord.GetRecord();

                if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Height(Model.Settings.GUI.TOOLBAR_HEIGHT)))
                {
                    AssetProcessEventRecord.GetRecord().Clear(true);
                    m_logViewController.EventSelectionChanged(null);
                    RefreshView();
                }

                GUILayout.Space(4);

                var clearOnBuild = m_clearOnBuild;
                clearOnBuild = GUILayout.Toggle(m_clearOnBuild, new GUIContent("Clear on Build"), EditorStyles.toolbarButton, GUILayout.Height(Model.Settings.GUI.TOOLBAR_HEIGHT));
                if (clearOnBuild != m_clearOnBuild)
                {
                    UserPreference.ClearAssetLogOnBuild = m_clearOnBuild = clearOnBuild;
                }

                GUILayout.FlexibleSpace();

                var showInfo  = GUILayout.Toggle(m_showInfo, new GUIContent(r.InfoEventCount.ToString(), m_infoIcon, "Toggle Show Info"), EditorStyles.toolbarButton, GUILayout.Height(Model.Settings.GUI.TOOLBAR_HEIGHT));
                var showError = GUILayout.Toggle(m_showError, new GUIContent(r.ErrorEventCount.ToString(), m_errorIcon, "Toggle Show Errors"), EditorStyles.toolbarButton, GUILayout.Height(Model.Settings.GUI.TOOLBAR_HEIGHT));

                if (showInfo != m_showInfo || showError != m_showError)
                {
                    m_showInfo  = showInfo;
                    m_showError = showError;
                    r.SetFilterCondition(m_showInfo, m_showError);
                    m_logViewController.Reload();
                }
            }
        }
コード例 #2
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, bool clearRecord = false, Action <Model.NodeData, string, float> updateHandler = null)
        {
            if (clearRecord)
            {
                AssetProcessEventRecord.GetRecord().Clear(false);
            }

            string assetPath = AssetDatabase.GetAssetPath(graph);

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

            AssetGraphController c = new AssetGraphController(graph);

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

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

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

            Action <Model.NodeData, string, float> defaultUpdateHandler = (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;
                }
            };

            if (updateHandler == null)
            {
                updateHandler = defaultUpdateHandler;
            }

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

            AssetDatabase.Refresh();

            return(new ExecuteGraphResult(target, graph, c.Issues));
        }
コード例 #3
0
        private void LogIssues()
        {
            var r = AssetProcessEventRecord.GetRecord();

            foreach (var e in m_nodeExceptions)
            {
                r.LogError(e);
            }
        }
コード例 #4
0
 public void Dispose()
 {
     if (m_Disposed)
     {
         return;
     }
     m_Disposed = true;
     AssetProcessEventRecord.GetRecord().EnabledRecording = m_oldState;
 }
コード例 #5
0
        public void DrawToolBar()
        {
            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
            {
                var r = AssetProcessEventRecord.GetRecord();

                if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Height(_assetGraphGuiConfig.TOOLBAR_HEIGHT)))
                {
                    AssetProcessEventRecord.GetRecord().Clear(true);
                    m_logViewController.EventSelectionChanged(null);
                    RefreshView();
                }

                GUILayout.Space(4);

                var clearOnBuild = m_clearOnBuild;
                clearOnBuild = GUILayout.Toggle(m_clearOnBuild, new GUIContent("Clear on Build"), EditorStyles.toolbarButton,
                                                GUILayout.Height(_assetGraphGuiConfig.TOOLBAR_HEIGHT));
                if (clearOnBuild != m_clearOnBuild)
                {
                    UserPreference.Preferences._clearAssetLogOnBuild = m_clearOnBuild = clearOnBuild;
                }

                GUILayout.FlexibleSpace();

                EditorGUI.BeginChangeCheck();

                m_searchKeywords = m_search.OnToolbarGUI(m_searchKeywords);

                if (EditorGUI.EndChangeCheck())
                {
                    r.SetFilterKeyword(m_searchKeywords);
                    m_logViewController.Reload();
                }

                var infoEventCountStr  = (string.IsNullOrEmpty(m_searchKeywords)) ? r.InfoEventCount.ToString() : r.FilteredInfoEventCount.ToString();
                var errorEventCountStr = (string.IsNullOrEmpty(m_searchKeywords)) ? r.ErrorEventCount.ToString() : r.FilteredErrorEventCount.ToString();

                var showInfo = GUILayout.Toggle(m_showInfo, new GUIContent(infoEventCountStr, m_infoIcon, "Toggle Show Info"), EditorStyles.toolbarButton,
                                                GUILayout.Height(_assetGraphGuiConfig.TOOLBAR_HEIGHT));
                var showError = GUILayout.Toggle(m_showError, new GUIContent(errorEventCountStr, m_errorIcon, "Toggle Show Errors"), EditorStyles.toolbarButton,
                                                 GUILayout.Height(_assetGraphGuiConfig.TOOLBAR_HEIGHT));

                if (showInfo != m_showInfo || showError != m_showError)
                {
                    m_showInfo  = showInfo;
                    m_showError = showError;
                    r.SetFilterCondition(m_showInfo, m_showError);
                    m_logViewController.Reload();
                }
            }
        }
コード例 #6
0
        protected override TreeViewItem BuildRoot()
        {
            var root = new AssetProcessEventListTreeItem();

            var r = AssetProcessEventRecord.GetRecord();

            if (r != null && r.Events != null)
            {
                foreach (var e in r.Events)
                {
                    root.AddChild(new AssetProcessEventListTreeItem(e));
                }
            }

            return(root);
        }
コード例 #7
0
        private void ApplyImportSetting(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming)
        {
            var referenceImporter = GetReferenceAssetImporter(node, true);

            var configurator = m_configuratorInstance.Get <IAssetImporterConfigurator> (target);

            Assertions.Assert.IsNotNull(configurator);

            foreach (var ag in incoming)
            {
                foreach (var groupKey in ag.assetGroups.Keys)
                {
                    var assets = ag.assetGroups[groupKey];
                    foreach (var asset in assets)
                    {
                        // skip if incoming asset is this custom setting asset
                        if (m_useCustomSettingAsset)
                        {
                            var assetGuid = AssetDatabase.AssetPathToGUID(asset.importFrom);
                            if (assetGuid == m_customSettingAssetGuid)
                            {
                                continue;
                            }
                        }

                        var  importer         = AssetImporter.GetAtPath(asset.importFrom);
                        bool importerModified = false;

                        if (configurator.IsModified(referenceImporter, importer, target, groupKey))
                        {
                            configurator.Configure(referenceImporter, importer, target, groupKey);
                            AssetProcessEventRecord.GetRecord().LogModify(asset);
                            importerModified = true;
                        }

                        if (importerModified)
                        {
                            importer.SaveAndReimport();
                            asset.TouchImportAsset();
                        }
                    }
                }
            }
        }
コード例 #8
0
        private void Init()
        {
            this.titleContent = new GUIContent("Asset Log");
            this.minSize      = new Vector2(150f, 100f);

            m_errorIcon = EditorGUIUtility.Load("icons/console.erroricon.sml.png") as Texture2D;
            m_infoIcon  = EditorGUIUtility.Load("icons/console.infoicon.sml.png") as Texture2D;

            m_showError = true;
            m_showInfo  = true;

            m_clearOnBuild = UserPreference.ClearAssetLogOnBuild;

            m_logViewController = new AssetProcessEventLogViewController();
            m_search            = new SearchField();

            AssetProcessEventRecord.GetRecord().SetFilterCondition(m_showInfo, m_showError);
            AssetProcessEventRecord.GetRecord().SetFilterKeyword(string.Empty);
        }
コード例 #9
0
        public void AddModifiedAsset(AssetReference a)
        {
            AssetPostprocessorContext ctx = null;

            if (m_contexts.Count == 0)
            {
                ctx = new AssetPostprocessorContext();
                m_contexts.Push(ctx);
            }
            else
            {
                ctx = m_contexts.Peek();
            }

            if (!ctx.ImportedAssets.Contains(a))
            {
                ctx.ImportedAssets.Add(a);
            }

            AssetProcessEventRecord.GetRecord().LogModify(a.assetDatabaseId);
        }
コード例 #10
0
        public override void Build(BuildTarget target,
                                   Model.NodeData node,
                                   IEnumerable <PerformGraph.AssetGroups> incoming,
                                   IEnumerable <Model.ConnectionData> connectionsToOutput,
                                   PerformGraph.Output Output,
                                   Action <Model.NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }
            var modifier = m_instance.Get <IModifier>(target);

            UnityEngine.Assertions.Assert.IsNotNull(modifier);
            Type targetType         = ModifierUtility.GetModifierTargetType(m_instance.ClassName);
            bool isAnyAssetModified = false;

            var aggregatedGroups = new Dictionary <string, List <AssetReference> >();

            foreach (var ag in incoming)
            {
                foreach (var name in ag.assetGroups.Keys)
                {
                    if (!aggregatedGroups.ContainsKey(name))
                    {
                        aggregatedGroups[name] = new List <AssetReference>();
                    }
                    aggregatedGroups[name].AddRange(ag.assetGroups[name].AsEnumerable());
                }
            }

            foreach (var assets in aggregatedGroups.Values)
            {
                foreach (var asset in assets)
                {
                    if (asset.assetType == targetType)
                    {
                        if (modifier.IsModified(asset.allData, assets))
                        {
                            modifier.Modify(asset.allData, assets);
                            asset.SetDirty();
                            AssetProcessEventRecord.GetRecord().LogModify(asset);

                            isAnyAssetModified = true;

                            // apply asset setting changes to AssetDatabase.
                            if (asset.isSceneAsset)
                            {
                                if (!EditorSceneManager.SaveScene(asset.scene))
                                {
                                    throw new NodeException("Failed to save modified scene:" + asset.importFrom, "See console for details.", node);
                                }
                            }
                            else
                            {
                                AssetDatabase.SaveAssets();
                            }
                        }
                        asset.ReleaseData();
                    }
                }
            }

            if (isAnyAssetModified)
            {
                AssetDatabase.Refresh();
            }

            if (incoming != null && Output != null)
            {
                // Modifier does not add, filter or change structure of group, so just pass given group of assets
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();

                Output(dst, aggregatedGroups);
            }
        }
コード例 #11
0
        public override void Build(BuildTarget target,
                                   Model.NodeData node,
                                   IEnumerable <PerformGraph.AssetGroups> incoming,
                                   IEnumerable <Model.ConnectionData> connectionsToOutput,
                                   PerformGraph.Output Output,
                                   Action <Model.NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }

            bool isAnyAssetGenerated = false;

            foreach (var entry in m_entries)
            {
                var generator = entry.m_instance.Get <IAssetGenerator>(target);
                UnityEngine.Assertions.Assert.IsNotNull(generator);

                foreach (var ag in incoming)
                {
                    foreach (var assets in ag.assetGroups.Values)
                    {
                        foreach (var a in assets)
                        {
                            var assetOutputDir = PrepareOutputDirectory(target, node, a);
                            var assetSaveDir   = FileUtility.PathCombine(assetOutputDir, GetGeneratorIdForSubPath(target, entry));
                            var assetSavePath  = FileUtility.PathCombine(assetSaveDir, a.fileName + generator.GetAssetExtension(a));

                            if (!File.Exists(assetSavePath) || AssetGenerateInfo.DoesAssetNeedRegenerate(entry, node, target, a))
                            {
                                if (!Directory.Exists(assetSaveDir))
                                {
                                    Directory.CreateDirectory(assetSaveDir);
                                }

                                if (!generator.GenerateAsset(a, assetSavePath))
                                {
                                    throw new AssetGraphException(
                                              $"{node.Name} :Failed to generate asset for {entry.m_name}");
                                }
                                if (!File.Exists(assetSavePath))
                                {
                                    throw new AssetGraphException(
                                              $"{node.Name} :{entry.m_name} returned success, but generated asset not found.");
                                }

                                AssetProcessEventRecord.GetRecord().LogModify(AssetDatabase.AssetPathToGUID(assetSavePath));

                                isAnyAssetGenerated = true;

                                LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)generating Asset:{1} with {2}({3})", node.Name, assetSavePath,
                                                            AssetGeneratorUtility.GetGUIName(entry.m_instance.ClassName),
                                                            AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName));

                                if (progressFunc != null)
                                {
                                    progressFunc(node, $"Creating {assetSavePath}", 0.5f);
                                }

                                AssetGenerateInfo.SaveAssetGenerateInfo(entry, node, target, a);
                            }
                        }
                    }
                }
            }

            if (isAnyAssetGenerated)
            {
                AssetDatabase.Refresh();
            }
        }
コード例 #12
0
        public override void Build(BuildTarget target,
                                   Model.NodeData node,
                                   IEnumerable <PerformGraph.AssetGroups> incoming,
                                   IEnumerable <Model.ConnectionData> connectionsToOutput,
                                   PerformGraph.Output Output,
                                   Action <Model.NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }

            var builder = m_instance.Get <IPrefabBuilder>(target);

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = PrepareOutputDirectory(target, node);
            Dictionary <string, List <AssetReference> > output = null;

            if (Output != null)
            {
                output = new Dictionary <string, List <AssetReference> >();
            }

            var aggregatedGroups = new Dictionary <string, List <AssetReference> >();

            foreach (var ag in incoming)
            {
                foreach (var key in ag.assetGroups.Keys)
                {
                    if (!aggregatedGroups.ContainsKey(key))
                    {
                        aggregatedGroups[key] = new List <AssetReference>();
                    }
                    aggregatedGroups[key].AddRange(ag.assetGroups[key].AsEnumerable());
                }
            }

            var anyPrefabCreated = false;

            foreach (var key in aggregatedGroups.Keys)
            {
                var assets = aggregatedGroups[key];

                var        allAssets      = LoadAllAssets(assets);
                GameObject previousPrefab = null; //TODO

                var prefabFileName = builder.CanCreatePrefab(key, allAssets, previousPrefab);
                var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab");

                if (!Directory.Exists(Path.GetDirectoryName(prefabSavePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(prefabSavePath));
                }

                if (!File.Exists(prefabSavePath) || PrefabBuildInfo.DoesPrefabNeedRebuilding(prefabOutputDir, this, node, target, key, assets))
                {
                    UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets, previousPrefab);
                    if (obj == null)
                    {
                        throw new AssetGraphException(string.Format("{0} :PrefabBuilder {1} returned null in CreatePrefab() [groupKey:{2}]",
                                                                    node.Name, builder.GetType().FullName, key));
                    }

                    LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)creating Prefab:{1} with {2}({3})", node.Name, prefabFileName,
                                                PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName),
                                                PrefabBuilderUtility.GetPrefabBuilderVersion(m_instance.ClassName));

                    if (progressFunc != null)
                    {
                        progressFunc(node, string.Format("Creating {0}", prefabFileName), 0.5f);
                    }

                    PrefabUtility.CreatePrefab(prefabSavePath, obj, m_replacePrefabOptions);
                    PrefabBuildInfo.SavePrefabBuildInfo(prefabOutputDir, this, node, target, key, assets);
                    GameObject.DestroyImmediate(obj);
                    anyPrefabCreated = true;
                    AssetProcessEventRecord.GetRecord().LogModify(AssetDatabase.AssetPathToGUID(prefabSavePath));
                }
                UnloadAllAssets(assets);

                if (anyPrefabCreated)
                {
                    AssetDatabase.SaveAssets();
                }

                if (output != null)
                {
                    output[key] = new List <AssetReference> ()
                    {
                        AssetReferenceDatabase.GetPrefabReference(prefabSavePath)
                    };
                }
            }

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }
        }
コード例 #13
0
        public override void Build(BuildTarget target,
                                   Model.NodeData node,
                                   IEnumerable <PerformGraph.AssetGroups> incoming,
                                   IEnumerable <Model.ConnectionData> connectionsToOutput,
                                   PerformGraph.Output Output,
                                   Action <Model.NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }

            var builder = m_instance.Get <IPrefabBuilder>(target);

            Assert.IsNotNull(builder);

            var prefabOutputDir = PrepareOutputDirectory(target, node);
            Dictionary <string, List <AssetReference> > output = null;

            if (Output != null)
            {
                output = new Dictionary <string, List <AssetReference> >();
            }

            var aggregatedGroups = new Dictionary <string, List <AssetReference> >();

            foreach (var ag in incoming)
            {
                foreach (var key in ag.assetGroups.Keys)
                {
                    if (!aggregatedGroups.ContainsKey(key))
                    {
                        aggregatedGroups[key] = new List <AssetReference>();
                    }
                    aggregatedGroups[key].AddRange(ag.assetGroups[key].AsEnumerable());
                }
            }

            var anyPrefabCreated = false;

            foreach (var key in aggregatedGroups.Keys)
            {
                var assets = aggregatedGroups[key];

                var allAssets = LoadAllAssets(assets);

                try
                {
                    m_createDescription.Reset();
                    var canCreatePrefab = builder.CanCreatePrefab(key, allAssets, ref m_createDescription);
                    Assert.IsTrue(canCreatePrefab, "CanCreatePrefab() should not fail at Build phase.");
                }
                catch (Exception e)
                {
                    throw new NodeException(e.Message, "See reason for detail.", node);
                }

                var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, m_createDescription.prefabName + ".prefab");

                if (!Directory.Exists(Path.GetDirectoryName(prefabSavePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(prefabSavePath));
                }

                if (!File.Exists(prefabSavePath) || PrefabBuildInfo.DoesPrefabNeedRebuilding(prefabOutputDir, this, node, target, key, assets, m_createDescription))
                {
                    GameObject obj;
                    GameObject previous = null;

                    try
                    {
                        if (m_loadPreviousPrefab && File.Exists(prefabSavePath))
                        {
                            previous = PrefabUtility.LoadPrefabContents(prefabSavePath);
                        }

                        obj = builder.CreatePrefab(key, allAssets, previous);
                    }
                    catch (Exception e)
                    {
                        throw new NodeException(e.Message, "See reason for detail.", node);
                    }

                    if (obj == null)
                    {
                        throw new AssetGraphException(
                                  $"{node.Name} :PrefabBuilder {builder.GetType().FullName} returned null in CreatePrefab() [groupKey:{key}]");
                    }

                    LogUtility.Logger.LogFormat(LogType.Log, "{0} is (re)creating Prefab:{1} with {2}({3})", node.Name, m_createDescription.prefabName,
                                                PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName),
                                                PrefabBuilderUtility.GetPrefabBuilderVersion(m_instance.ClassName));

                    progressFunc?.Invoke(node, $"Creating {m_createDescription.prefabName}", 0.5f);

                    var isPartOfAsset = PrefabUtility.IsPartOfPrefabAsset(obj);

                    PrefabUtility.SaveAsPrefabAsset(obj, prefabSavePath);

                    if (previous != obj && isPartOfAsset)
                    {
                        PrefabUtility.UnloadPrefabContents(obj);
                    }
                    else
                    {
                        Object.DestroyImmediate(obj);
                    }

                    if (previous)
                    {
                        PrefabUtility.UnloadPrefabContents(previous);
                    }

                    PrefabBuildInfo.SavePrefabBuildInfo(prefabOutputDir, this, node, target, key, assets, m_createDescription);
                    anyPrefabCreated = true;
                    AssetProcessEventRecord.GetRecord().LogModify(AssetDatabase.AssetPathToGUID(prefabSavePath));
                }
                UnloadAllAssets(assets);

                if (anyPrefabCreated)
                {
                    AssetDatabase.SaveAssets();
                }

                if (output != null)
                {
                    output[key] = new List <AssetReference> ()
                    {
                        AssetReferenceDatabase.GetPrefabReference(prefabSavePath)
                    };
                }
            }

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }
        }
コード例 #14
0
 public DisableAssetProcessEventRecordScope()
 {
     m_oldState = AssetProcessEventRecord.GetRecord().EnabledRecording;
     AssetProcessEventRecord.GetRecord().EnabledRecording = false;
 }