Beispiel #1
0
        static public bool DoesAssetNeedRegenerate(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset)
        {
            var generateInfo = GetAssetGenerateInfo(entry, node, target, asset);

            // need rebuilding if no buildInfo found
            if (generateInfo == null)
            {
                return(true);
            }

            // need rebuilding if given builder is changed
            if (generateInfo.m_generatorClass != entry.m_instance.ClassName)
            {
                return(true);
            }

            // need rebuilding if given builder is changed
            if (generateInfo.m_instanceData != entry.m_instance[target])
            {
                return(true);
            }

            var version = AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName);

            // need rebuilding if given builder version is changed
            if (generateInfo.m_generatorVersion != version)
            {
                return(true);
            }

            if (generateInfo.m_usedAsset.importFrom != asset.importFrom)
            {
                return(true);
            }

            // If asset is modified from last time, then need rebuilding
            if (generateInfo.m_usedAsset.IsAssetModifiedFromLastTime)
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        static public void SaveAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset)
        {
            var cacheDir        = FileUtility.EnsureAssetGeneratorCacheDirExists(target, node);
            var generateInfoDir = FileUtility.PathCombine(cacheDir, entry.m_id);

            if (!Directory.Exists(generateInfoDir))
            {
                Directory.CreateDirectory(generateInfoDir);
            }
            var generatorInfoPath = FileUtility.PathCombine(generateInfoDir, asset.fileNameAndExtension + ".asset");

            var version = AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName);

            var info = ScriptableObject.CreateInstance <AssetGenerateInfo>();

            info.Initialize(entry.m_instance.ClassName, entry.m_instance[target], version, asset);

            AssetDatabase.CreateAsset(info, generatorInfoPath);
        }
Beispiel #3
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)) {
                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.Data, entry);
                        // event must raise to propagate change to connection associated with point
                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED, node, Vector2.zero, GetConnectionPoint(node.Data, entry)));
                        onValueChanged();
                    }
                }

                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(
                            string.Format(
                                "Your AssetGenerator script {0} is missing from assembly. Did you delete script?", entry.m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_ASSETGENERATOR.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one AssetGenerator script to use this node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), 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);
                        }
                    }
                }

                GUILayout.Space(4);

                if (GUILayout.Button("Remove Generator"))
                {
                    m_removingEntry = entry;
                }
            }
        }
Beispiel #4
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);

                var assetOutputDir = FileUtility.EnsureAssetGeneratorCacheDirExists(target, node);
                var assetSaveDir   = FileUtility.PathCombine(assetOutputDir, entry.m_id);

                if (!Directory.Exists(assetSaveDir))
                {
                    Directory.CreateDirectory(assetSaveDir);
                }

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

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

                                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, string.Format("Creating {0}", assetSavePath), 0.5f);
                                }

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

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