4 using System.Collections;
13 private static Texture m_copiedTexture;
15 private static Material m_copiedProperties;
16 private static Material m_copiedAtlasProperties;
20 [MenuItem(
"CONTEXT/Texture/Copy",
false, 2000)]
21 static void CopyTexture(MenuCommand command)
23 m_copiedTexture = command.context as Texture;
28 [MenuItem(
"CONTEXT/Material/Select Material",
false, 500)]
29 static void SelectMaterial(MenuCommand command)
31 Material mat = command.context as Material;
34 EditorUtility.FocusProjectWindow();
35 EditorGUIUtility.PingObject(mat);
40 [MenuItem(
"CONTEXT/Material/Create Material Preset",
false)]
41 static void DuplicateMaterial(MenuCommand command)
46 Material source_Mat = (Material)command.context;
47 if (!EditorUtility.IsPersistent(source_Mat))
49 Debug.LogWarning(
"Material is an instance and cannot be converted into a permanent asset.");
54 string assetPath = AssetDatabase.GetAssetPath(source_Mat).Split(
'.')[0];
56 Material duplicate =
new Material(source_Mat);
59 duplicate.shaderKeywords = source_Mat.shaderKeywords;
61 AssetDatabase.CreateAsset(duplicate, AssetDatabase.GenerateUniqueAssetPath(assetPath +
".mat"));
64 if (Selection.activeGameObject !=
null)
67 if (textObject !=
null)
75 if (subMeshObject !=
null)
81 if (subMeshUIObject !=
null)
88 EditorUtility.FocusProjectWindow();
89 EditorGUIUtility.PingObject(duplicate);
94 [MenuItem(
"CONTEXT/Material/Copy Material Properties",
false)]
95 static void CopyMaterialProperties(MenuCommand command)
98 if (command.context.GetType() == typeof(Material))
99 mat = (Material)command.context;
102 mat = Selection.activeGameObject.GetComponent<CanvasRenderer>().GetMaterial();
105 m_copiedProperties =
new Material(mat);
107 m_copiedProperties.shaderKeywords = mat.shaderKeywords;
109 m_copiedProperties.hideFlags = HideFlags.DontSave;
115 [MenuItem(
"CONTEXT/Material/Paste Material Properties",
false)]
116 static void PasteMaterialProperties(MenuCommand command)
119 if (m_copiedProperties ==
null)
121 Debug.LogWarning(
"No Material Properties to Paste. Use Copy Material Properties first.");
126 if (command.context.GetType() == typeof(Material))
127 mat = (Material)command.context;
130 mat = Selection.activeGameObject.GetComponent<CanvasRenderer>().GetMaterial();
133 Undo.RecordObject(mat,
"Paste Material");
135 ShaderUtilities.GetShaderPropertyIDs();
136 if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
139 m_copiedProperties.SetTexture(ShaderUtilities.ID_MainTex, mat.GetTexture(ShaderUtilities.ID_MainTex));
140 m_copiedProperties.SetFloat(ShaderUtilities.ID_GradientScale, mat.GetFloat(ShaderUtilities.ID_GradientScale));
141 m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureWidth, mat.GetFloat(ShaderUtilities.ID_TextureWidth));
142 m_copiedProperties.SetFloat(ShaderUtilities.ID_TextureHeight, mat.GetFloat(ShaderUtilities.ID_TextureHeight));
145 EditorShaderUtilities.CopyMaterialProperties(m_copiedProperties, mat);
148 mat.shaderKeywords = m_copiedProperties.shaderKeywords;
151 TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(
true, mat);
157 [MenuItem(
"CONTEXT/Material/Reset",
false, 2100)]
158 static void ResetSettings(MenuCommand command)
162 if (command.context.GetType() == typeof(Material))
163 mat = (Material)command.context;
166 mat = Selection.activeGameObject.GetComponent<CanvasRenderer>().GetMaterial();
169 Undo.RecordObject(mat,
"Reset Material");
171 ShaderUtilities.GetShaderPropertyIDs();
172 if (mat.HasProperty(ShaderUtilities.ID_GradientScale))
175 var texture = mat.GetTexture(ShaderUtilities.ID_MainTex);
176 var gradientScale = mat.GetFloat(ShaderUtilities.ID_GradientScale);
177 var texWidth = mat.GetFloat(ShaderUtilities.ID_TextureWidth);
178 var texHeight = mat.GetFloat(ShaderUtilities.ID_TextureHeight);
179 var stencilId = mat.GetFloat(ShaderUtilities.ID_StencilID);
180 var stencilComp = mat.GetFloat(ShaderUtilities.ID_StencilComp);
181 var normalWeight = mat.GetFloat(ShaderUtilities.ID_WeightNormal);
182 var boldWeight = mat.GetFloat(ShaderUtilities.ID_WeightBold);
185 Unsupported.SmartReset(mat);
188 mat.shaderKeywords =
new string[0];
191 mat.SetTexture(ShaderUtilities.ID_MainTex, texture);
192 mat.SetFloat(ShaderUtilities.ID_GradientScale, gradientScale);
193 mat.SetFloat(ShaderUtilities.ID_TextureWidth, texWidth);
194 mat.SetFloat(ShaderUtilities.ID_TextureHeight, texHeight);
195 mat.SetFloat(ShaderUtilities.ID_StencilID, stencilId);
196 mat.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
197 mat.SetFloat(ShaderUtilities.ID_WeightNormal, normalWeight);
198 mat.SetFloat(ShaderUtilities.ID_WeightBold, boldWeight);
202 Unsupported.SmartReset(mat);
205 TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(
true, mat);
211 [MenuItem(
"CONTEXT/Material/Copy Atlas",
false, 2000)]
212 static void CopyAtlas(MenuCommand command)
214 Material mat = command.context as Material;
216 m_copiedAtlasProperties =
new Material(mat);
217 m_copiedAtlasProperties.hideFlags = HideFlags.DontSave;
222 [MenuItem(
"CONTEXT/Material/Paste Atlas",
false, 2001)]
223 static void PasteAtlas(MenuCommand command)
225 Material mat = command.context as Material;
227 if (m_copiedAtlasProperties !=
null)
229 Undo.RecordObject(mat,
"Paste Texture");
231 ShaderUtilities.GetShaderPropertyIDs();
232 mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedAtlasProperties.GetTexture(ShaderUtilities.ID_MainTex));
233 mat.SetFloat(ShaderUtilities.ID_GradientScale, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_GradientScale));
234 mat.SetFloat(ShaderUtilities.ID_TextureWidth, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureWidth));
235 mat.SetFloat(ShaderUtilities.ID_TextureHeight, m_copiedAtlasProperties.GetFloat(ShaderUtilities.ID_TextureHeight));
237 else if (m_copiedTexture !=
null)
239 Undo.RecordObject(mat,
"Paste Texture");
241 mat.SetTexture(ShaderUtilities.ID_MainTex, m_copiedTexture);
249 [MenuItem(
"CONTEXT/TMP_FontAsset/Extract Atlas",
false, 2100)]
250 static void ExtractAtlas(MenuCommand command)
254 string fontPath = AssetDatabase.GetAssetPath(font);
255 string texPath = Path.GetDirectoryName(fontPath) +
"/" + Path.GetFileNameWithoutExtension(fontPath) +
" Atlas.png";
258 SerializedObject texprop =
new SerializedObject(font.
material.GetTexture(ShaderUtilities.ID_MainTex));
259 texprop.FindProperty(
"m_IsReadable").boolValue =
true;
260 texprop.ApplyModifiedProperties();
263 Texture2D tex = Instantiate(font.
material.GetTexture(ShaderUtilities.ID_MainTex)) as Texture2D;
266 texprop.FindProperty(
"m_IsReadable").boolValue =
false;
267 texprop.ApplyModifiedProperties();
271 var pngData = tex.EncodeToPNG();
272 File.WriteAllBytes(texPath, pngData);
274 AssetDatabase.Refresh();
275 DestroyImmediate(tex);
282 [MenuItem(
"CONTEXT/TMP_FontAsset/Update Atlas Texture...",
false, 2000)]
287 if (fontAsset !=
null)
294 [MenuItem(
"CONTEXT/TrueTypeFontImporter/Create TMP Font Asset...",
false, 200)]
295 static void CreateFontAsset(MenuCommand command)
297 TrueTypeFontImporter importer = command.context as TrueTypeFontImporter;
299 if (importer !=
null)
301 Font sourceFontFile = AssetDatabase.LoadAssetAtPath<Font>(importer.assetPath);
Base class which contains common properties and functions shared between the TextMeshPro and TextMesh...
Material sharedMaterial
The material to be assigned to this text object.
Material material
The material used by this asset.
virtual Material fontSharedMaterial
The material to be assigned to this text object.
Material sharedMaterial
The material to be assigned to this text object.