示例#1
0
        public void Setup(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, 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 <InternalAssetData>();

            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.importedPath;
                var assumedType           = TypeBinder.AssumeTypeOfAsset(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. check support.
            if (!TypeBinder.SupportedModifierOperatorDefinition.ContainsKey(modifierType))
            {
                throw new NodeException("current incoming Asset Type:" + modifierType + " is unsupported.", nodeId);
            }

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

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

                // ready default platform path.
                var modifierOperatorDataPathForDefaultPlatform = FileController.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 = TypeBinder.SupportedModifierOperatorDefinition[modifierType];

                    var operatorInstance = Activator.CreateInstance(operatorType) as ModifierOperators.OperatorBase;

                    var defaultRenderTextureOp = operatorInstance.DefaultSetting();

                    /*
                     *      generated json data is typed as supported ModifierOperation type.
                     */
                    var jsonData   = JsonUtility.ToJson(defaultRenderTextureOp);
                    var prettified = AssetBundleGraph.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 <InternalAssetData>();

            /*
             *      all assets types are same and do nothing to assets in setup.
             */
            foreach (var inputSource in inputSources)
            {
                var modifyTargetAssetPath = inputSource.importedPath;

                var newData = InternalAssetData.InternalAssetDataByImporterOrModifier(
                    inputSource.traceId,
                    inputSource.absoluteSourcePath,
                    inputSource.sourceBasePath,
                    inputSource.fileNameAndExtension,
                    inputSource.pathUnderSourceBase,
                    inputSource.importedPath,
                    null,
                    inputSource.assetType
                    );

                outputSources.Add(newData);
            }

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

            outputDict[groupMergeKey] = outputSources;

            Output(nodeId, connectionIdToNextNode, outputDict, new List <string>());
        }
        public void Setup(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            // reserve importSetting type for limit asset.
            var importSettingSampleType = string.Empty;


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

            var first = true;

            if (groupedSources.Keys.Count == 0)
            {
                return;
            }

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

            var inputSources = new List <InternalAssetData>();

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

            var assumedImportedAssetDatas = new List <InternalAssetData>();


            var samplingDirectoryPath = FileController.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, nodeId);

            ValidateImportSample(samplingDirectoryPath,
                                 (string samplePath) => {
                // do nothing. keep importing new asset for sampling.
            },
                                 (string samplePath) => {
                // do nothing. keep importing new asset for sampling.
            },
                                 (string samplePath) => {
                importSettingSampleType = AssetImporter.GetAtPath(samplePath).GetType().ToString();
                first = false;
            },
                                 (string samplePath) => {
                throw new NodeException(
                    String.Format("Too many sample file found for this import setting node. Delete files in {0} or use \"Clear Saved ImportSettings\" menu.", samplePath),
                    nodeId);
            }
                                 );

            var alreadyImported = new List <string>();
            var ignoredResource = new List <string>();


            foreach (var inputSource in inputSources)
            {
                if (string.IsNullOrEmpty(inputSource.absoluteSourcePath))
                {
                    if (!string.IsNullOrEmpty(inputSource.importedPath))
                    {
                        alreadyImported.Add(inputSource.importedPath);
                        continue;
                    }

                    ignoredResource.Add(inputSource.fileNameAndExtension);
                    continue;
                }

                var assumedImportedPath = inputSource.importedPath;

                var assumedType     = AssetImporter.GetAtPath(assumedImportedPath).GetType();
                var importerTypeStr = assumedType.ToString();

                /*
                 *      only texture, model and audio importer is acceptable.
                 */
                switch (importerTypeStr)
                {
                case "UnityEditor.TextureImporter":
                case "UnityEditor.ModelImporter":
                case "UnityEditor.AudioImporter": {
                    break;
                }

                default: {
                    throw new NodeException("unhandled importer type:" + importerTypeStr, nodeId);
                }
                }

                var newData = InternalAssetData.InternalAssetDataByImporterOrModifier(
                    inputSource.traceId,
                    inputSource.absoluteSourcePath,
                    inputSource.sourceBasePath,
                    inputSource.fileNameAndExtension,
                    inputSource.pathUnderSourceBase,
                    assumedImportedPath,
                    null,
                    assumedType
                    );
                assumedImportedAssetDatas.Add(newData);

                if (first)
                {
                    if (!Directory.Exists(samplingDirectoryPath))
                    {
                        Directory.CreateDirectory(samplingDirectoryPath);
                    }

                    var absoluteFilePath = inputSource.absoluteSourcePath;
                    var targetFilePath   = FileController.PathCombine(samplingDirectoryPath, inputSource.fileNameAndExtension);

                    EditorUtility.DisplayProgressBar("AssetBundleGraph ImportSetting generating ImporterSetting...", targetFilePath, 0);
                    FileController.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath);
                    first = false;
                    AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                    EditorUtility.ClearProgressBar();

                    importSettingSampleType = AssetImporter.GetAtPath(targetFilePath).GetType().ToString();
                }
                else
                {
                    if (importerTypeStr != importSettingSampleType)
                    {
                        throw new NodeException("Multiple asset type is given to Importer Settings. ImporterSetting Takes only 1 asset type." + nodeName + " is configured for " + importSettingSampleType + ", but " + importerTypeStr + " found.", nodeId);
                    }
                }


                if (alreadyImported.Any())
                {
                    Debug.LogError("importSetting:" + string.Join(", ", alreadyImported.ToArray()) + " are already imported.");
                }
                if (ignoredResource.Any())
                {
                    Debug.LogError("importSetting:" + string.Join(", ", ignoredResource.ToArray()) + " are ignored.");
                }

                outputDict[groupedSources.Keys.ToList()[0]] = assumedImportedAssetDatas;
            }

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