private void Filter(List <Asset> assets, Action <string, List <string> > FilterResultReceiver) { var exhaustiveAssets = new List <ExhaustiveAssetPathData>(); foreach (var asset in assets) { exhaustiveAssets.Add(new ExhaustiveAssetPathData(asset.absoluteAssetPath, asset.importFrom)); } 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.importFrom, 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 = TypeUtility.FindTypeOfAsset(containedAssetData.importFrom); if (assumedType == null || keytype != assumedType.ToString()) { continue; } } typeMatchedAssetsAbsolutePaths.Add(containedAssetData.absoluteAssetPath); } // mark assets as exhausted. foreach (var exhaustiveAsset in exhaustiveAssets) { if (typeMatchedAssetsAbsolutePaths.Contains(exhaustiveAsset.absoluteAssetPath)) { exhaustiveAsset.isFilterExhausted = true; } } if (connectionId != AssetBundleGraphSettings.FILTER_FAKE_CONNECTION_ID) { FilterResultReceiver(connectionId, typeMatchedAssetsAbsolutePaths); } } }
private void Filter(NodeData node, Dictionary <string, List <Asset> > inputGroupAssets, Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output) { foreach (var connToChild in connectionsToChild) { var filter = node.FilterConditions.Find(fc => fc.ConnectionPoint.Id == connToChild.FromNodeConnectionPointId); UnityEngine.Assertions.Assert.IsNotNull(filter); var output = new Dictionary <string, List <Asset> >(); foreach (var groupKey in inputGroupAssets.Keys) { var assets = inputGroupAssets[groupKey]; var filteringAssets = new List <FilterableAsset>(); assets.ForEach(a => filteringAssets.Add(new FilterableAsset(a))); // filter by keyword first List <FilterableAsset> keywordContainsAssets = filteringAssets.Where( assetData => !assetData.isFiltered && Regex.IsMatch(assetData.asset.importFrom, filter.FilterKeyword, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace) ).ToList(); List <FilterableAsset> finalFilteredAsset = new List <FilterableAsset>(); // then, filter by type foreach (var a in keywordContainsAssets) { if (filter.FilterKeytype != AssetBundleGraphSettings.DEFAULT_FILTER_KEYTYPE) { var assumedType = TypeUtility.FindTypeOfAsset(a.asset.importFrom); if (assumedType == null || filter.FilterKeytype != assumedType.ToString()) { continue; } } finalFilteredAsset.Add(a); } // mark assets as exhausted. foreach (var a in finalFilteredAsset) { a.isFiltered = true; } output[groupKey] = finalFilteredAsset.Select(v => v.asset).ToList(); } Output(connToChild, output, null); } }
public static void ValidateModifier( NodeData node, BuildTarget target, List <Asset> incomingAssets, Action <Type, Type, Asset> multipleAssetTypeFound, Action noModiferData, Action failedToCreateModifier, Action <Type, Type> incomingTypeMismatch ) { Type expectedType = TypeUtility.FindIncomingAssetType(incomingAssets); if (expectedType != null) { foreach (var a in incomingAssets) { Type assetType = TypeUtility.FindTypeOfAsset(a.importFrom); if (assetType != expectedType) { multipleAssetTypeFound(expectedType, assetType, a); } } } if (string.IsNullOrEmpty(node.InstanceData[target])) { noModiferData(); } var modifier = ModifierUtility.CreateModifier(node, target); if (null == modifier) { failedToCreateModifier(); } // if there is no incoming assets, there is no way to check if // right type of asset is coming in - so we'll just skip the test if (incomingAssets.Any()) { var targetType = ModifierUtility.GetModifierTargetType(modifier); if (targetType != expectedType) { incomingTypeMismatch(targetType, expectedType); } } }
public static void ValidateInputSetting( NodeData node, BuildTarget target, List <Asset> incomingAssets, Action <Type, Type, Asset> multipleAssetTypeFound, Action <Type> unsupportedType, Action <Type, Type> incomingTypeMismatch, Action <ConfigStatus> errorInConfig ) { Type expectedType = TypeUtility.FindIncomingAssetType(incomingAssets); if (multipleAssetTypeFound != null) { if (expectedType != null) { foreach (var a in incomingAssets) { Type assetType = TypeUtility.FindTypeOfAsset(a.importFrom); if (assetType != expectedType) { multipleAssetTypeFound(expectedType, assetType, a); } } } } if (unsupportedType != null) { if (expectedType != null) { if (expectedType == typeof(UnityEditor.TextureImporter) || expectedType == typeof(UnityEditor.ModelImporter) || expectedType == typeof(UnityEditor.AudioImporter) ) { // good. do nothing } else { unsupportedType(expectedType); } } } var status = GetConfigStatus(node); if (errorInConfig != null) { if (status != ConfigStatus.GoodSampleFound) { errorInConfig(status); } } if (incomingTypeMismatch != null) { // if there is no incoming assets, there is no way to check if // right type of asset is coming in - so we'll just skip the test if (incomingAssets.Any() && status == ConfigStatus.GoodSampleFound) { Type targetType = GetReferenceAssetImporter(node).GetType(); if (targetType != expectedType) { incomingTypeMismatch(targetType, expectedType); } } } }
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 ModifierOperators.OperatorBase; 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>()); }
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 <ModifierOperators.OperatorBase>(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 ModifierOperators.OperatorBase; 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>()); }