Exemple #1
0
        public static string GetPathWithAssetsPath(string pathUnderAssetsFolder)
        {
            var assetPath = Application.dataPath;

            return(FileUtility.PathCombine(assetPath, pathUnderAssetsFolder));
        }
        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 bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            var bundleNames    = inputGroupAssets.Keys.ToList();
            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var name in bundleNames)
            {
                bundleVariants[name] = new List <string>();
                var assets = inputGroupAssets[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            int validNames = 0;

            foreach (var name in bundleNames)
            {
                var assets = inputGroupAssets[name];
                // we do not build bundle without any asset
                if (assets.Count > 0)
                {
                    validNames += bundleVariants[name].Count;
                }
            }

            AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames];

            int bbIndex = 0;

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    var bundleName = name;
                    var assets     = inputGroupAssets[name];

                    if (assets.Count <= 0)
                    {
                        continue;
                    }

                    bundleBuild[bbIndex].assetBundleName    = bundleName;
                    bundleBuild[bbIndex].assetBundleVariant = v;
                    bundleBuild[bbIndex].assetNames         = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray();
                    ++bbIndex;
                }
            }


            BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target);


            var output = new Dictionary <string, List <Asset> >();

            output[key] = new List <Asset>();

            var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir);

            // add manifest file
            bundleNames.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target));
            foreach (var path in generatedFiles)
            {
                var fileName = Path.GetFileName(path);
                if (IsFileIntendedItem(fileName, bundleNames))
                {
                    output[key].Add(Asset.CreateAssetWithImportPath(path));
                }
                else
                {
                    Debug.LogWarning(node.Name + ":Irrelevant file found in assetbundle cache folder:" + fileName);
                }
            }

            Output(connectionToOutput, output, alreadyCached);
        }
Exemple #3
0
        public static List <string> GetCachedDataByNode(BuildTarget t, NodeData node)
        {
            switch (node.Kind)
            {
            case NodeKind.IMPORTSETTING_GUI: {
                // no cache file exists for importSetting.
                return(new List <string>());
            }

            case NodeKind.MODIFIER_GUI: {
                // no cache file exists for modifier.
                return(new List <string>());
            }

            case NodeKind.PREFABBUILDER_GUI: {
                var cachedPathBase = FileUtility.PathCombine(
                    AssetBundleGraphSettings.PREFABBUILDER_CACHE_PLACE,
                    node.Id,
                    SystemDataUtility.GetPathSafeTargetName(t)
                    );

                // no cache folder, no cache.
                if (!Directory.Exists(cachedPathBase))
                {
                    // search default platform + package
                    cachedPathBase = FileUtility.PathCombine(
                        AssetBundleGraphSettings.PREFABBUILDER_CACHE_PLACE,
                        node.Id,
                        SystemDataUtility.GetPathSafeDefaultTargetName()
                        );

                    if (!Directory.Exists(cachedPathBase))
                    {
                        return(new List <string>());
                    }
                }

                return(FileUtility.GetFilePathsInFolder(cachedPathBase));
            }

            case NodeKind.BUNDLECONFIG_GUI: {
                // do nothing.
                break;
            }

            case NodeKind.BUNDLEBUILDER_GUI: {
                var cachedPathBase = FileUtility.PathCombine(
                    AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE,
                    node.Id,
                    SystemDataUtility.GetPathSafeTargetName(t)
                    );

                // no cache folder, no cache.
                if (!Directory.Exists(cachedPathBase))
                {
                    // search default platform + package
                    cachedPathBase = FileUtility.PathCombine(
                        AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE,
                        node.Id,
                        SystemDataUtility.GetPathSafeDefaultTargetName()
                        );

                    if (!Directory.Exists(cachedPathBase))
                    {
                        return(new List <string>());
                    }
                }

                return(FileUtility.GetFilePathsInFolder(cachedPathBase));
            }

            default: {
                // nothing to do.
                break;
            }
            }
            return(new List <string>());
        }
Exemple #4
0
 public static string ModifierDataPathForDefaultPlatform(string nodeId)
 {
     return(FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, nodeId, ModifierOperatiorDataName(AssetBundleGraphSettings.PLATFORM_DEFAULT_NAME)));
 }
Exemple #5
0
 public static string ModifierDataPathForeachPlatform(string nodeId, string platformStr)
 {
     return(FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, nodeId, ModifierOperatiorDataName(platformStr)));
 }
Exemple #6
0
        public void Setup(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            if (groupedSources.Keys.Count == 0)
            {
                return;
            }

            // Modifier merges multiple incoming groups into one.
            if (1 < groupedSources.Keys.Count)
            {
                Debug.LogWarning(nodeName + " Modifier merges incoming group into \"" + groupedSources.Keys.ToList()[0]);
            }

            var groupMergeKey = groupedSources.Keys.ToList()[0];

            // merge all assets into single list.
            var inputSources = new List <Asset>();

            foreach (var groupKey in groupedSources.Keys)
            {
                inputSources.AddRange(groupedSources[groupKey]);
            }

            if (!inputSources.Any())
            {
                return;
            }

            // initialize as object.
            var modifierType = string.Empty;

            var first = true;

            foreach (var inputSource in inputSources)
            {
                var modifyTargetAssetPath = inputSource.importFrom;
                var assumedType           = TypeUtility.FindTypeOfAsset(modifyTargetAssetPath);

                if (assumedType == null || assumedType == typeof(object))
                {
                    continue;
                }

                if (first)
                {
                    first        = false;
                    modifierType = assumedType.ToString();
                    continue;
                }

                if (modifierType != assumedType.ToString())
                {
                    throw new NodeException("multiple Asset Type detected. consider reduce Asset Type number to only 1 by Filter. detected Asset Types is:" + modifierType + " , and " + assumedType.ToString(), nodeId);
                }
            }

            // modifierType is fixed.

            if (!string.IsNullOrEmpty(specifiedScriptClass))
            {
                Debug.LogError("modifierのScript版実装中。");
                return;
            }

            // check support.
            if (!TypeUtility.SupportedModifierOperatorDefinition.ContainsKey(modifierType))
            {
                throw new NodeException("current incoming Asset Type:" + modifierType + " is unsupported.", nodeId);
            }

            // generate modifierOperatorData if data is not exist yet.
            {
                var modifierOperationDataFolderPath = AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE;
                if (!Directory.Exists(modifierOperationDataFolderPath))
                {
                    Directory.CreateDirectory(modifierOperationDataFolderPath);
                }

                var opDataFolderPath = FileUtility.PathCombine(modifierOperationDataFolderPath, nodeId);
                if (!Directory.Exists(opDataFolderPath))
                {
                    Directory.CreateDirectory(opDataFolderPath);
                }

                // ready default platform path.
                var modifierOperatorDataPathForDefaultPlatform = FileUtility.PathCombine(opDataFolderPath, ModifierOperatiorDataName(AssetBundleGraphSettings.PLATFORM_DEFAULT_NAME));

                /*
                 *      create default platform ModifierOperatorData if not exist.
                 *      default ModifierOperatorData is the target platform for every platform by default.
                 */
                if (!File.Exists(modifierOperatorDataPathForDefaultPlatform))
                {
                    var operatorType = TypeUtility.SupportedModifierOperatorDefinition[modifierType];

                    var operatorInstance = Activator.CreateInstance(operatorType) as ModifierBase;

                    var defaultRenderTextureOp = operatorInstance.DefaultSetting();

                    /*
                     *      generated json data is typed as supported ModifierOperation type.
                     */
                    var jsonData   = JsonUtility.ToJson(defaultRenderTextureOp);
                    var prettified = AssetBundleGraphEditorWindow.PrettifyJson(jsonData);
                    using (var sw = new StreamWriter(modifierOperatorDataPathForDefaultPlatform)) {
                        sw.WriteLine(prettified);
                    }
                }
            }

            // validate saved data.
            ValidateModifiyOperationData(
                nodeId,
                currentPlatformStr,
                () => {
                throw new NodeException("No ModifierOperatorData found. please Setup first.", nodeId);
            },
                () => {
                /*do nothing.*/
            }
                );

            var outputSources = new List <Asset>();

            /*
             *      all assets types are same and do nothing to assets in setup.
             */
            foreach (var asset in inputSources)
            {
                outputSources.Add(Asset.DuplicateAsset(asset));
            }

            var outputDict = new Dictionary <string, List <Asset> >();

            outputDict[groupMergeKey] = outputSources;

            Output(nodeId, connectionIdToNextNode, outputDict, new List <string>());
        }
