EnsurePrefabBuilderCacheDirExists() public static method

public static EnsurePrefabBuilderCacheDirExists ( BuildTarget t, NodeData node ) : string
t BuildTarget
node NodeData
return string
Ejemplo n.º 1
0
        static private PrefabBuildInfo GetPrefabBuildInfo(NodeData node, BuildTarget target, string groupKey)
        {
            var prefabCacheDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            var buildInfoPath  = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset");

            return(AssetDatabase.LoadAssetAtPath <PrefabBuildInfo>(buildInfoPath));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public void Setup(BuildTarget target,
                          NodeData node,
                          ConnectionPointData inputPoint,
                          ConnectionData connectionToOutput,
                          Dictionary <string, List <Asset> > inputGroupAssets,
                          List <string> alreadyCached,
                          Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            ValidatePrefabBuilder(node, target, inputGroupAssets,
                                  () => {
                throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id);
            },
                                  () => {
                throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id);
            },
                                  (string groupKey) => {
                throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id);
            },
                                  (Asset badAsset) => {
                throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id);
            }
                                  );

            var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >();

            foreach (var key in inputGroupAssets.Keys)
            {
                var prefabFileName = builder.CanCreatePrefab(key, LoadAllAssets(inputGroupAssets[key]));
                output[key] = new List <Asset> ()
                {
                    Asset.CreateAssetWithImportPath(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"))
                };
            }

            Output(connectionToOutput, output, null);
        }
Ejemplo n.º 4
0
        public void Run(BuildTarget target,
                        NodeData node,
                        ConnectionPointData inputPoint,
                        ConnectionData connectionToOutput,
                        Dictionary <string, List <Asset> > inputGroupAssets,
                        List <string> alreadyCached,
                        Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(builder);

            var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
            Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >();

            foreach (var key in inputGroupAssets.Keys)
            {
                var allAssets              = LoadAllAssets(inputGroupAssets[key]);
                var prefabFileName         = builder.CanCreatePrefab(key, allAssets);
                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));
                }

                var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab");
                PrefabUtility.CreatePrefab(prefabSavePath, obj, ReplacePrefabOptions.Default);

                output[key] = new List <Asset> ()
                {
                    Asset.CreateAssetWithImportPath(prefabSavePath)
                };
                GameObject.DestroyImmediate(obj);
            }

            Output(connectionToOutput, output, null);
        }
Ejemplo n.º 5
0
        public void Setup(BuildTarget target,
                          NodeData node,
                          IEnumerable <PerformGraph.AssetGroups> incoming,
                          IEnumerable <ConnectionData> connectionsToOutput,
                          PerformGraph.Output Output)
        {
            ValidatePrefabBuilder(node, target, incoming,
                                  () => {
                throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id);
            },
                                  () => {
                throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id);
            },
                                  (string groupKey) => {
                throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id);
            },
                                  (AssetReference badAsset) => {
                throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id);
            }
                                  );

            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 thresold = PrefabBuilderUtility.GetPrefabBuilderAssetThreshold(node.ScriptClassName);
                if (thresold < assets.Count)
                {
                    var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(node.ScriptClassName);
                    throw new NodeException(string.Format("{0} :Too many assets passed to {1} for group:{2}. {3}'s threshold is set to {4}",
                                                          node.Name, guiName, key, guiName, thresold), node.Id);
                }

                List <UnityEngine.Object> allAssets = LoadAllAssets(aggregatedGroups[key]);
                var prefabFileName = builder.CanCreatePrefab(key, allAssets);
                if (output != null && prefabFileName != null)
                {
                    output[key] = new List <AssetReference> ()
                    {
                        AssetReferenceDatabase.GetPrefabReference(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"))
                    };
                }
                allAssets.ForEach(o => Resources.UnloadAsset(o));
            }

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }
        }
Ejemplo n.º 6
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);
            }
        }