Exemple #1
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();
            }
        }
Exemple #2
0
        private void DrawGeneratorSetting(
            GeneratorEntry entry,
            NodeGUI node,
            AssetReferenceStreamManager streamManager,
            NodeGUIEditor editor,
            Action onValueChanged)
        {
            var generator = entry.m_instance.Get <IAssetGenerator>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                using (new GUILayout.HorizontalScope())
                {
                    var newName = EditorGUILayout.TextField("Name", entry.m_name);
                    if (newName != entry.m_name)
                    {
                        using (new RecordUndoScope("Change Name", node, true)) {
                            entry.m_name = newName;
                            UpdateGeneratorEntry(node, entry);
                            onValueChanged();
                        }
                    }

                    if (GUILayout.Button(m_popupIcon, GUI.skin.label, GUILayout.Width(20f)))
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Remove Generator"), false, () =>
                        {
                            m_removingEntry = entry;
                        });
                        menu.ShowAsContext();
                    }
                }

                var map = AssetGeneratorUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("AssetGenerator");
                        var guiName = AssetGeneratorUtility.GetGUIName(entry.m_instance.ClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change AssetGenerator class", node, true)) {
                                        generator = AssetGeneratorUtility.CreateGenerator(selectedGUIName);
                                        entry.m_instance.Set(editor.CurrentEditingGroup, generator);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(entry.m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(entry.m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            $"Your AssetGenerator script {entry.m_instance.ClassName} is missing from assembly. Did you delete script?", MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_ASSETGENERATOR.Split('/');
                        EditorGUILayout.HelpBox(
                            $"You need to create at least one AssetGenerator script to use this node. To start, select {menuNames[1]}>{menuNames[2]}>{menuNames[3]} menu and create new script from template.", MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, entry.m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            entry.m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                        }
                        else
                        {
                            entry.m_instance.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        if (generator != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change AssetGenerator Setting", node)) {
                                    entry.m_instance.Set(editor.CurrentEditingGroup, generator);
                                    onValueChanged();
                                }
                            };

                            generator.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }