public static CreateNewAssetWithImportPathAndStatus ( string importFrom, bool isNew, bool isBundled ) : |
||
importFrom | string | |
isNew | bool | |
isBundled | bool | |
return |
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) { var usedCache = new List <string>(); var invalids = new List <string>(); foreach (var sources in groupedSources.Values) { foreach (var source in sources) { if (string.IsNullOrEmpty(source.importFrom)) { invalids.Add(source.absoluteAssetPath); } } } if (invalids.Any()) { throw new NodeException(string.Join(", ", invalids.ToArray()) + " are not imported yet. These assets need to be imported before prefabricated.", nodeId); } var recommendedPrefabOutputDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.PREFABRICATOR_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey()); var outputDict = new Dictionary <string, List <Asset> >(); var cachedOrGenerated = new List <string>(); foreach (var groupKey in groupedSources.Keys) { var inputSources = groupedSources[groupKey]; var recommendedPrefabPath = FileUtility.PathCombine(recommendedPrefabOutputDirectoryPath, groupKey); if (!recommendedPrefabPath.EndsWith(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString())) { recommendedPrefabPath = recommendedPrefabPath + AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString(); } /* * ready input resource info for execute. not contains cache in this node. */ var assets = new List <DepreacatedAssetInfo>(); foreach (var assetData in inputSources) { var assetName = assetData.fileNameAndExtension; var assetType = assetData.assetType; var assetPath = assetData.importFrom; var assetDatabaseId = assetData.assetDatabaseId; assets.Add(new DepreacatedAssetInfo(assetName, assetType, assetPath, assetDatabaseId)); } // collect generated prefab path. var generated = new List <string>(); var outputSources = new List <Asset>(); /* * Prefabricate(GameObject baseObject, string prefabName, bool forceGenerate) method. */ Func <GameObject, string, bool, string> Prefabricate = (GameObject baseObject, string prefabName, bool forceGenerate) => { var newPrefabOutputPath = Path.Combine(recommendedPrefabPath, prefabName); if (forceGenerate || !SystemDataUtility.IsAllAssetsCachedAndUpdated(inputSources, alreadyCached, newPrefabOutputPath)) { // not cached, create new. UnityEngine.Object prefabFile = PrefabUtility.CreateEmptyPrefab(newPrefabOutputPath); // export prefab data. PrefabUtility.ReplacePrefab(baseObject, prefabFile); // save prefab. AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); AssetDatabase.SaveAssets(); generated.Add(newPrefabOutputPath); cachedOrGenerated.Add(newPrefabOutputPath); Debug.Log(nodeName + " created new prefab: " + newPrefabOutputPath); } else { // cached. usedCache.Add(newPrefabOutputPath); cachedOrGenerated.Add(newPrefabOutputPath); Debug.Log(nodeName + " used cached prefab: " + newPrefabOutputPath); } isPrefabricateFunctionCalled = true; return(newPrefabOutputPath); }; if (!Directory.Exists(recommendedPrefabPath)) { // create recommended directory. Directory.CreateDirectory(recommendedPrefabPath); } /* * execute inheritee's input method. */ try { CreatePrefab(nodeName, nodeId, groupKey, assets, recommendedPrefabPath, Prefabricate); } catch (Exception e) { Debug.LogError(nodeName + " Error:" + e); throw new NodeException(nodeName + " Error:" + e, nodeId); } if (!isPrefabricateFunctionCalled) { Debug.LogWarning(nodeName + ": Prefabricate delegate was not called. Prefab might not be created properly."); } /* * ready assets-output-data from this node to next output. * it contains "cached" or "generated as prefab" or "else" assets. * output all assets. */ var currentAssetsInThisNode = FileUtility.FilePathsInFolder(recommendedPrefabPath); foreach (var generatedCandidateAssetPath in currentAssetsInThisNode) { /* * candidate is new, regenerated prefab. */ if (generated.Contains(generatedCandidateAssetPath)) { var newAsset = Asset.CreateNewAssetWithImportPathAndStatus( generatedCandidateAssetPath, true, false ); outputSources.Add(newAsset); continue; } /* * candidate is not new prefab. */ var cachedPrefabAsset = Asset.CreateNewAssetWithImportPathAndStatus( generatedCandidateAssetPath, false, false ); outputSources.Add(cachedPrefabAsset); } /* * add current resources to next node's resources. */ outputSources.AddRange(inputSources); outputDict[groupKey] = outputSources; } // delete unused cached prefabs. var unusedCachePaths = alreadyCached.Except(cachedOrGenerated).Where(path => !FileUtility.IsMetaFile(path)).ToList(); foreach (var unusedCachePath in unusedCachePaths) { // unbundlize unused prefabricated cached asset. var assetImporter = AssetImporter.GetAtPath(unusedCachePath); assetImporter.assetBundleName = string.Empty; FileUtility.DeleteFileThenDeleteFolderIfEmpty(unusedCachePath); } Output(nodeId, connectionIdToNextNode, outputDict, usedCache); }
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) { var usedCache = new List <string>(); var outputDict = new Dictionary <string, List <Asset> >(); // caution if import setting file is exists already or not. var samplingDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, nodeId); var sampleAssetPath = string.Empty; ValidateImportSample(samplingDirectoryPath, (string samplePath) => { throw new AssetBundleGraphBuildException(nodeName + ": No ImportSettings Directory found for this node:" + nodeName + " please supply assets to this node."); }, (string samplePath) => { throw new AssetBundleGraphBuildException(nodeName + ": No saved ImportSettings found for asset:" + samplePath); }, (string samplePath) => { sampleAssetPath = samplePath; }, (string samplePath) => { throw new AssetBundleGraphBuildException(nodeName + ": Too many ImportSettings found. please open editor and resolve issue:" + samplePath); } ); if (groupedSources.Keys.Count == 0) { return; } var the1stGroupKey = groupedSources.Keys.ToList()[0]; // 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 <Asset>(); foreach (var groupKey in groupedSources.Keys) { inputSources.AddRange(groupedSources[groupKey]); } var assetImportSettingUpdateMap = new Dictionary <Asset, bool>(); /* * check file & setting. * if need, apply importSetting to file. */ var samplingAssetImporter = AssetImporter.GetAtPath(sampleAssetPath); var effector = new InternalSamplingImportEffector(samplingAssetImporter); foreach (var asset in inputSources) { var importer = AssetImporter.GetAtPath(asset.importFrom); if (samplingAssetImporter.GetType() != importer.GetType()) { throw new NodeException("for each importerSetting should be only treat 1 import setting. current import setting type of this node is:" + samplingAssetImporter.GetType().ToString() + " for file:" + asset.importFrom, nodeId); } assetImportSettingUpdateMap[asset] = false; /* * Apply ImporterSettings' preserved settings, and record if anything changed */ switch (importer.GetType().ToString()) { case "UnityEditor.TextureImporter": { var texImporter = importer as TextureImporter; var same = InternalSamplingImportEffector.IsSameTextureSetting(texImporter, samplingAssetImporter as TextureImporter); if (!same) { effector.ForceOnPreprocessTexture(texImporter); assetImportSettingUpdateMap[asset] = true; } break; } case "UnityEditor.ModelImporter": { var modelImporter = importer as ModelImporter; var same = InternalSamplingImportEffector.IsSameModelSetting(modelImporter, samplingAssetImporter as ModelImporter); if (!same) { effector.ForceOnPreprocessModel(modelImporter); assetImportSettingUpdateMap[asset] = true; } break; } case "UnityEditor.AudioImporter": { var audioImporter = importer as AudioImporter; var same = InternalSamplingImportEffector.IsSameAudioSetting(audioImporter, samplingAssetImporter as AudioImporter); if (!same) { effector.ForceOnPreprocessAudio(audioImporter); assetImportSettingUpdateMap[asset] = true; } break; } default: { throw new NodeException("unhandled importer type:" + importer.GetType().ToString(), nodeId); } } } var outputSources = new List <Asset>(); foreach (var asset in inputSources) { var updated = assetImportSettingUpdateMap[asset]; if (!updated) { // already set completed. outputSources.Add( Asset.CreateNewAssetWithImportPathAndStatus( asset.importFrom, false, // isNew not changed. false ) ); } else { // updated asset. outputSources.Add( Asset.CreateNewAssetWithImportPathAndStatus( asset.importFrom, true, // isNew changed. false ) ); } } outputDict[the1stGroupKey] = outputSources; Output(nodeId, connectionIdToNextNode, outputDict, usedCache); }
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) { var invalids = new List <string>(); foreach (var sources in groupedSources.Values) { foreach (var source in sources) { if (string.IsNullOrEmpty(source.importFrom)) { invalids.Add(source.absoluteAssetPath); } } } if (invalids.Any()) { throw new NodeException(string.Join(", ", invalids.ToArray()) + " are not imported yet. These assets need to be imported before prefabricated.", nodeId); } var recommendedPrefabOutputDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.PREFABRICATOR_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey()); var outputDict = new Dictionary <string, List <Asset> >(); foreach (var groupKey in groupedSources.Keys) { var inputSources = groupedSources[groupKey]; var recommendedPrefabPath = FileUtility.PathCombine(recommendedPrefabOutputDirectoryPath, groupKey); if (!recommendedPrefabPath.EndsWith(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString())) { recommendedPrefabPath = recommendedPrefabPath + AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString(); } /* * ready input resource info for execute. not contains cache in this node. */ var assets = new List <DepreacatedAssetInfo>(); foreach (var assetData in inputSources) { var assetName = assetData.fileNameAndExtension; var assetType = assetData.assetType; var assetPath = assetData.importFrom; var assetDatabaseId = assetData.assetDatabaseId; assets.Add(new DepreacatedAssetInfo(assetName, assetType, assetPath, assetDatabaseId)); } // collect generated prefab path. var generated = new List <string>(); /* * Prefabricate(string prefabName) method. */ Func <string, string> Prefabricate = (string prefabName) => { var newPrefabOutputPath = Path.Combine(recommendedPrefabPath, prefabName); generated.Add(newPrefabOutputPath); isPrefabricateFunctionCalled = true; return(newPrefabOutputPath); }; ValidateCanCreatePrefab(nodeName, nodeId, groupKey, assets, recommendedPrefabPath, Prefabricate); if (!isPrefabricateFunctionCalled) { Debug.LogWarning(nodeName + ": Prefabricate delegate was not called. Prefab might not be created properly."); } foreach (var generatedPrefabPath in generated) { var newAsset = Asset.CreateNewAssetWithImportPathAndStatus( generatedPrefabPath, true, // absolutely new in setup. false ); if (!outputDict.ContainsKey(groupKey)) { outputDict[groupKey] = new List <Asset>(); } outputDict[groupKey].Add(newAsset); } outputDict[groupKey].AddRange(inputSources); } 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>()); }