Beispiel #1
0
        static public bool DoesPrefabNeedRebuilding(PrefabBuilder builder, Model.NodeData node, BuildTarget target, string groupKey, List <AssetReference> assets)
        {
            var buildInfo = GetPrefabBuildInfo(builder, node, target, groupKey);

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

            // need rebuilding if given builder is changed
            if (buildInfo.m_builderClass != builder.Builder.ClassName)
            {
                return(true);
            }

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

            // need rebuilding if replace prefab option is changed
            if (buildInfo.m_replacePrefabOptions != (int)builder.Options)
            {
                return(true);
            }

            var builderVersion = PrefabBuilderUtility.GetPrefabBuilderVersion(builder.Builder.ClassName);

            // need rebuilding if given builder version is changed
            if (buildInfo.m_prefabBuilderVersion != builderVersion)
            {
                return(true);
            }

            // need rebuilding if given groupKey changed
            if (buildInfo.m_groupKey != groupKey)
            {
                return(true);
            }

            if (!Enumerable.SequenceEqual(
                    buildInfo.m_usedAssets.Select(v => v.importFrom).OrderBy(s => s),
                    assets.Select(v => v.importFrom).OrderBy(s => s)))
            {
                return(true);
            }

            // If any asset is modified from last time, then need rebuilding
            foreach (var usedAsset in buildInfo.m_usedAssets)
            {
                if (usedAsset.IsAssetModifiedFromLastTime)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        static public void SavePrefabBuildInfo(PrefabBuilder builder, Model.NodeData node, BuildTarget target, string groupKey, List <AssetReference> assets)
        {
            var prefabCacheDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            var buildInfoPath  = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset");

            var version = PrefabBuilderUtility.GetPrefabBuilderVersion(builder.Builder.ClassName);

            var buildInfo = ScriptableObject.CreateInstance <PrefabBuildInfo>();

            buildInfo.Initialize(groupKey, builder.Builder.ClassName, builder.Builder[target], version, builder.Options, assets);

            AssetDatabase.CreateAsset(buildInfo, buildInfoPath);
        }
Beispiel #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;
            }

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

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(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());
                }
            }

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

                var allAssets = LoadAllAssets(assets);

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

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

                if (PrefabBuildInfo.DoesPrefabNeedRebuilding(this, node, target, key, assets))
                {
                    UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets);
                    if (obj == null)
                    {
                        throw new AssetBundleGraphException(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(this, node, target, key, assets);
                    GameObject.DestroyImmediate(obj);
                }
                UnloadAllAssets(assets);

                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);
            }
        }