private void OnSplineChanged(BezierSpline spline, DirtyFlags dirtyFlags) { #if UNITY_EDITOR if (!executeInEditMode && !EditorApplication.isPlaying) { return; } if (BuildPipeline.isBuildingPlayer) { return; } #if UNITY_2018_3_OR_NEWER // Don't execute the script in prefab mode PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (openPrefabStage != null && openPrefabStage.IsPartOfPrefabContents(gameObject)) { return; } #endif #endif if (m_autoRefresh && (dirtyFlags & (DirtyFlags.SplineShapeChanged | DirtyFlags.NormalsChanged)) != DirtyFlags.None) { Refresh(); } }
private void InitiateSearch() { if (objectsToSearch.IsEmpty()) { errorMessage = "ADD AN ASSET TO THE LIST FIRST!"; } else if (!EditorApplication.isPlaying && !Utilities.AreScenesSaved()) { // Don't start the search if at least one scene is currently dirty (not saved) errorMessage = "SAVE OPEN SCENES FIRST!"; } else { errorMessage = string.Empty; currentPhase = Phase.Processing; SavePrefs(); #if UNITY_2018_3_OR_NEWER ReplacePrefabStageObjectsWithAssets(PrefabStageUtility.GetCurrentPrefabStage()); #endif // Start searching searchResult = core.Run(new AssetUsageDetector.Parameters() { objectsToSearch = new ObjectToSearchEnumerator(objectsToSearch).ToArray(), searchInScenes = GetSceneSearchMode(true), searchInAssetsFolder = searchInAssetsFolder, searchInAssetsSubset = !searchInAssetsSubset.IsEmpty() ? searchInAssetsSubset.ToArray() : null, excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null, dontSearchInSourceAssets = dontSearchInSourceAssets, excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null, searchInProjectSettings = searchInProjectSettings, //fieldModifiers = fieldModifiers, //propertyModifiers = propertyModifiers, //searchDepthLimit = searchDepthLimit, //searchNonSerializableVariables = searchNonSerializableVariables, lazySceneSearch = lazySceneSearch, noAssetDatabaseChanges = noAssetDatabaseChanges, showDetailedProgressBar = showDetailedProgressBar }); currentPhase = Phase.Complete; } }
private void OnGUI() { if (EditorApplication.isPlaying) { EditorGUILayout.HelpBox("Text To TMP can't work while in Play Mode.", MessageType.Error); return; } if (!AreScenesSaved()) { EditorGUILayout.HelpBox("Text To TMP can't work while there are unsaved Scenes.", MessageType.Error); return; } #if UNITY_2018_3_OR_NEWER PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && openPrefabStage.scene.isDirty) { EditorGUILayout.HelpBox("Text To TMP can't work while there are unsaved changes in the Prefab stage.", MessageType.Error); return; } #endif if (boldWordWrappedLabel == null) { boldWordWrappedLabel = new GUIStyle(EditorStyles.boldLabel) { wordWrap = true } } ; scrollPos = GUILayout.BeginScrollView(scrollPos); Event ev = Event.current; if (stage == UpgradeStage.InitializeAndCollectReferences) { GUILayout.Box("Assets & Scenes To Upgrade", GL_EXPAND_WIDTH); if ((ev.type == EventType.DragPerform || ev.type == EventType.DragUpdated) && GUILayoutUtility.GetLastRect().Contains(ev.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ev.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Object[] draggedObjects = DragAndDrop.objectReferences; if (draggedObjects != null) { for (int i = 0; i < draggedObjects.Length; i++) { if (draggedObjects[i] && AssetDatabase.Contains(draggedObjects[i])) { upgradeTargets.Add(draggedObjects[i]); } } } } ev.Use(); } for (int i = 0; i < upgradeTargets.Count; i++) { GUILayout.BeginHorizontal(); upgradeTargets[i] = EditorGUILayout.ObjectField(GUIContent.none, upgradeTargets[i], typeof(Object), false); if (GUILayout.Button("+", GL_WIDTH_25)) { upgradeTargets.Insert(i + 1, null); } if (GUILayout.Button("-", GL_WIDTH_25)) { // Always keep at least 1 element if (upgradeTargets.Count > 1) { upgradeTargets.RemoveAt(i--); } else { upgradeTargets[0] = null; } } GUILayout.EndHorizontal(); } EditorGUILayout.HelpBox("You can add folder(s) to this list. Their contents will be included in the upgrade process.", MessageType.Info); EditorGUILayout.Space(); upgradeScenes = EditorGUILayout.ToggleLeft("Upgrade Objects In Scenes (If Any)", upgradeScenes); if (upgradeScenes) { EditorGUILayout.HelpBox(DONT_CLOSE_SCENES_WARNING, MessageType.Warning); } EditorGUILayout.Space(); GUILayout.Box("Font Upgrades", GL_EXPAND_WIDTH); if ((ev.type == EventType.DragPerform || ev.type == EventType.DragUpdated) && GUILayoutUtility.GetLastRect().Contains(ev.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ev.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Object[] draggedObjects = DragAndDrop.objectReferences; if (draggedObjects != null) { List <Font> draggedUnityFonts = new List <Font>(); List <TMP_FontAsset> draggedTMPFonts = new List <TMP_FontAsset>(); for (int i = 0; i < draggedObjects.Length; i++) { if (draggedObjects[i]) { if (draggedObjects[i] is Font) { draggedUnityFonts.Add((Font)draggedObjects[i]); } else if (draggedObjects[i] is TMP_FontAsset) { draggedTMPFonts.Add((TMP_FontAsset)draggedObjects[i]); } } } for (int i = 0, count = Mathf.Max(draggedUnityFonts.Count, draggedTMPFonts.Count); i < count; i++) { FontUpgrade fontUpgrade; if (i < draggedUnityFonts.Count && i < draggedTMPFonts.Count) { fontUpgrade = new FontUpgrade() { unityFont = draggedUnityFonts[i], tmpFont = draggedTMPFonts[i] } } ; else if (i < draggedUnityFonts.Count) { fontUpgrade = new FontUpgrade() { unityFont = draggedUnityFonts[i] } } ; else { fontUpgrade = new FontUpgrade() { tmpFont = draggedTMPFonts[i] } }; if (fontUpgrade.tmpFont) { fontUpgrade.tmpFontMaterialDefault = fontUpgrade.tmpFont.material; fontUpgrade.tmpFontMaterialShadow = fontUpgrade.tmpFontMaterialDefault; fontUpgrade.tmpFontMaterialOutline = fontUpgrade.tmpFontMaterialDefault; fontUpgrade.tmpFontMaterialShadowAndOutline = fontUpgrade.tmpFontMaterialDefault; } fontUpgrades.Add(fontUpgrade); } } } ev.Use(); } EditorGUILayout.HelpBox("There are 4 types of font materials:\n- Shadow Material: used for Text components with Shadow component\n- Outline Material: used for Text components with Outline component\n- Shadow & Outline Material: used for Text components with Shadow and Outline components\n- Default Material: used for the remaining Text components", MessageType.Info); for (int i = 0; i < fontUpgrades.Count; i++) { GUILayout.BeginHorizontal(); if (i == 0) { GUILayout.Label("Default TMP Font", boldWordWrappedLabel); } else { GUILayout.Label("TMP Font for: " + (fontUpgrades[i].unityFont ? fontUpgrades[i].unityFont.name : "<Font not assigned>"), boldWordWrappedLabel); } if (GUILayout.Button("+", GL_WIDTH_25)) { fontUpgrades.Insert(i + 1, new FontUpgrade()); } if (i > 0 && GUILayout.Button("-", GL_WIDTH_25)) { fontUpgrades.RemoveAt(i--); } GUILayout.EndHorizontal(); if (i != 0) { fontUpgrades[i].unityFont = EditorGUILayout.ObjectField("Unity Font", fontUpgrades[i].unityFont, typeof(Font), false) as Font; } EditorGUI.BeginChangeCheck(); fontUpgrades[i].tmpFont = EditorGUILayout.ObjectField("TMP Font", fontUpgrades[i].tmpFont, typeof(TMP_FontAsset), false) as TMP_FontAsset; if (EditorGUI.EndChangeCheck()) { fontUpgrades[i].tmpFontMaterialDefault = fontUpgrades[i].tmpFont ? fontUpgrades[i].tmpFont.material : null; fontUpgrades[i].tmpFontMaterialShadow = fontUpgrades[i].tmpFontMaterialDefault; fontUpgrades[i].tmpFontMaterialOutline = fontUpgrades[i].tmpFontMaterialDefault; fontUpgrades[i].tmpFontMaterialShadowAndOutline = fontUpgrades[i].tmpFontMaterialDefault; } fontUpgrades[i].tmpFontMaterialDefault = EditorGUILayout.ObjectField("TMP Font Default Material", fontUpgrades[i].tmpFontMaterialDefault, typeof(Material), false) as Material; fontUpgrades[i].tmpFontMaterialShadow = EditorGUILayout.ObjectField("TMP Font Shadow Material", fontUpgrades[i].tmpFontMaterialShadow, typeof(Material), false) as Material; fontUpgrades[i].tmpFontMaterialOutline = EditorGUILayout.ObjectField("TMP Font Outline Material", fontUpgrades[i].tmpFontMaterialOutline, typeof(Material), false) as Material; fontUpgrades[i].tmpFontMaterialShadowAndOutline = EditorGUILayout.ObjectField("TMP Font Shadow & Outline Material", fontUpgrades[i].tmpFontMaterialShadowAndOutline, typeof(Material), false) as Material; } EditorGUILayout.Space(); if (GUILayout.Button("START", GL_HEIGHT_30) && (!upgradeScenes || EditorUtility.DisplayDialog("Warning", DONT_CLOSE_SCENES_WARNING.Replace("&", "and"), "Got it!", "Cancel"))) { AssetDatabase.SaveAssets(); EditorUtility.DisplayProgressBar("Initializing...", "Please wait...", 0f); try { Initialize(); } finally { EditorUtility.ClearProgressBar(); } CollectReferences(); SwitchStage(UpgradeStage.UpgradeScripts); } } else if (stage == UpgradeStage.UpgradeScripts) { GUILayout.Box("Step 1/3: Upgrading Scripts", GL_EXPAND_WIDTH); GUILayout.Label("Text, InputField, Dropdown and TextMesh terms used inside these scripts will be upgraded to their TextMesh Pro variants:", boldWordWrappedLabel); if (scriptsToUpgrade.Length > 0) { scriptsToUpgrade.DrawOnGUI(); } else { GUILayout.Label("<None>"); } EditorGUILayout.Space(); #if UNITY_2017_3_OR_NEWER GUILayout.Label("TextMesh Pro's Assembly Definition File (if exists) will be added to these Assembly Definition Files' 'Assembly Definition References' list:", boldWordWrappedLabel); if (assemblyDefinitionFilesToUpgrade.Length > 0) { assemblyDefinitionFilesToUpgrade.DrawOnGUI(); } else { GUILayout.Label("<None>"); } EditorGUILayout.Space(); #endif EditorGUILayout.HelpBox(BACKUP_PROJECT_WARNING, MessageType.Warning); EditorGUILayout.HelpBox(DONT_CLOSE_WINDOW_WARNING, MessageType.Warning); EditorGUILayout.Space(); #if UNITY_2017_3_OR_NEWER GUI.enabled = scriptsToUpgrade.EnabledCount > 0 | assemblyDefinitionFilesToUpgrade.EnabledCount > 0; #else GUI.enabled = scriptsToUpgrade.EnabledCount > 0; #endif if (GUILayout.Button("UPGRADE SCRIPTS", GL_HEIGHT_30) && EditorUtility.DisplayDialog("Warning", BACKUP_PROJECT_WARNING, "Got it!", "Cancel") && EditorUtility.DisplayDialog("Warning", DONT_CLOSE_WINDOW_WARNING, "Got it!", "Cancel")) { AssetDatabase.SaveAssets(); UpgradeScripts(); SwitchStage(UpgradeStage.PendingUpgradeScriptsCompletion); } GUI.enabled = true; EditorGUILayout.Space(); if (GUILayout.Button("DON'T UPGRADE SCRIPTS", GL_HEIGHT_30) && EditorUtility.DisplayDialog("Warning", BACKUP_PROJECT_WARNING, "Got it!", "Cancel") && EditorUtility.DisplayDialog("Warning", DONT_CLOSE_WINDOW_WARNING, "Got it!", "Cancel")) { SwitchStage(UpgradeStage.UpgradeComponents); } EditorGUILayout.Space(); if (GUILayout.Button("BACK", GL_HEIGHT_30)) { SwitchStage(UpgradeStage.InitializeAndCollectReferences); } } else if (stage == UpgradeStage.PendingUpgradeScriptsCompletion) { GUILayout.Box("Step 1/3: Upgrading Scripts", GL_EXPAND_WIDTH); if (EditorApplication.isCompiling) { GUILayout.Label("Waiting for Unity to finish compiling the scripts...", boldWordWrappedLabel); } else { GUILayout.Label(FIX_COMPILATION_ERRORS_WARNING, boldWordWrappedLabel); } EditorGUILayout.Space(); GUI.enabled = !EditorApplication.isCompiling; if (GUILayout.Button("NEXT STEP", GL_HEIGHT_30) && EditorUtility.DisplayDialog("Warning", FIX_COMPILATION_ERRORS_WARNING, "Got it!", "Cancel")) { SwitchStage(UpgradeStage.UpgradeComponents); } GUI.enabled = true; } else if (stage == UpgradeStage.UpgradeComponents) { GUILayout.Box("Step 2/3: Upgrading Components", GL_EXPAND_WIDTH); GUILayout.Label("Text, InputField, Dropdown and TextMesh component(s) on the following assets will be upgraded to their TextMesh Pro variants:", boldWordWrappedLabel); if (assetsToUpgrade.Length > 0) { assetsToUpgrade.DrawOnGUI(); } else { GUILayout.Label("<None>"); } EditorGUILayout.Space(); GUILayout.Label("The same component(s) inside these Scenes will also be upgraded:", boldWordWrappedLabel); if (scenesToUpgrade.Length > 0) { scenesToUpgrade.DrawOnGUI(); } else { GUILayout.Label("<None>"); } EditorGUILayout.Space(); if (assetsToUpgrade.EnabledCount > 0 || scenesToUpgrade.EnabledCount > 0) { GUILayout.Label("When a Text's 'Horizontal Overflow' is set to 'Overflow' and 'Vertical Overflow' is set to 'Truncate', its behaviour will change when it is upgraded to TextMesh Pro:", boldWordWrappedLabel); alwaysUseOverflowForNonWrappingTexts = !WordWrappingToggleLeft("Set TextMesh Pro's 'Overflow' value to 'Truncate': text will truncate both horizontally and vertically, i.e. it won't overflow horizontally", !alwaysUseOverflowForNonWrappingTexts); alwaysUseOverflowForNonWrappingTexts = WordWrappingToggleLeft("Set TextMesh Pro's 'Overflow' value to 'Overflow': text will overflow both horizontally and vertically, i.e. it won't truncate vertically", alwaysUseOverflowForNonWrappingTexts); EditorGUILayout.Space(); } GUI.enabled = assetsToUpgrade.EnabledCount > 0 || scenesToUpgrade.EnabledCount > 0; if (GUILayout.Button("UPGRADE COMPONENTS", GL_HEIGHT_30)) { AssetDatabase.SaveAssets(); UpgradeComponents(); SwitchStage(UpgradeStage.UpdateReferences); } GUI.enabled = true; EditorGUILayout.Space(); if (GUILayout.Button("DON'T UPGRADE COMPONENTS", GL_HEIGHT_30)) { SwitchStage(UpgradeStage.UpdateReferences); } } else if (stage == UpgradeStage.UpdateReferences) { GUILayout.Box("Step 3/3: Reconnecting References", GL_EXPAND_WIDTH); GUILayout.Label("For objects whose variables were referencing the upgraded Text, InputField, Dropdown and TextMesh components, these variables will now refer to the components' TextMesh Pro variants.", boldWordWrappedLabel); EditorGUILayout.Space(); if (GUILayout.Button("RECONNECT REFERENCES", GL_HEIGHT_30)) { AssetDatabase.SaveAssets(); UpdateReferences(); SwitchStage(UpgradeStage.Finished); } EditorGUILayout.Space(); if (GUILayout.Button("DON'T RECONNECT REFERENCES", GL_HEIGHT_30)) { SwitchStage(UpgradeStage.Finished); } } else if (stage == UpgradeStage.Finished) { GUILayout.Box("Upgrade Completed", GL_EXPAND_WIDTH); GUILayout.Label("You can now safely close this window and close the scenes that were opened during the upgrade process (if any).", boldWordWrappedLabel); EditorGUILayout.Space(); if (GUILayout.Button("START AGAIN", GL_HEIGHT_30)) { SwitchStage(UpgradeStage.InitializeAndCollectReferences); } } EditorGUILayout.Space(); GUILayout.EndScrollView(); }
// Ping an object in either Project view or Hierarchy view public static Object PingInEditor(this Object obj) { if (obj is Component) { obj = ((Component)obj).gameObject; } Object selection = obj; // Pinging a prefab only works if the pinged object is the root of the prefab // or a direct child of it. Pinging any grandchildren of the prefab // does not work; in which case, traverse the parent hierarchy until // a pingable parent is reached if (obj.IsAsset() && obj is GameObject) { #if UNITY_2018_3_OR_NEWER Transform objTR = ((GameObject)obj).transform.root; PrefabAssetType prefabAssetType = PrefabUtility.GetPrefabAssetType(objTR.gameObject); if (prefabAssetType == PrefabAssetType.Regular || prefabAssetType == PrefabAssetType.Variant) { string assetPath = AssetDatabase.GetAssetPath(objTR.gameObject); PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); // Try to open the prefab stage of pinged prefabs if they are double clicked if (previousPingedPrefabInstanceId == objTR.GetInstanceID() && EditorApplication.timeSinceStartup - previousPingedPrefabPingTime <= 0.3f && #if UNITY_2020_1_OR_NEWER (openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.assetPath)) #else (openPrefabStage == null || !openPrefabStage.stageHandle.IsValid() || assetPath != openPrefabStage.prefabAssetPath)) #endif { AssetDatabase.OpenAsset(objTR.gameObject); openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); } previousPingedPrefabInstanceId = objTR.GetInstanceID(); previousPingedPrefabPingTime = EditorApplication.timeSinceStartup; #if UNITY_2020_1_OR_NEWER if (openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.assetPath) #else if (openPrefabStage != null && openPrefabStage.stageHandle.IsValid() && assetPath == openPrefabStage.prefabAssetPath) #endif { GameObject prefabStageGO = FollowSymmetricHierarchy((GameObject)obj, ((GameObject)obj).transform.root.gameObject, openPrefabStage.prefabContentsRoot); if (prefabStageGO != null) { objTR = prefabStageGO.transform; selection = objTR.gameObject; } } #if UNITY_2019_1_OR_NEWER else if (obj != objTR.gameObject) { Debug.Log("Open " + assetPath + " in prefab mode to select and edit " + obj.name); selection = objTR.gameObject; } #else else { Debug.Log("Open " + assetPath + " in prefab mode to select and edit " + obj.name); } #endif } #else Transform objTR = ((GameObject)obj).transform; while (objTR.parent != null && objTR.parent.parent != null) { objTR = objTR.parent; } #endif obj = objTR.gameObject; } EditorGUIUtility.PingObject(obj); return(selection); }