Exemple #7
0
        public void Run(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            if (groupedSources.Keys.Count == 0)
            {
                return;
            }

            // Modifier merges multiple incoming groups into one.
            if (1 < groupedSources.Keys.Count)
            {
                Debug.LogWarning(nodeName + " Modifier merges incoming group into \"" + groupedSources.Keys.ToList()[0]);
            }

            var groupMergeKey = groupedSources.Keys.ToList()[0];

            // merge all assets into single list.
            var inputSources = new List <Asset>();

            foreach (var groupKey in groupedSources.Keys)
            {
                inputSources.AddRange(groupedSources[groupKey]);
            }

            if (!inputSources.Any())
            {
                return;
            }

            // load type from 1st asset of flow.
            var modifierType = TypeUtility.FindTypeOfAsset(inputSources[0].importFrom).ToString();

            // modifierType is fixed.

            if (!string.IsNullOrEmpty(specifiedScriptClass))
            {
                Debug.LogError("modifierのScript版実装中。");
                return;
            }

            // check support.
            if (!TypeUtility.SupportedModifierOperatorDefinition.ContainsKey(modifierType))
            {
                throw new NodeException("current incoming Asset Type:" + modifierType + " is unsupported.", nodeId);
            }


            // validate saved data.
            ValidateModifiyOperationData(
                nodeId,
                currentPlatformStr,
                () => {
                throw new NodeException("No ModifierOperatorData found. please Setup first.", nodeId);
            },
                () => {
                /*do nothing.*/
            }
                );

            var outputSources = new List <Asset>();

            var modifierOperatorDataPathForTargetPlatform = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, nodeId, ModifierOperatiorDataName(currentPlatformStr));

            // if runtime platform specified modifierOperatorData is nof found,
            // use default platform modifierOperatorData.
            if (!File.Exists(modifierOperatorDataPathForTargetPlatform))
            {
                modifierOperatorDataPathForTargetPlatform = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, nodeId, ModifierOperatiorDataName(AssetBundleGraphSettings.PLATFORM_DEFAULT_NAME));
            }

            var loadedModifierOperatorData = string.Empty;

            using (var sr = new StreamReader(modifierOperatorDataPathForTargetPlatform)) {
                loadedModifierOperatorData = sr.ReadToEnd();
            }

            /*
             *      read saved modifierOperation type for detect data type.
             */
            var deserializedDataObject = JsonUtility.FromJson <ModifierBase>(loadedModifierOperatorData);
            var dataTypeString         = deserializedDataObject.operatorType;

            // sadly, if loaded assetType is no longer supported or not.
            if (!TypeUtility.SupportedModifierOperatorDefinition.ContainsKey(dataTypeString))
            {
                throw new NodeException("unsupported ModifierOperator Type:" + modifierType, nodeId);
            }

            var modifyOperatorType = TypeUtility.SupportedModifierOperatorDefinition[dataTypeString];

            /*
             *      make generic method for genearte desired typed ModifierOperator instance.
             */
            var modifyOperatorInstance = typeof(IntegratedGUIModifier)
                                         .GetMethod("FromJson")
                                         .MakeGenericMethod(modifyOperatorType)// set desired generic type here.
                                         .Invoke(this, new object[] { loadedModifierOperatorData }) as ModifierBase;

            var isChanged = false;

            foreach (var inputSource in inputSources)
            {
                var modifyTargetAssetPath = inputSource.importFrom;

                var modifyOperationTargetAsset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(modifyTargetAssetPath);

                if (!modifyOperatorInstance.IsChanged(modifyOperationTargetAsset))
                {
                    outputSources.Add(
                        Asset.CreateNewAssetWithImportPathAndStatus(
                            inputSource.importFrom,
                            false,                            // marked as not changed.
                            false
                            )
                        );
                    continue;
                }

                isChanged = true;
                modifyOperatorInstance.Modify(modifyOperationTargetAsset);

                outputSources.Add(
                    Asset.CreateNewAssetWithImportPathAndStatus(
                        inputSource.importFrom,
                        true,                        // marked as changed.
                        false
                        )
                    );
            }

            if (isChanged)
            {
                // apply asset setting changes to AssetDatabase.
                AssetDatabase.Refresh();
            }

            var outputDict = new Dictionary <string, List <Asset> >();

            outputDict[groupMergeKey] = outputSources;

            Output(nodeId, connectionIdToNextNode, outputDict, new List <string>());
        }