Exemplo n.º 1
0
        private void Filter(List <InternalAssetData> assets, Action <string, List <string> > FilterResultReceiver)
        {
            var exhaustiveAssets = new List <ExhaustiveAssetPathData>();

            foreach (var asset in assets)
            {
                exhaustiveAssets.Add(new ExhaustiveAssetPathData(asset.absoluteSourcePath, asset.importedPath));
            }

            for (var i = 0; i < connectionIdsFromThisNodeToChildNodesOrFakeIds.Length; i++)
            {
                // these 3 parameters depends on their contents order.
                var connectionId = connectionIdsFromThisNodeToChildNodesOrFakeIds[i];
                var keyword      = containsKeywords[i];
                var keytype      = containsKeytypes[i];

                // filter by keyword first
                List <ExhaustiveAssetPathData> keywordContainsAssets = exhaustiveAssets.Where(
                    assetData =>
                    !assetData.isFilterExhausted &&
                    Regex.IsMatch(assetData.importedPath, keyword, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace)
                    ).ToList();

                var typeMatchedAssetsAbsolutePaths = new List <string>();

                // then, filter by type
                foreach (var containedAssetData in keywordContainsAssets)
                {
                    if (keytype != AssetBundleGraphSettings.DEFAULT_FILTER_KEYTYPE)
                    {
                        var assumedType = TypeBinder.AssumeTypeOfAsset(containedAssetData.importedPath);
                        if (assumedType == null || keytype != assumedType.ToString())
                        {
                            continue;
                        }
                    }
                    typeMatchedAssetsAbsolutePaths.Add(containedAssetData.absoluteSourcePath);
                }

                // mark assets as exhausted.
                foreach (var exhaustiveAsset in exhaustiveAssets)
                {
                    if (typeMatchedAssetsAbsolutePaths.Contains(exhaustiveAsset.absoluteSourcePath))
                    {
                        exhaustiveAsset.isFilterExhausted = true;
                    }
                }

                if (connectionId != AssetBundleGraphSettings.FILTER_FAKE_CONNECTION_ID)
                {
                    FilterResultReceiver(connectionId, typeMatchedAssetsAbsolutePaths);
                }
            }
        }
Exemplo n.º 2
0
        private void Filtering(List <InternalAssetData> assets, Action <string, List <string> > Out)
        {
            for (var i = 0; i < containsKeywords.Count; i++)
            {
                var keyword = containsKeywords[i];
                var keytype = containsKeytypes[i];

                var contains = assets.Where(assetData => assetData.importedPath.Contains(keyword)).ToList();

                // if keyword is wildcard, use type for constraint. pass all assets.
                if (keyword == AssetBundleGraphSettings.FILTER_KEYWORD_WILDCARD)
                {
                    contains = assets;
                }

                // type constraint.
                if (keytype != AssetBundleGraphSettings.DEFAULT_FILTER_KEYTYPE)
                {
                    var typeContains = new List <string>();

                    foreach (var containedAssetData in contains)
                    {
                        var assumedType = TypeBinder.AssumeTypeOfAsset(containedAssetData.importedPath);
                        if (keytype == assumedType.ToString())
                        {
                            typeContains.Add(containedAssetData.absoluteSourcePath);
                        }
                    }

                    Out(keyword, typeContains);
                    continue;
                }

                var containsAssetAbsolutePaths = contains.Select(assetData => assetData.absoluteSourcePath).ToList();
                Out(keyword, containsAssetAbsolutePaths);
            }
        }
Exemplo n.º 3
0
        public void Setup(string nodeId, string labelToNext, Dictionary <string, List <InternalAssetData> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <InternalAssetData> >, List <string> > Output)
        {
            var outputDict = new Dictionary <string, List <InternalAssetData> >();

            var first = true;

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

            // shrink group to 1 group.
            if (1 < groupedSources.Keys.Count)
            {
                Debug.LogWarning("modifierSetting shrinking group to \"" + groupedSources.Keys.ToList()[0] + "\" forcely.");
            }

            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.MODIFIER_SAMPLING_PLACE, nodeId);

            ValidateModifierSample(samplingDirectoryPath,
                                   (string noSampleFolder) => {
                // do nothing. keep importing new asset for sampling.
            },
                                   (string noSampleFile) => {
                // do nothing. keep importing new asset for sampling.
            },
                                   (string samplePath) => {
                first = false;
            },
                                   (string tooManysample) => {
                first = false;
            }
                                   );

            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 assumedType = TypeBinder.AssumeTypeOfAsset(inputSource.importedPath);

                var newData = InternalAssetData.InternalAssetDataByImporter(
                    inputSource.traceId,
                    inputSource.absoluteSourcePath,
                    inputSource.sourceBasePath,
                    inputSource.fileNameAndExtension,
                    inputSource.pathUnderSourceBase,
                    inputSource.importedPath,
                    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 Modifier generating ModifierSetting...", targetFilePath, 0);
                    FileController.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath);
                    first = false;
                    AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                    EditorUtility.ClearProgressBar();
                }


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

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

            Output(nodeId, labelToNext, outputDict, new List <string>());
        }
Exemplo n.º 4
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>());
        }
Exemplo n.º 5
0
        public void Run(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;
            }

            // load type from 1st asset of flow.
            var modifierType = TypeBinder.AssumeTypeOfAsset(inputSources[0].importedPath).ToString();

            // modifierType is fixed. check support.
            if (!TypeBinder.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 <InternalAssetData>();

            var modifierOperatorDataPathForTargetPlatform = FileController.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 = FileController.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 modifierOperator type for detect data type.
             */
            var deserializedDataObject = JsonUtility.FromJson <ModifierOperators.OperatorBase>(loadedModifierOperatorData);
            var dataTypeString         = deserializedDataObject.dataType;

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

            var modifyOperatorType = TypeBinder.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 ModifierOperators.OperatorBase;

            var isChanged = false;

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

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

                if (!modifyOperatorInstance.IsChanged(modifyOperationTargetAsset))
                {
                    var notChangedData = InternalAssetData.InternalAssetDataGeneratedByImporterOrModifierOrPrefabricator(
                        inputSource.importedPath,
                        AssetDatabase.AssetPathToGUID(inputSource.importedPath),
                        AssetBundleGraphInternalFunctions.GetAssetType(inputSource.importedPath),
                        false,                        // marked as not changed.
                        false
                        );
                    outputSources.Add(notChangedData);
                    continue;
                }

                isChanged = true;
                modifyOperatorInstance.Modify(modifyOperationTargetAsset);

                var newData = InternalAssetData.InternalAssetDataGeneratedByImporterOrModifierOrPrefabricator(
                    inputSource.importedPath,
                    AssetDatabase.AssetPathToGUID(inputSource.importedPath),
                    AssetBundleGraphInternalFunctions.GetAssetType(inputSource.importedPath),
                    true,                    // marked as changed.
                    false
                    );

                outputSources.Add(newData);
            }

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

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

            outputDict[groupMergeKey] = outputSources;

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