/// <summary> /// 导出需要修改的文件,文件存放路径在CacheFileRootPath下 /// </summary> private static void CopyToModificationFile(string root) { Stopwatch sw = Stopwatch.StartNew(); var modificationBundlesPath = root + "/OriginalBundles"; var modificationI18NDataPath = root + "/I18NData"; if (Directory.Exists(modificationBundlesPath)) { FileUtil.DeleteFileOrDirectory(modificationBundlesPath); // Directory.Delete(modificationBundlesPath); } if (Directory.Exists(modificationI18NDataPath)) { FileUtil.DeleteFileOrDirectory(modificationI18NDataPath); } Debug.Log("<color='#00ff66'>----修改的文件----</color>" + _modificationFiles.Count); if (_modificationFiles.Count > 0) { foreach (var file in _modificationFiles) { string sourceFile = file.FullName; string destFile = root + "/" + FileNameSplit(file.FullName); FileInfo fileInfo = new FileInfo(destFile); if (fileInfo.Directory.Exists == false) { fileInfo.Directory.Create(); } File.Copy(sourceFile, destFile, true); } } sw.Stop(); long time = sw.ElapsedMilliseconds; Debug.Log("<color='#00ff66'> ====== Copy耗时:" + time + "ms</color>"); }
internal static void ExtractSelectedObjectsFromPrefab() { var assetsToReload = new HashSet <string>(); string folder = null; foreach (var selectedObj in Selection.objects) { var path = AssetDatabase.GetAssetPath(selectedObj); // use the first selected element as the basis for the folder path where all the materials will be extracted if (folder == null) { folder = EditorUtility.SaveFolderPanel("Select Materials Folder", FileUtil.DeleteLastPathNameComponent(path), ""); if (string.IsNullOrEmpty(folder)) { // cancel the extraction if the user did not select a folder return; } folder = FileUtil.GetProjectRelativePath(folder); } // TODO: [bogdanc 3/6/2017] if we want this function really generic, we need to know what extension the new asset files should have var extension = selectedObj is Material ? kMaterialExtension : string.Empty; var newAssetPath = FileUtil.CombinePaths(folder, selectedObj.name) + extension; newAssetPath = AssetDatabase.GenerateUniqueAssetPath(newAssetPath); var error = AssetDatabase.ExtractAsset(selectedObj, newAssetPath); if (string.IsNullOrEmpty(error)) { assetsToReload.Add(path); } } foreach (var path in assetsToReload) { AssetDatabase.WriteImportSettingsIfDirty(path); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); } }
public static void MonoLink(BuildTarget buildTarget, string managedLibrariesDirectory, string[] input, string[] allAssemblies, RuntimeClassRegistry usedClasses) { Process process = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory); string buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget); string text = null; string frameWorksFolder = MonoInstallationFinder.GetFrameWorksFolder(); string text2 = Path.Combine(frameWorksFolder, MonoAssemblyStripping.StripperExe()); string text3 = Path.Combine(Path.GetDirectoryName(text2), "link.xml"); string text4 = Path.Combine(managedLibrariesDirectory, "output"); Directory.CreateDirectory(text4); process.StartInfo.Arguments = "\"" + text2 + "\" -l none -c link"; for (int i = 0; i < input.Length; i++) { string str = input[i]; ProcessStartInfo expr_82 = process.StartInfo; expr_82.Arguments = expr_82.Arguments + " -a \"" + str + "\""; } ProcessStartInfo expr_B5 = process.StartInfo; string arguments = expr_B5.Arguments; expr_B5.Arguments = string.Concat(new string[] { arguments, " -out output -x \"", text3, "\" -d \"", managedLibrariesDirectory, "\"" }); string text5 = Path.Combine(buildToolsDirectory, "link.xml"); if (File.Exists(text5)) { ProcessStartInfo expr_112 = process.StartInfo; expr_112.Arguments = expr_112.Arguments + " -x \"" + text5 + "\""; } string text6 = Path.Combine(Path.GetDirectoryName(text2), "Core.xml"); if (File.Exists(text6)) { ProcessStartInfo expr_153 = process.StartInfo; expr_153.Arguments = expr_153.Arguments + " -x \"" + text6 + "\""; } string[] files = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "link.xml", SearchOption.AllDirectories); string[] array = files; for (int j = 0; j < array.Length; j++) { string str2 = array[j]; ProcessStartInfo expr_1A5 = process.StartInfo; expr_1A5.Arguments = expr_1A5.Arguments + " -x \"" + str2 + "\""; } if (usedClasses != null) { text = MonoAssemblyStripping.GenerateBlackList(managedLibrariesDirectory, usedClasses, allAssemblies); ProcessStartInfo expr_1EA = process.StartInfo; expr_1EA.Arguments = expr_1EA.Arguments + " -x \"" + text + "\""; } string path = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(EditorUserBuildSettings.activeBuildTarget, BuildOptions.None), "Whitelists"); string[] files2 = Directory.GetFiles(path, "*.xml"); for (int k = 0; k < files2.Length; k++) { string str3 = files2[k]; ProcessStartInfo expr_241 = process.StartInfo; expr_241.Arguments = expr_241.Arguments + " -x \"" + str3 + "\""; } MonoProcessUtility.RunMonoProcess(process, "assemblies stripper", Path.Combine(text4, "mscorlib.dll")); MonoAssemblyStripping.DeleteAllDllsFrom(managedLibrariesDirectory); MonoAssemblyStripping.CopyAllDlls(managedLibrariesDirectory, text4); string[] files3 = Directory.GetFiles(managedLibrariesDirectory); for (int l = 0; l < files3.Length; l++) { string text7 = files3[l]; if (text7.Contains(".mdb")) { string path2 = text7.Replace(".mdb", ""); if (!File.Exists(path2)) { FileUtil.DeleteFileOrDirectory(text7); } } } if (text != null) { FileUtil.DeleteFileOrDirectory(Path.Combine(managedLibrariesDirectory, text)); } FileUtil.DeleteFileOrDirectory(text4); }
// shared by compute shader inspector too internal static void ShaderErrorListUI(Object shader, ShaderMessage[] messages, ref Vector2 scrollPosition) { int n = messages.Length; GUILayout.Space(kSpace); GUILayout.Label(string.Format("Errors ({0}):", n), EditorStyles.boldLabel); int errorListID = GUIUtility.GetControlID(kErrorViewHash, FocusType.Passive); float height = Mathf.Min(n * 20f + 40f, 150f); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkin.current.box, GUILayout.MinHeight(height)); EditorGUIUtility.SetIconSize(new Vector2(16.0f, 16.0f)); float lineHeight = Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent(Styles.errorIcon), 100); Event e = Event.current; for (int i = 0; i < n; ++i) { Rect r = EditorGUILayout.GetControlRect(false, lineHeight); string err = messages[i].message; string plat = messages[i].platform.ToString(); bool warn = messages[i].severity != ShaderCompilerMessageSeverity.Error; string fileName = FileUtil.GetLastPathNameComponent(messages[i].file); int line = messages[i].line; // Double click opens shader file at error line if (e.type == EventType.MouseDown && e.button == 0 && r.Contains(e.mousePosition)) { GUIUtility.keyboardControl = errorListID; if (e.clickCount == 2) { string filePath = messages[i].file; Object asset = string.IsNullOrEmpty(filePath) ? null : AssetDatabase.LoadMainAssetAtPath(filePath); // if we don't have an asset and the filePath is an absolute path, it's an error in a system // cginc - open that instead if (asset == null && System.IO.Path.IsPathRooted(filePath)) { ShaderUtil.OpenSystemShaderIncludeError(filePath, line); } else { AssetDatabase.OpenAsset(asset ?? shader, line); } GUIUtility.ExitGUI(); } e.Use(); } // Context menu, "Copy" if (e.type == EventType.ContextClick && r.Contains(e.mousePosition)) { e.Use(); var menu = new GenericMenu(); // need to copy current value to be used in delegate // (C# closures close over variables, not their values) var errorIndex = i; menu.AddItem(EditorGUIUtility.TrTextContent("Copy error text"), false, delegate { string errMsg = messages[errorIndex].message; if (!string.IsNullOrEmpty(messages[errorIndex].messageDetails)) { errMsg += '\n'; errMsg += messages[errorIndex].messageDetails; } EditorGUIUtility.systemCopyBuffer = errMsg; }); menu.ShowAsContext(); } // background if (e.type == EventType.Repaint) { if ((i & 1) == 0) { GUIStyle st = Styles.evenBackground; st.Draw(r, false, false, false, false); } } // error location on the right side Rect locRect = r; locRect.xMin = locRect.xMax; if (line > 0) { GUIContent gc; if (string.IsNullOrEmpty(fileName)) { gc = EditorGUIUtility.TempContent(line.ToString(CultureInfo.InvariantCulture)); } else { gc = EditorGUIUtility.TempContent(fileName + ":" + line.ToString(CultureInfo.InvariantCulture)); } // calculate size so we can right-align it Vector2 size = EditorStyles.miniLabel.CalcSize(gc); locRect.xMin -= size.x; GUI.Label(locRect, gc, EditorStyles.miniLabel); locRect.xMin -= 2; // ensure some minimum width so that platform field next will line up if (locRect.width < 30) { locRect.xMin = locRect.xMax - 30; } } // platform to the left of it Rect platRect = locRect; platRect.width = 0; if (plat.Length > 0) { GUIContent gc = EditorGUIUtility.TempContent(plat); // calculate size so we can right-align it Vector2 size = EditorStyles.miniLabel.CalcSize(gc); platRect.xMin -= size.x; // draw platform in dimmer color; it's often not very important information Color oldColor = GUI.contentColor; GUI.contentColor = new Color(1, 1, 1, 0.5f); GUI.Label(platRect, gc, EditorStyles.miniLabel); GUI.contentColor = oldColor; platRect.xMin -= 2; } // error message Rect msgRect = r; msgRect.xMax = platRect.xMin; GUI.Label(msgRect, EditorGUIUtility.TempContent(err, warn ? Styles.warningIcon : Styles.errorIcon), Styles.messageStyle); } EditorGUIUtility.SetIconSize(Vector2.zero); GUILayout.EndScrollView(); }
public void OnEnable() { this.m_AnimationType = base.serializedObject.FindProperty("m_AnimationType"); this.m_AvatarSource = base.serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource"); this.m_OptimizeGameObjects = base.serializedObject.FindProperty("m_OptimizeGameObjects"); this.m_RootMotionBoneName = base.serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName"); this.m_ExposeTransformEditor = new ExposeTransformEditor(); string[] transformPaths = this.singleImporter.transformPaths; this.m_RootMotionBoneList = new GUIContent[transformPaths.Length]; for (int i = 0; i < transformPaths.Length; i++) { this.m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]); } if (this.m_RootMotionBoneList.Length > 0) { this.m_RootMotionBoneList[0] = new GUIContent("None"); } this.rootIndex = ArrayUtility.FindIndex <GUIContent>(this.m_RootMotionBoneList, (GUIContent content) => FileUtil.GetLastPathNameComponent(content.text) == this.m_RootMotionBoneName.stringValue); this.rootIndex = ((this.rootIndex >= 1) ? this.rootIndex : 0); this.m_CopyAvatar = base.serializedObject.FindProperty("m_CopyAvatar"); this.m_LegacyGenerateAnimations = base.serializedObject.FindProperty("m_LegacyGenerateAnimations"); this.m_AnimationCompression = base.serializedObject.FindProperty("m_AnimationCompression"); this.m_ExposeTransformEditor.OnEnable(this.singleImporter.transformPaths, base.serializedObject); this.m_CanMultiEditTransformList = this.CanMultiEditTransformList(); this.CheckIfAvatarCopyIsUpToDate(); this.m_IsBiped = false; this.m_BipedMappingReport = new List <string>(); if (this.m_AnimationType.intValue == 3) { GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(this.singleImporter.assetPath) as GameObject; this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, this.m_BipedMappingReport); } }
static bool PickBuildLocation(BuildTargetGroup targetGroup, BuildTarget target, BuildOptions options, out bool updateExistingBuild) { updateExistingBuild = false; var previousPath = EditorUserBuildSettings.GetBuildLocation(target); string defaultFolder; string defaultName; if (previousPath == String.Empty) { defaultFolder = FileUtil.DeleteLastPathNameComponent(Application.dataPath); defaultName = ""; } else { defaultFolder = FileUtil.DeleteLastPathNameComponent(previousPath); defaultName = FileUtil.GetLastPathNameComponent(previousPath); } string extension = PostprocessBuildPlayer.GetExtensionForBuildTarget(targetGroup, target, options); // Invalidate default name, if extension mismatches the default file (for ex., when switching between folder type export to file type export, see Android) if (extension != Path.GetExtension(defaultName).Replace(".", "")) { defaultName = string.Empty; } // Hack: For Windows Standalone, we want the BuildPanel to choose a folder, // but we don't want BuildPlayer to take a folder path because historically it took an .exe path // and we would be breaking tons of projects! bool isWindowsStandalone = target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64; string realExtension = extension; if (isWindowsStandalone) { extension = string.Empty; // Remove the filename.exe part from the path if (!string.IsNullOrEmpty(defaultName)) { defaultName = Path.GetDirectoryName(defaultName); } } string title = "Build " + BuildPlatforms.instance.GetBuildTargetDisplayName(targetGroup, target); string path = EditorUtility.SaveBuildPanel(target, title, defaultFolder, defaultName, extension, out updateExistingBuild); if (path == string.Empty) { return(false); } if (isWindowsStandalone) { extension = realExtension; path = Path.Combine(path, PlayerSettings.productName + '.' + extension); } if (!IsBuildPathValid(path)) { return(false); } // Enforce extension if needed if (extension != string.Empty && FileUtil.GetPathExtension(path).ToLower() != extension) { path += '.' + extension; } // A path may not be empty initially, but it could contain, e.g., a drive letter (as in Windows), // so even appending an extention will work fine, but in reality the name will be, for example, // G:/ //Debug.Log(path); string currentlyChosenName = FileUtil.GetLastPathNameComponent(path); if (currentlyChosenName == string.Empty) { return(false); // No nameless projects, please } // We don't want to re-create a directory that already exists, this may // result in access-denials that will make users unhappy. string check_dir = extension != string.Empty ? FileUtil.DeleteLastPathNameComponent(path) : path; if (!Directory.Exists(check_dir)) { Directory.CreateDirectory(check_dir); } // On OSX we've got replace/update dialog, for other platforms warn about deleting // files in target folder. if ((target == BuildTarget.iOS) && (Application.platform != RuntimePlatform.OSXEditor)) { if (!FolderIsEmpty(path) && !UserWantsToDeleteFiles(path)) { return(false); } } EditorUserBuildSettings.SetBuildLocation(target, path); return(true); }
static void CacheServerVersion1GUI(bool allowCacheServerChanges, string overrideAddress) { GUILayout.Label(Properties.assetPipelineVersion1, EditorStyles.boldLabel); GUILayout.Space(5); if (!allowCacheServerChanges) { EditorGUILayout.HelpBox("Cache Server preferences cannot be modified because a remote address was specified via command line argument. To modify Cache Server preferences, restart Unity without the " + kIpAddressKeyArgs + " command line argument.", MessageType.Info, true); } using (new EditorGUI.DisabledScope(!allowCacheServerChanges)) { var displayMode = !allowCacheServerChanges ? CacheServerMode.Remote : s_CacheServerMode; s_CacheServerMode = (CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", displayMode); } if (s_CacheServerMode == CacheServerMode.Remote) { using (new EditorGUI.DisabledScope(!allowCacheServerChanges)) { var displayAddress = overrideAddress != null ? overrideAddress : s_CacheServerIPAddress; s_CacheServerIPAddress = EditorGUILayout.TextField("IP Address", displayAddress); if (GUI.changed) { s_ConnectionState = ConnectionState.Unknown; } } GUILayout.Space(5); using (new EditorGUI.DisabledScope(AssetDatabase.IsV2Enabled())) { if (GUILayout.Button("Check Connection", GUILayout.Width(150))) { if (InternalEditorUtility.CanConnectToCacheServer()) { s_ConnectionState = ConnectionState.Success; } else { s_ConnectionState = ConnectionState.Failure; } } } GUILayout.Space(-25); var s = AssetDatabase.IsV1Enabled() ? s_ConnectionState : ConnectionState.Unknown; switch (s) { case ConnectionState.Success: EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false); break; case ConnectionState.Failure: EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false); break; case ConnectionState.Unknown: GUILayout.Space(44); break; } } else if (s_CacheServerMode == CacheServerMode.Local) { const int kMinSizeInGigabytes = 1; const int kMaxSizeInGigabytes = 200; // Write size in GigaBytes. s_LocalCacheServerSize = EditorGUILayout.IntSlider(Properties.maxCacheSize, s_LocalCacheServerSize, kMinSizeInGigabytes, kMaxSizeInGigabytes); s_EnableCustomPath = EditorGUILayout.Toggle(Properties.customCacheLocation, s_EnableCustomPath); // browse for cache folder if not per project if (s_EnableCustomPath) { GUIStyle style = EditorStyles.miniButton; GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(Properties.cacheFolderLocation, style); Rect r = GUILayoutUtility.GetRect(GUIContent.none, style); GUIContent guiText = string.IsNullOrEmpty(s_CachePath) ? Properties.browse : new GUIContent(s_CachePath); if (EditorGUI.DropdownButton(r, guiText, FocusType.Passive, style)) { string pathToOpen = s_CachePath; string path = EditorUtility.OpenFolderPanel(Properties.browseCacheLocation.text, pathToOpen, ""); if (!string.IsNullOrEmpty(path)) { if (LocalCacheServer.CheckValidCacheLocation(path)) { s_CachePath = path; WritePreferences(); } else { EditorUtility.DisplayDialog("Invalid Cache Location", string.Format("The directory {0} contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", path), "OK"); } EditorGUIUtility.ExitGUI(); } } GUILayout.EndHorizontal(); } else { s_CachePath = ""; } bool locationExists = LocalCacheServer.CheckCacheLocationExists(); if (locationExists == true) { GUIContent cacheSizeIs = EditorGUIUtility.TrTextContent("Cache size is unknown"); if (s_LocalCacheServerUsedSize != -1) { cacheSizeIs = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(s_LocalCacheServerUsedSize)); } GUILayout.BeginHorizontal(); GUIStyle style = EditorStyles.miniButton; EditorGUILayout.PrefixLabel(cacheSizeIs, style); Rect r = GUILayoutUtility.GetRect(GUIContent.none, style); if (EditorGUI.Button(r, Properties.enumerateCache, style)) { s_LocalCacheServerUsedSize = LocalCacheServer.CheckCacheLocationExists() ? FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation()) : 0; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUIContent spacerContent = EditorGUIUtility.blankContent; EditorGUILayout.PrefixLabel(spacerContent, style); Rect r2 = GUILayoutUtility.GetRect(GUIContent.none, style); if (EditorGUI.Button(r2, Properties.cleanCache, style)) { LocalCacheServer.Clear(); s_LocalCacheServerUsedSize = 0; } GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false); //If the cache server was on an external HDD or on a temporarily unavailable network drive, set the size to unknown so that the user re-queries it when they've reconnected s_LocalCacheServerUsedSize = -1; } GUILayout.Label(Properties.cacheFolderLocation.text + ":"); GUILayout.Label(LocalCacheServer.GetCacheLocation(), Styles.cacheFolderLocation); } }
public static void OnGUI() { EventType type = Event.current.type; if (s_Constants == null) { s_Constants = new Constants(); } GUILayout.Space(10f); if (!InternalEditorUtility.HasTeamLicense()) { GUILayout.Label(EditorGUIUtility.TempContent("You need to have a Pro or Team license to use the cache server.", EditorGUIUtility.GetHelpIcon(MessageType.Warning)), EditorStyles.helpBox, new GUILayoutOption[0]); } using (new EditorGUI.DisabledScope(!InternalEditorUtility.HasTeamLicense())) { if (!s_PrefsLoaded) { ReadPreferences(); if ((s_CacheServerMode != CacheServerMode.Disabled) && (s_ConnectionState == ConnectionState.Unknown)) { if (InternalEditorUtility.CanConnectToCacheServer()) { s_ConnectionState = ConnectionState.Success; } else { s_ConnectionState = ConnectionState.Failure; } } s_PrefsLoaded = true; } EditorGUI.BeginChangeCheck(); if (Collab.instance.collabInfo.whitelisted && IsCollabCacheEnabled()) { s_CollabCacheEnabled = EditorGUILayout.Toggle("Use Collab Cache", s_CollabCacheEnabled, new GUILayoutOption[0]); using (new EditorGUI.DisabledScope(!s_CollabCacheEnabled)) { s_CollabCacheIPAddress = EditorGUILayout.TextField("Collab Cache IP Address", s_CollabCacheIPAddress, new GUILayoutOption[0]); } } s_CacheServerMode = (CacheServerMode)EditorGUILayout.EnumPopup("Cache Server Mode", s_CacheServerMode, new GUILayoutOption[0]); if (s_CacheServerMode != CacheServerMode.Remote) { goto Label_0238; } s_CacheServerIPAddress = EditorGUILayout.DelayedTextField("IP Address", s_CacheServerIPAddress, new GUILayoutOption[0]); if (GUI.changed) { s_ConnectionState = ConnectionState.Unknown; } GUILayout.Space(5f); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(150f) }; if (GUILayout.Button("Check Connection", options)) { if (InternalEditorUtility.CanConnectToCacheServer()) { s_ConnectionState = ConnectionState.Success; } else { s_ConnectionState = ConnectionState.Failure; } } GUILayout.Space(-25f); ConnectionState state = s_ConnectionState; if (state != ConnectionState.Success) { if (state == ConnectionState.Failure) { goto Label_0212; } if (state == ConnectionState.Unknown) { goto Label_0223; } } else { EditorGUILayout.HelpBox("Connection successful.", MessageType.Info, false); } goto Label_04B9; Label_0212: EditorGUILayout.HelpBox("Connection failed.", MessageType.Warning, false); goto Label_04B9; Label_0223: GUILayout.Space(44f); goto Label_04B9; Label_0238: if (s_CacheServerMode == CacheServerMode.Local) { s_LocalCacheServerSize = EditorGUILayout.IntSlider(Styles.maxCacheSize, s_LocalCacheServerSize, 1, 200, new GUILayoutOption[0]); s_EnableCustomPath = EditorGUILayout.Toggle(Styles.customCacheLocation, s_EnableCustomPath, new GUILayoutOption[0]); if (s_EnableCustomPath) { GUIStyle popup = EditorStyles.popup; GUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PrefixLabel(Styles.cacheFolderLocation, popup); Rect position = GUILayoutUtility.GetRect(GUIContent.none, popup); GUIContent content = !string.IsNullOrEmpty(s_CachePath) ? new GUIContent(s_CachePath) : Styles.browse; if (EditorGUI.ButtonMouseDown(position, content, FocusType.Passive, popup)) { string folder = s_CachePath; string str2 = EditorUtility.OpenFolderPanel(Styles.browseCacheLocation.text, folder, ""); if (!string.IsNullOrEmpty(str2)) { if (LocalCacheServer.CheckValidCacheLocation(str2)) { s_CachePath = str2; WritePreferences(); } else { EditorUtility.DisplayDialog("Invalid Cache Location", "The directory " + str2 + " contains some files which don't look like Unity Cache server files. Please delete the directory contents or choose another directory.", "OK"); } } } GUILayout.EndHorizontal(); } else { s_CachePath = ""; } if (LocalCacheServer.CheckCacheLocationExists()) { GUIContent label = EditorGUIUtility.TextContent("Cache size is unknown"); if (s_LocalCacheServerUsedSize != -1L) { label = EditorGUIUtility.TextContent("Cache size is " + EditorUtility.FormatBytes(s_LocalCacheServerUsedSize)); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIStyle miniButton = EditorStyles.miniButton; EditorGUILayout.PrefixLabel(label, miniButton); if (EditorGUI.Button(GUILayoutUtility.GetRect(GUIContent.none, miniButton), Styles.enumerateCache, miniButton)) { s_LocalCacheServerUsedSize = !LocalCacheServer.CheckCacheLocationExists() ? 0L : FileUtil.GetDirectorySize(LocalCacheServer.GetCacheLocation()); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PrefixLabel(EditorGUIUtility.blankContent, miniButton); if (EditorGUI.Button(GUILayoutUtility.GetRect(GUIContent.none, miniButton), Styles.cleanCache, miniButton)) { LocalCacheServer.Clear(); s_LocalCacheServerUsedSize = 0L; } GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("Local cache directory does not exist - please check that you can access the cache folder and are able to write to it", MessageType.Warning, false); s_LocalCacheServerUsedSize = -1L; } GUILayout.Label(Styles.cacheFolderLocation.text + ":", new GUILayoutOption[0]); GUILayout.Label(LocalCacheServer.GetCacheLocation(), s_Constants.cacheFolderLocation, new GUILayoutOption[0]); } Label_04B9: if (EditorGUI.EndChangeCheck()) { s_HasPendingChanges = true; } if (s_HasPendingChanges && (GUIUtility.hotControl == 0)) { s_HasPendingChanges = false; WritePreferences(); ReadPreferences(); } } }
private static void HandleExternalDrag(string[] paths, bool perform, ref List <Sprite> result) { foreach (var path in paths) { if (!ValidPathForTextureAsset(path)) { continue; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (!perform) { continue; } var newPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(path))); if (newPath.Length <= 0) { continue; } FileUtil.CopyFileOrDirectory(path, newPath); ForcedImportFor(newPath); Sprite defaultSprite = GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(newPath) as UnityTexture2D); if (defaultSprite != null) { result.Add(defaultSprite); } } }
private void ExtractTexturesGUI() { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(Styles.Textures); using ( new EditorGUI.DisabledScope(!m_HasEmbeddedTextures.boolValue && !m_HasEmbeddedTextures.hasMultipleDifferentValues)) { if (GUILayout.Button(Styles.ExtractEmbeddedTextures)) { // when extracting textures, we must handle the case when multiple selected assets could generate textures with the same name at the user supplied path // we proceed as follows: // 1. each asset extracts the textures in a separate temp folder // 2. we remap the extracted assets to the respective asset importer // 3. we generate unique names for each asset and move them to the user supplied path // 4. we re-import all the assets to have the internal materials linked to the newly extracted textures List <Tuple <Object, string> > outputsForTargets = new List <Tuple <Object, string> >(); // use the first target for selecting the destination folder, but apply that path for all targets string destinationPath = (target as ModelImporter).assetPath; destinationPath = EditorUtility.SaveFolderPanel("Select Textures Folder", FileUtil.DeleteLastPathNameComponent(destinationPath), ""); if (string.IsNullOrEmpty(destinationPath)) { // cancel the extraction if the user did not select a folder return; } destinationPath = FileUtil.GetProjectRelativePath(destinationPath); try { // batch the extraction of the textures AssetDatabase.StartAssetEditing(); foreach (var t in targets) { var tempPath = FileUtil.GetUniqueTempPathInProject(); tempPath = tempPath.Replace("Temp", UnityEditorInternal.InternalEditorUtility.GetAssetsFolder()); outputsForTargets.Add(Tuple.Create(t, tempPath)); var importer = t as ModelImporter; importer.ExtractTextures(tempPath); } } finally { AssetDatabase.StopAssetEditing(); } try { // batch the remapping and the reimport of the assets AssetDatabase.Refresh(); AssetDatabase.StartAssetEditing(); foreach (var item in outputsForTargets) { var importer = item.Item1 as ModelImporter; var guids = AssetDatabase.FindAssets("t:Texture", new string[] { item.Item2 }); foreach (var guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); var tex = AssetDatabase.LoadAssetAtPath <Texture>(path); if (tex == null) { continue; } importer.AddRemap(new AssetImporter.SourceAssetIdentifier(tex), tex); var newPath = Path.Combine(destinationPath, FileUtil.UnityGetFileName(path)); newPath = AssetDatabase.GenerateUniqueAssetPath(newPath); AssetDatabase.MoveAsset(path, newPath); } AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); AssetDatabase.DeleteAsset(item.Item2); } } finally { AssetDatabase.StopAssetEditing(); } } } } }
private HumanTemplate OpenHumanTemplate() { string directory = "Assets/"; string str = EditorUtility.OpenFilePanel("Open Human Template", directory, "ht"); if (str == string.Empty) { return((HumanTemplate)null); } HumanTemplate humanTemplate = AssetDatabase.LoadMainAssetAtPath(FileUtil.GetProjectRelativePath(str)) as HumanTemplate; if ((UnityEngine.Object)humanTemplate == (UnityEngine.Object)null && EditorUtility.DisplayDialog("Human Template not found in project", "Import asset '" + str + "' into project", "Yes", "No")) { string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(directory + FileUtil.GetLastPathNameComponent(str)); FileUtil.CopyFileOrDirectory(str, uniqueAssetPath); AssetDatabase.Refresh(); humanTemplate = AssetDatabase.LoadMainAssetAtPath(uniqueAssetPath) as HumanTemplate; if ((UnityEngine.Object)humanTemplate == (UnityEngine.Object)null) { Debug.Log((object)("Failed importing file '" + str + "' to '" + uniqueAssetPath + "'")); } } return(humanTemplate); }