示例#1
0
        static public bool DoesPrefabNeedRebuilding(NodeData node, BuildTarget target, string groupKey, List <AssetReference> assets)
        {
            var buildInfo = GetPrefabBuildInfo(node, target, groupKey);

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

            // need rebuilding if given builder is changed
            if (buildInfo.m_prefabBuilderClass != node.ScriptClassName)
            {
                return(true);
            }

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

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

            var builderVersion = PrefabBuilderUtility.GetPrefabBuilderVersion(node.ScriptClassName);

            // 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);
        }
示例#2
0
        static public void SavePrefabBuildInfo(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(node.ScriptClassName);

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

            buildInfo.Initialize(groupKey, node.ScriptClassName, node.InstanceData[target], version, node.ReplacePrefabOptions, assets);

            AssetDatabase.CreateAsset(buildInfo, buildInfoPath);
        }
示例#3
0
        public void Run(BuildTarget target,
                        NodeData node,
                        IEnumerable <PerformGraph.AssetGroups> incoming,
                        IEnumerable <ConnectionData> connectionsToOutput,
                        PerformGraph.Output Output,
                        Action <NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }

            var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, 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 (PrefabBuildInfo.DoesPrefabNeedRebuilding(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(node.ScriptClassName),
                                                PrefabBuilderUtility.GetPrefabBuilderVersion(node.ScriptClassName));

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

                    PrefabUtility.CreatePrefab(prefabSavePath, obj, node.ReplacePrefabOptions);
                    PrefabBuildInfo.SavePrefabBuildInfo(node, target, key, assets);
                    GameObject.DestroyImmediate(obj);
                }
                allAssets.ForEach(o => Resources.UnloadAsset(o));

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

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }
        }