Created
August 21, 2024 18:50
-
-
Save yasirkula/edf4ba1bb7c5c18800e791e01bc9bcd7 to your computer and use it in GitHub Desktop.
Revisions
-
yasirkula created this gist
Aug 21, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ using System; using TMPro; using TMPro.EditorUtilities; using UnityEditor; using UnityEngine; [CustomEditor(typeof(TMP_FontAsset))] public class FontAssetSaveDisabler : TMP_FontAssetEditor { private static bool FontAssetsLocked { get => EditorPrefs.GetBool("TMPFontsLocked", false); set => EditorPrefs.SetBool("TMPFontsLocked", value); } public override void OnInspectorGUI() { if (GUILayout.Button(FontAssetsLocked ? "Unlock Font Assets" : "Lock Font Assets")) { FontAssetsLocked = !FontAssetsLocked; GUIUtility.ExitGUI(); } if (!FontAssetsLocked) { EditorGUILayout.Space(); base.OnInspectorGUI(); } } // Credit: https://discussions.unity.com/t/tmpro-dynamic-font-asset-constantly-changes-in-source-control/868941/29 private class SaveHandler : AssetModificationProcessor { private static string[] OnWillSaveAssets(string[] paths) { if (FontAssetsLocked) { int index = 0; foreach (string path in paths) { if (!typeof(TMP_FontAsset).IsAssignableFrom(AssetDatabase.GetMainAssetTypeAtPath(path))) paths[index++] = path; } Array.Resize(ref paths, index); } return paths; } } }