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);
        }
        static public void SaveAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset)
        {
            var cacheDir        = FileUtility.EnsureCacheDirExists(target, node, AssetGenerator.kCacheDirName);
            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);
        }
Exemple #3
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();
            }
        }