public static void ValidateModifiyOperationData( string modifierNodeId, string targetPlatform, Action noAssetOperationDataFound, Action validAssetOperationDataFound ) { var platformOpDataPath = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, modifierNodeId, ModifierOperatiorDataName(targetPlatform)); if (File.Exists(platformOpDataPath)) { validAssetOperationDataFound(); return; } // if platform data is not exist, search default one. var defaultPlatformOpDataPath = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, modifierNodeId, ModifierOperatiorDataName(AssetBundleGraphSettings.PLATFORM_DEFAULT_NAME)); if (File.Exists(defaultPlatformOpDataPath)) { validAssetOperationDataFound(); return; } noAssetOperationDataFound(); }
public static string GetPathWithProjectPath(string pathUnderProjectFolder) { var assetPath = Application.dataPath; var projectPath = Directory.GetParent(assetPath).ToString(); return(FileUtility.PathCombine(projectPath, pathUnderProjectFolder)); }
static private PrefabBuildInfo GetPrefabBuildInfo(NodeData node, BuildTarget target, string groupKey) { var prefabCacheDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node); var buildInfoPath = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset"); return(AssetDatabase.LoadAssetAtPath <PrefabBuildInfo>(buildInfoPath)); }
private void DoInspectorImportSettingGUI(NodeGUI node) { EditorGUILayout.HelpBox("ImportSetting: Force apply import settings to given assets.", MessageType.Info); UpdateNodeName(node); GUILayout.Space(10f); if (packageEditMode) { EditorGUI.BeginDisabledGroup(true); } /* * importer node has no platform key. * platform key is contained by Unity's importer inspector itself. */ using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var nodeId = node.nodeId; var samplingPath = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, nodeId); IntegratedGUIImportSetting.ValidateImportSample(samplingPath, (string noFolderFound) => { EditorGUILayout.LabelField("Sampling Asset", "No sample asset found. please Reload first."); }, (string noFilesFound) => { EditorGUILayout.LabelField("Sampling Asset", "No sample asset found. please Reload first."); }, (string samplingAssetPath) => { EditorGUILayout.LabelField("Sampling Asset Path", samplingAssetPath); if (GUILayout.Button("Setup Import Setting")) { var obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(samplingAssetPath); Selection.activeObject = obj; } if (GUILayout.Button("Reset Import Setting")) { // delete all import setting files. FileUtility.RemakeDirectory(samplingPath); node.Save(); } }, (string tooManyFilesFoundMessage) => { if (GUILayout.Button("Reset Import Setting")) { // delete all import setting files. FileUtility.RemakeDirectory(samplingPath); node.Save(); } } ); } if (packageEditMode) { EditorGUI.EndDisabledGroup(); } UpdateDeleteSetting(node); }
public static void DeletePlatformData(string nodeId, string platformStr) { var platformOpdataPath = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, nodeId, ModifierOperatiorDataName(platformStr)); if (File.Exists(platformOpdataPath)) { File.Delete(platformOpdataPath); } }
public void Setup(string nodeName, string nodeId, string unused_connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output) { try { ValidateBundleNameTemplate( bundleNameTemplate, () => { throw new NodeException(nodeName + ":Bundle Name Template is empty.", nodeId); } ); foreach (var name in variants.Values) { ValidateVariantName(name, variants.Values.ToList(), () => { throw new NodeException(nodeName + ":Variant is empty.", nodeId); }, () => { throw new NodeException(nodeName + ":Variant name cannot contain whitespace \"" + name + "\".", nodeId); }, () => { throw new NodeException(nodeName + ":Variant name already exists \"" + name + "\".", nodeId); }); } } catch (NodeException e) { AssetBundleGraphEditorWindow.AddNodeException(e); return; } var recommendedBundleOutputDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLIZER_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey()); var outputDict = new Dictionary <string, List <Asset> >(); foreach (var groupKey in groupedSources.Keys) { var inputSources = groupedSources[groupKey]; var reservedBundlePath = BundlizeAssets(nodeName, groupKey, inputSources, recommendedBundleOutputDir, false); if (string.IsNullOrEmpty(reservedBundlePath)) { continue; } var outputSources = new List <Asset>(); var newAssetData = Asset.CreateAssetWithImportPath(reservedBundlePath); outputSources.Add(newAssetData); outputDict[groupKey] = outputSources; } if (assetsOutputConnectionId != AssetBundleGraphSettings.BUNDLIZER_FAKE_CONNECTION_ID) { Output(nodeId, assetsOutputConnectionId, outputDict, new List <string>()); } }
public void Setup(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 outputDict = new Dictionary <string, List <Asset> >(); outputDict[key] = new List <Asset>(); 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); } } } // add manifest file var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target); bundleNames.Add(manifestName); bundleVariants[manifestName] = new List <string>() { "" }; var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v; Asset bundle = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName)); Asset manifest = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } Output(connectionToOutput, outputDict, new List <string>()); }
static public void SavePrefabBuildInfo(NodeData node, BuildTarget target, string groupKey, List <AssetReference> assets) { var prefabCacheDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node); var buildInfoPath = FileUtility.PathCombine(prefabCacheDir, groupKey + ".asset"); var version = PrefabBuilderUtility.GetPrefabBuilderVersion(node.ScriptClassName); var buildInfo = ScriptableObject.CreateInstance <PrefabBuildInfo>(); buildInfo.Initialize(groupKey, node.ScriptClassName, node.InstanceData[target], version, node.ReplacePrefabOptions, assets); AssetDatabase.CreateAsset(buildInfo, buildInfoPath); }
public static string EnsurePrefabBuilderCacheDirExists(BuildTarget t, NodeData node) { var cacheDir = FileUtility.PathCombine(AssetBundleGraphSettings.PREFABBUILDER_CACHE_PLACE, node.Id, SystemDataUtility.GetPathSafeTargetName(t)); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } if (!cacheDir.EndsWith(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString())) { cacheDir = cacheDir + AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString(); } return(cacheDir); }
public static AssetImporter GetReferenceAssetImporter(NodeData node) { var sampleFileDir = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, node.Id); UnityEngine.Assertions.Assert.IsTrue(Directory.Exists(sampleFileDir)); var sampleFiles = FileUtility.GetFilePathsInFolder(sampleFileDir) .Where(path => !path.EndsWith(AssetBundleGraphSettings.UNITY_METAFILE_EXTENSION)) .ToList(); UnityEngine.Assertions.Assert.IsTrue(sampleFiles.Count == 1); return(AssetImporter.GetAtPath(sampleFiles[0])); }
private static void CreateCUITool() { var appCmd = string.Format("{0}{1}", EditorApplication.applicationPath, (Application.platform == RuntimePlatform.WindowsEditor)? "" : "/Contents/MacOS/Unity"); var argPass = (Application.platform == RuntimePlatform.WindowsEditor)? "%1 %2 %3 %4 %5 %6 %7 %8 %9" : "$*"; var cmd = string.Format(kCommandStr, appCmd, FileUtility.ProjectPathWithSlash(), kCommandMethod, argPass); var ext = (Application.platform == RuntimePlatform.WindowsEditor)? "bat" : "sh"; var cmdFile = string.Format(kCommandName, ext); var destinationPath = FileUtility.PathCombine(AssetBundleGraphSettings.CUISPACE_PATH, cmdFile); Directory.CreateDirectory(AssetBundleGraphSettings.CUISPACE_PATH); File.WriteAllText(destinationPath, cmd); AssetDatabase.Refresh(); }
private void SaveSampleFile(NodeData node, Asset asset) { var samplingDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, node.Id); if (!Directory.Exists(samplingDirectoryPath)) { Directory.CreateDirectory(samplingDirectoryPath); } var absoluteFilePath = asset.absoluteAssetPath; var targetFilePath = FileUtility.PathCombine(samplingDirectoryPath, asset.fileNameAndExtension); FileUtility.CopyFileFromGlobalToLocal(absoluteFilePath, targetFilePath); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); }
public static string EnsureAssetBundleCacheDirExists(BuildTarget t, NodeData node, bool remake = false) { var cacheDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE, node.Id, BuildTargetUtility.TargetToAssetBundlePlatformName(t)); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } else { if (remake) { RemakeDirectory(cacheDir); } } return(cacheDir); }
private void SaveSampleFile(NodeData node, AssetReference asset) { var samplingDirectoryPath = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, node.Id); if (!Directory.Exists(samplingDirectoryPath)) { Directory.CreateDirectory(samplingDirectoryPath); } var configFilePath = FileUtility.GetImportSettingTemplateFilePath(asset); UnityEngine.Assertions.Assert.IsNotNull(configFilePath); var targetFilePath = FileUtility.PathCombine(samplingDirectoryPath, Path.GetFileName(configFilePath)); FileUtility.CopyFile(configFilePath, targetFilePath); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); }
public void Setup(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) { ValidatePrefabBuilder(node, target, inputGroupAssets, () => { throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id); }, () => { throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id); }, (string groupKey) => { throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id); }, (Asset badAsset) => { throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id); } ); var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target); UnityEngine.Assertions.Assert.IsNotNull(builder); var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node); Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >(); foreach (var key in inputGroupAssets.Keys) { var prefabFileName = builder.CanCreatePrefab(key, LoadAllAssets(inputGroupAssets[key])); output[key] = new List <Asset> () { Asset.CreateAssetWithImportPath(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab")) }; } Output(connectionToOutput, output, null); }
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 builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target); UnityEngine.Assertions.Assert.IsNotNull(builder); var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node); Dictionary <string, List <Asset> > output = new Dictionary <string, List <Asset> >(); foreach (var key in inputGroupAssets.Keys) { var allAssets = LoadAllAssets(inputGroupAssets[key]); var prefabFileName = builder.CanCreatePrefab(key, allAssets); UnityEngine.GameObject obj = builder.CreatePrefab(key, allAssets); if (obj == null) { throw new AssetBundleGraphException(string.Format("{0} :PrefabBuilder {1} returned null in CreatePrefab() [groupKey:{2}]", node.Name, builder.GetType().FullName, key)); } var prefabSavePath = FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"); PrefabUtility.CreatePrefab(prefabSavePath, obj, ReplacePrefabOptions.Default); output[key] = new List <Asset> () { Asset.CreateAssetWithImportPath(prefabSavePath) }; GameObject.DestroyImmediate(obj); } Output(connectionToOutput, output, null); }
public void Run(string nodeName, string nodeId, string unused_connectionIdToNextNode, Dictionary <string, List <Asset> > groupedSources, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output) { ValidateBundleNameTemplate( bundleNameTemplate, () => { throw new AssetBundleGraphBuildException(nodeName + ": Bundle Name Template is empty."); } ); var recommendedBundleOutputDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLIZER_CACHE_PLACE, nodeId, SystemDataUtility.GetCurrentPlatformKey()); var outputDict = new Dictionary <string, List <Asset> >(); foreach (var groupKey in groupedSources.Keys) { var inputSources = groupedSources[groupKey]; var reservedBundlePath = BundlizeAssets(nodeName, groupKey, inputSources, recommendedBundleOutputDir, true); if (string.IsNullOrEmpty(reservedBundlePath)) { continue; } var outputSources = new List <Asset>(); var newAssetData = Asset.CreateAssetWithImportPath(reservedBundlePath); outputSources.Add(newAssetData); outputDict[groupKey] = outputSources; } if (assetsOutputConnectionId != AssetBundleGraphSettings.BUNDLIZER_FAKE_CONNECTION_ID) { Output(nodeId, assetsOutputConnectionId, outputDict, new List <string>()); } }
public static ConfigStatus GetConfigStatus(NodeData node) { var sampleFileDir = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, node.Id); if (!Directory.Exists(sampleFileDir)) { return(ConfigStatus.NoSampleFound); } var sampleFiles = FileUtility.GetFilePathsInFolder(sampleFileDir) .Where(path => !path.EndsWith(AssetBundleGraphSettings.UNITY_METAFILE_EXTENSION)) .ToList(); if (sampleFiles.Count == 0) { return(ConfigStatus.NoSampleFound); } if (sampleFiles.Count == 1) { return(ConfigStatus.GoodSampleFound); } return(ConfigStatus.TooManySamplesFound); }
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 Setup(BuildTarget target, NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output Output) { // BundleBuilder do nothing without incoming connections if (incoming == null) { return; } var bundleNames = incoming.SelectMany(v => v.assetGroups.Keys).Distinct().ToList(); var bundleVariants = new Dictionary <string, List <string> >(); // get all variant name for bundles foreach (var ag in incoming) { foreach (var name in ag.assetGroups.Keys) { if (!bundleVariants.ContainsKey(name)) { bundleVariants[name] = new List <string>(); } var assets = ag.assetGroups[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } } // add manifest file var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target); bundleNames.Add(manifestName); bundleVariants[manifestName] = new List <string>() { "" }; if (connectionsToOutput != null && Output != null) { UnityEngine.Assertions.Assert.IsTrue(connectionsToOutput.Any()); var outputDict = new Dictionary <string, List <AssetReference> >(); outputDict[key] = new List <AssetReference>(); var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v; AssetReference bundle = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName)); AssetReference manifest = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, outputDict); } }
public string BundlizeAssets(string nodeName, string groupkey, List <Asset> sources, string recommendedBundleOutputDir, bool isRun) { var invalids = new List <string>(); foreach (var source in sources) { if (string.IsNullOrEmpty(source.importFrom)) { invalids.Add(source.absoluteAssetPath); } } if (invalids.Any()) { throw new AssetBundleGraphBuildException(nodeName + ": Invalid files to bundle. Following files need to be imported before bundlize: " + string.Join(", ", invalids.ToArray())); } var bundleName = bundleNameTemplate; /* * if contains KEYWORD_WILDCARD, use group identifier to bundlize name. */ if (bundleNameTemplate.Contains(AssetBundleGraphSettings.KEYWORD_WILDCARD)) { var templateHead = bundleNameTemplate.Split(AssetBundleGraphSettings.KEYWORD_WILDCARD)[0]; var templateTail = bundleNameTemplate.Split(AssetBundleGraphSettings.KEYWORD_WILDCARD)[1]; bundleName = (templateHead + groupkey + templateTail + "." + SystemDataUtility.GetCurrentPlatformShortName()).ToLower(); } var bundlePath = FileUtility.PathCombine(recommendedBundleOutputDir, bundleName); for (var i = 0; i < sources.Count; i++) { var source = sources[i]; // if already bundled in this running, avoid changing that name. if (source.isBundled) { continue; } if (isRun) { if (FileUtility.IsMetaFile(source.importFrom)) { continue; } var assetImporter = AssetImporter.GetAtPath(source.importFrom); if (assetImporter == null) { continue; } assetImporter.assetBundleName = bundleName; } // set as this resource is already bundled. sources[i] = Asset.DuplicateAssetWithNewStatus(sources[i], sources[i].isNew, true); } return(bundlePath); }
private void Export(BuildTarget target, NodeData node, ConnectionPointData inputPoint, ConnectionData connectionToOutput, Dictionary <string, List <Asset> > inputGroupAssets, Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output, bool isRun) { var outputDict = new Dictionary <string, List <Asset> >(); outputDict["0"] = new List <Asset>(); var failedExports = new List <string>(); foreach (var groupKey in inputGroupAssets.Keys) { var exportedAssets = new List <Asset>(); var inputSources = inputGroupAssets[groupKey]; foreach (var source in inputSources) { if (isRun) { if (!Directory.Exists(node.ExporterExportPath[target])) { Directory.CreateDirectory(node.ExporterExportPath[target]); } } var destinationSourcePath = source.importFrom; // in bundleBulider, use platform-package folder for export destination. if (destinationSourcePath.StartsWith(AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE)) { var depth = AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE.Split(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR).Length + 1; var splitted = destinationSourcePath.Split(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR); var reducedArray = new string[splitted.Length - depth]; Array.Copy(splitted, depth, reducedArray, 0, reducedArray.Length); var fromDepthToEnd = string.Join(AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR.ToString(), reducedArray); destinationSourcePath = fromDepthToEnd; } var destination = FileUtility.PathCombine(node.ExporterExportPath[target], destinationSourcePath); var parentDir = Directory.GetParent(destination).ToString(); if (isRun) { if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } if (File.Exists(destination)) { File.Delete(destination); } if (string.IsNullOrEmpty(source.importFrom)) { failedExports.Add(source.absoluteAssetPath); continue; } try { File.Copy(source.importFrom, destination); } catch (Exception e) { failedExports.Add(source.importFrom); Debug.LogError(node.Name + ": Error occured: " + e.Message); } } var exportedAsset = Asset.CreateAssetWithExportPath(destination); exportedAssets.Add(exportedAsset); } outputDict["0"].AddRange(exportedAssets); } if (failedExports.Any()) { Debug.LogError(node.Name + ": Failed to export files. All files must be imported before exporting: " + string.Join(", ", failedExports.ToArray())); } Output(connectionToOutput, outputDict, null); }
public static string GetPathWithAssetsPath(string pathUnderAssetsFolder) { var assetPath = Application.dataPath; return(FileUtility.PathCombine(assetPath, pathUnderAssetsFolder)); }
public static void ResetConfig(NodeData node) { var sampleFileDir = FileUtility.PathCombine(AssetBundleGraphSettings.IMPORTER_SETTINGS_PLACE, node.Id); FileUtility.RemakeDirectory(sampleFileDir); }
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>()); }
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 string GetLoaderFullLoadPath(BuildTarget g) { return(FileUtility.PathCombine(Application.dataPath, LoaderLoadPath[g])); }
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) { // reserve importSetting type for limit asset. var importSettingSampleType = string.Empty; var outputDict = new Dictionary <string, List <Asset> >(); 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 <Asset>(); foreach (var groupKey in groupedSources.Keys) { inputSources.AddRange(groupedSources[groupKey]); } var importedAssets = new List <Asset>(); var samplingDirectoryPath = FileUtility.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 asset in inputSources) { if (string.IsNullOrEmpty(asset.absoluteAssetPath)) { if (!string.IsNullOrEmpty(asset.importFrom)) { alreadyImported.Add(asset.importFrom); continue; } ignoredResource.Add(asset.fileNameAndExtension); continue; } var assetType = AssetImporter.GetAtPath(asset.importFrom).GetType(); var importerTypeStr = assetType.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 = Asset.DuplicateAssetWithNewType(asset, assetType); importedAssets.Add(newData); if (first) { if (!Directory.Exists(samplingDirectoryPath)) { Directory.CreateDirectory(samplingDirectoryPath); } var absoluteFilePath = asset.absoluteAssetPath; var targetFilePath = FileUtility.PathCombine(samplingDirectoryPath, asset.fileNameAndExtension); EditorUtility.DisplayProgressBar("AssetBundleGraph ImportSetting generating ImporterSetting...", targetFilePath, 0); FileUtility.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]] = importedAssets; } Output(nodeId, connectionIdToNextNode, outputDict, new List <string>()); }
private void DoInspectorModifierGUI(NodeGUI node) { EditorGUILayout.HelpBox("Modifier: Force apply asset settings to given assets.", MessageType.Info); UpdateNodeName(node); GUILayout.Space(10f); var currentModifierTargetType = IntegratedGUIModifier.ModifierOperationTargetTypeName(node.nodeId); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { // show incoming type of Assets and reset interface. { var isOperationDataExist = false; IntegratedGUIModifier.ValidateModifiyOperationData( node.nodeId, node.currentPlatform, () => { GUILayout.Label("No modifier data found, please Reload first."); }, () => { isOperationDataExist = true; } ); if (!isOperationDataExist) { return; } using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("Target Type:"); GUILayout.Label(currentModifierTargetType); } /* * reset whole platform's data for this modifier. */ if (GUILayout.Button("Reset Modifier")) { var modifierFolderPath = FileUtility.PathCombine(AssetBundleGraphSettings.MODIFIER_OPERATOR_DATAS_PLACE, node.nodeId); FileUtility.RemakeDirectory(modifierFolderPath); node.Save(); modifierOperatorInstance = null; return; } } GUILayout.Space(10f); var usingScriptMode = !string.IsNullOrEmpty(node.scriptClassName); // use modifier script manually. { GUIStyle s = new GUIStyle("TextFieldDropDownText"); /* * check prefabricator script-type string. */ if (string.IsNullOrEmpty(node.scriptClassName)) { s.fontStyle = FontStyle.Bold; s.fontSize = 12; } else { var loadedType = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(node.scriptClassName); if (loadedType == null) { s.fontStyle = FontStyle.Bold; s.fontSize = 12; } } var before = !string.IsNullOrEmpty(node.scriptClassName); usingScriptMode = EditorGUILayout.ToggleLeft("Use ModifierOperator Script", !string.IsNullOrEmpty(node.scriptClassName)); // detect mode changed. if (before != usingScriptMode) { // checked. initialize value of scriptClassName. if (usingScriptMode) { node.BeforeSave(); node.scriptClassName = "MyModifier"; node.Save(); } // unchecked. if (!usingScriptMode) { node.BeforeSave(); node.scriptClassName = string.Empty; node.Save(); } } if (!usingScriptMode) { EditorGUI.BeginDisabledGroup(true); } GUILayout.Label("ここをドロップダウンにする。2"); var newScriptClass = EditorGUILayout.TextField("Classname", node.scriptClassName, s); if (newScriptClass != node.scriptClassName) { node.BeforeSave(); node.scriptClassName = newScriptClass; node.Save(); } if (!usingScriptMode) { EditorGUI.EndDisabledGroup(); } } GUILayout.Space(10f); if (usingScriptMode) { EditorGUI.BeginDisabledGroup(true); } // show for each platform tab. var currentPlatform = node.currentPlatform; node.currentPlatform = UpdateCurrentPlatform(node.currentPlatform); /* * if platform tab is changed, renew modifierOperatorInstance for that tab. */ if (currentPlatform != node.currentPlatform) { modifierOperatorInstance = null; } /* * reload modifierOperator instance from saved modifierOperator data. */ if (modifierOperatorInstance == null) { var modifierOperatorDataPath = IntegratedGUIModifier.ModifierDataPathForeachPlatform(node.nodeId, node.currentPlatform); // choose default modifierOperatorData if platform specified file is not exist. if (!File.Exists(modifierOperatorDataPath)) { modifierOperatorDataPath = IntegratedGUIModifier.ModifierDataPathForDefaultPlatform(node.nodeId); } var loadedModifierOperatorDataStr = string.Empty; using (var sr = new StreamReader(modifierOperatorDataPath)) { loadedModifierOperatorDataStr = sr.ReadToEnd(); } var modifierOperatorType = TypeUtility.SupportedModifierOperatorDefinition[currentModifierTargetType]; /* * create instance from saved modifierOperator data. */ modifierOperatorInstance = typeof(NodeGUIEditor) .GetMethod("FromJson") .MakeGenericMethod(modifierOperatorType) // set desired generic type here. .Invoke(this, new object[] { loadedModifierOperatorDataStr }) as ModifierOperators.OperatorBase; } /* * Show ModifierOperator Inspector. */ if (modifierOperatorInstance != null) { Action changed = () => { var data = JsonUtility.ToJson(modifierOperatorInstance); var prettified = AssetBundleGraphEditorWindow.PrettifyJson(data); var modifierOperatorDataPath = IntegratedGUIModifier.ModifierDataPathForeachPlatform(node.nodeId, node.currentPlatform); using (var sw = new StreamWriter(modifierOperatorDataPath)) { sw.Write(prettified); } // reflect change of data. AssetDatabase.Refresh(); modifierOperatorInstance = null; }; GUILayout.Space(10f); modifierOperatorInstance.DrawInspector(changed); } var deleted = UpdateDeleteSetting(node); if (deleted) { // source platform depended data is deleted. reload instance for reloading instance from data. modifierOperatorInstance = null; } if (usingScriptMode) { EditorGUI.EndDisabledGroup(); } } }
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); }