暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TMP_BaseShaderGUI.cs 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace TMPro.EditorUtilities
  4. {
  5. /// <summary>Base class for TextMesh Pro shader GUIs.</summary>
  6. public abstract class TMP_BaseShaderGUI : ShaderGUI
  7. {
  8. /// <summary>Representation of a #pragma shader_feature.</summary>
  9. /// <description>It is assumed that the first feature option is for no keyword (underscores).</description>
  10. protected class ShaderFeature
  11. {
  12. public string undoLabel;
  13. public GUIContent label;
  14. /// <summary>The keyword labels, for display. Include the no-keyword as the first option.</summary>
  15. public GUIContent[] keywordLabels;
  16. /// <summary>The shader keywords. Exclude the no-keyword option.</summary>
  17. public string[] keywords;
  18. int m_State;
  19. public bool Active
  20. {
  21. get { return m_State >= 0; }
  22. }
  23. public int State
  24. {
  25. get { return m_State; }
  26. }
  27. public void ReadState(Material material)
  28. {
  29. for (int i = 0; i < keywords.Length; i++)
  30. {
  31. if (material.IsKeywordEnabled(keywords[i]))
  32. {
  33. m_State = i;
  34. return;
  35. }
  36. }
  37. m_State = -1;
  38. }
  39. public void SetActive(bool active, Material material)
  40. {
  41. m_State = active ? 0 : -1;
  42. SetStateKeywords(material);
  43. }
  44. public void DoPopup(MaterialEditor editor, Material material)
  45. {
  46. EditorGUI.BeginChangeCheck();
  47. int selection = EditorGUILayout.Popup(label, m_State + 1, keywordLabels);
  48. if (EditorGUI.EndChangeCheck())
  49. {
  50. m_State = selection - 1;
  51. editor.RegisterPropertyChangeUndo(undoLabel);
  52. SetStateKeywords(material);
  53. }
  54. }
  55. void SetStateKeywords(Material material)
  56. {
  57. for (int i = 0; i < keywords.Length; i++)
  58. {
  59. if (i == m_State)
  60. {
  61. material.EnableKeyword(keywords[i]);
  62. }
  63. else
  64. {
  65. material.DisableKeyword(keywords[i]);
  66. }
  67. }
  68. }
  69. }
  70. static GUIContent s_TempLabel = new GUIContent();
  71. protected static bool s_DebugExtended;
  72. static int s_UndoRedoCount, s_LastSeenUndoRedoCount;
  73. static float[][] s_TempFloats =
  74. {
  75. null, new float[1], new float[2], new float[3], new float[4]
  76. };
  77. protected static GUIContent[] s_XywhVectorLabels =
  78. {
  79. new GUIContent("X"),
  80. new GUIContent("Y"),
  81. new GUIContent("W", "Width"),
  82. new GUIContent("H", "Height")
  83. };
  84. protected static GUIContent[] s_LbrtVectorLabels =
  85. {
  86. new GUIContent("L", "Left"),
  87. new GUIContent("B", "Bottom"),
  88. new GUIContent("R", "Right"),
  89. new GUIContent("T", "Top")
  90. };
  91. protected static GUIContent[] s_CullingTypeLabels =
  92. {
  93. new GUIContent("Off"),
  94. new GUIContent("Front"),
  95. new GUIContent("Back")
  96. };
  97. static TMP_BaseShaderGUI()
  98. {
  99. // Keep track of how many undo/redo events happened.
  100. Undo.undoRedoPerformed += () => s_UndoRedoCount += 1;
  101. }
  102. bool m_IsNewGUI = true;
  103. float m_DragAndDropMinY;
  104. protected MaterialEditor m_Editor;
  105. protected Material m_Material;
  106. private int m_ShaderID;
  107. protected MaterialProperty[] m_Properties;
  108. void PrepareGUI()
  109. {
  110. m_IsNewGUI = false;
  111. ShaderUtilities.GetShaderPropertyIDs();
  112. // New GUI just got constructed. This happens in response to a selection,
  113. // but also after undo/redo events.
  114. if (s_LastSeenUndoRedoCount != s_UndoRedoCount)
  115. {
  116. // There's been at least one undo/redo since the last time this GUI got constructed.
  117. // Maybe the undo/redo was for this material? Assume that is was.
  118. TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material);
  119. }
  120. s_LastSeenUndoRedoCount = s_UndoRedoCount;
  121. }
  122. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
  123. {
  124. m_Editor = materialEditor;
  125. m_Material = materialEditor.target as Material;
  126. this.m_Properties = properties;
  127. if (m_IsNewGUI)
  128. PrepareGUI();
  129. DoDragAndDropBegin();
  130. EditorGUI.BeginChangeCheck();
  131. DoGUI();
  132. if (EditorGUI.EndChangeCheck())
  133. {
  134. TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material);
  135. }
  136. DoDragAndDropEnd();
  137. }
  138. public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
  139. {
  140. base.AssignNewShaderToMaterial(material, oldShader, newShader);
  141. TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, material);
  142. }
  143. /// <summary>Override this method to create the specific shader GUI.</summary>
  144. protected abstract void DoGUI();
  145. static string[] s_PanelStateLabel = new string[] { "\t- <i>Click to collapse</i> -", "\t- <i>Click to expand</i> -" };
  146. protected bool BeginPanel(string panel, bool expanded)
  147. {
  148. EditorGUI.indentLevel = 0;
  149. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  150. Rect r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 18));
  151. r.x += 20;
  152. r.width += 6;
  153. bool enabled = GUI.enabled;
  154. GUI.enabled = true;
  155. expanded = TMP_EditorUtility.EditorToggle(r, expanded, new GUIContent(panel), TMP_UIStyleManager.panelTitle);
  156. r.width -= 30;
  157. EditorGUI.LabelField(r, new GUIContent(expanded ? s_PanelStateLabel[0] : s_PanelStateLabel[1]), TMP_UIStyleManager.rightLabel);
  158. GUI.enabled = enabled;
  159. EditorGUI.indentLevel += 1;
  160. EditorGUI.BeginDisabledGroup(false);
  161. return expanded;
  162. }
  163. protected bool BeginPanel(string panel, ShaderFeature feature, bool expanded, bool readState = true)
  164. {
  165. EditorGUI.indentLevel = 0;
  166. if (readState)
  167. {
  168. feature.ReadState(m_Material);
  169. }
  170. EditorGUI.BeginChangeCheck();
  171. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  172. GUILayout.BeginHorizontal();
  173. Rect r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 20, GUILayout.Width(20f)));
  174. bool active = EditorGUI.Toggle(r, feature.Active);
  175. if (EditorGUI.EndChangeCheck())
  176. {
  177. m_Editor.RegisterPropertyChangeUndo(feature.undoLabel);
  178. feature.SetActive(active, m_Material);
  179. }
  180. r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 18));
  181. r.width += 6;
  182. bool enabled = GUI.enabled;
  183. GUI.enabled = true;
  184. expanded = TMP_EditorUtility.EditorToggle(r, expanded, new GUIContent(panel), TMP_UIStyleManager.panelTitle);
  185. r.width -= 10;
  186. EditorGUI.LabelField(r, new GUIContent(expanded ? s_PanelStateLabel[0] : s_PanelStateLabel[1]), TMP_UIStyleManager.rightLabel);
  187. GUI.enabled = enabled;
  188. GUILayout.EndHorizontal();
  189. EditorGUI.indentLevel += 1;
  190. EditorGUI.BeginDisabledGroup(!active);
  191. return expanded;
  192. }
  193. public void EndPanel()
  194. {
  195. EditorGUI.EndDisabledGroup();
  196. EditorGUI.indentLevel -= 1;
  197. EditorGUILayout.EndVertical();
  198. }
  199. MaterialProperty BeginProperty(string name)
  200. {
  201. MaterialProperty property = FindProperty(name, m_Properties);
  202. EditorGUI.BeginChangeCheck();
  203. EditorGUI.showMixedValue = property.hasMixedValue;
  204. m_Editor.BeginAnimatedCheck(Rect.zero, property);
  205. return property;
  206. }
  207. bool EndProperty()
  208. {
  209. m_Editor.EndAnimatedCheck();
  210. EditorGUI.showMixedValue = false;
  211. return EditorGUI.EndChangeCheck();
  212. }
  213. protected void DoPopup(string name, string label, GUIContent[] options)
  214. {
  215. MaterialProperty property = BeginProperty(name);
  216. s_TempLabel.text = label;
  217. int index = EditorGUILayout.Popup(s_TempLabel, (int)property.floatValue, options);
  218. if (EndProperty())
  219. {
  220. property.floatValue = index;
  221. }
  222. }
  223. protected void DoCubeMap(string name, string label)
  224. {
  225. DoTexture(name, label, typeof(Cubemap));
  226. }
  227. protected void DoTexture2D(string name, string label, bool withTilingOffset = false, string[] speedNames = null)
  228. {
  229. DoTexture(name, label, typeof(Texture2D), withTilingOffset, speedNames);
  230. }
  231. void DoTexture(string name, string label, System.Type type, bool withTilingOffset = false, string[] speedNames = null)
  232. {
  233. float objFieldSize = 60f;
  234. bool smallLayout = EditorGUIUtility.currentViewWidth <= 330f && (withTilingOffset || speedNames != null);
  235. float controlHeight = smallLayout ? objFieldSize * 2 : objFieldSize;
  236. MaterialProperty property = FindProperty(name, m_Properties);
  237. m_Editor.BeginAnimatedCheck(Rect.zero, property);
  238. Rect rect = EditorGUILayout.GetControlRect(true, controlHeight);
  239. float totalWidth = rect.width;
  240. rect.width = EditorGUIUtility.labelWidth + objFieldSize;
  241. rect.height = objFieldSize;
  242. s_TempLabel.text = label;
  243. EditorGUI.BeginChangeCheck();
  244. Object tex = EditorGUI.ObjectField(rect, s_TempLabel, property.textureValue, type, false);
  245. if (EditorGUI.EndChangeCheck())
  246. {
  247. property.textureValue = tex as Texture;
  248. }
  249. float additionalHeight = controlHeight - objFieldSize;
  250. float xOffset = smallLayout ? rect.width - objFieldSize : rect.width;
  251. rect.y += additionalHeight;
  252. rect.x += xOffset;
  253. rect.width = totalWidth - xOffset;
  254. rect.height = EditorGUIUtility.singleLineHeight;
  255. if (withTilingOffset)
  256. {
  257. DoTilingOffset(rect, property);
  258. rect.y += (rect.height + 2f) * 2f;
  259. }
  260. m_Editor.EndAnimatedCheck();
  261. if (speedNames != null)
  262. {
  263. DoUVSpeed(rect, speedNames);
  264. }
  265. }
  266. void DoTilingOffset(Rect rect, MaterialProperty property)
  267. {
  268. float labelWidth = EditorGUIUtility.labelWidth;
  269. int indentLevel = EditorGUI.indentLevel;
  270. EditorGUI.indentLevel = 0;
  271. EditorGUIUtility.labelWidth = Mathf.Min(40f, rect.width * 0.40f);
  272. Vector4 vector = property.textureScaleAndOffset;
  273. bool changed = false;
  274. float[] values = s_TempFloats[2];
  275. s_TempLabel.text = "Tiling";
  276. Rect vectorRect = EditorGUI.PrefixLabel(rect, s_TempLabel);
  277. values[0] = vector.x;
  278. values[1] = vector.y;
  279. EditorGUI.BeginChangeCheck();
  280. EditorGUI.MultiFloatField(vectorRect, s_XywhVectorLabels, values);
  281. if (EditorGUI.EndChangeCheck())
  282. {
  283. vector.x = values[0];
  284. vector.y = values[1];
  285. changed = true;
  286. }
  287. rect.y += rect.height + 2f;
  288. s_TempLabel.text = "Offset";
  289. vectorRect = EditorGUI.PrefixLabel(rect, s_TempLabel);
  290. values[0] = vector.z;
  291. values[1] = vector.w;
  292. EditorGUI.BeginChangeCheck();
  293. EditorGUI.MultiFloatField(vectorRect, s_XywhVectorLabels, values);
  294. if (EditorGUI.EndChangeCheck())
  295. {
  296. vector.z = values[0];
  297. vector.w = values[1];
  298. changed = true;
  299. }
  300. if (changed)
  301. {
  302. property.textureScaleAndOffset = vector;
  303. }
  304. EditorGUIUtility.labelWidth = labelWidth;
  305. EditorGUI.indentLevel = indentLevel;
  306. }
  307. protected void DoUVSpeed(Rect rect, string[] names)
  308. {
  309. float labelWidth = EditorGUIUtility.labelWidth;
  310. int indentLevel = EditorGUI.indentLevel;
  311. EditorGUI.indentLevel = 0;
  312. EditorGUIUtility.labelWidth = Mathf.Min(40f, rect.width * 0.40f);
  313. s_TempLabel.text = "Speed";
  314. rect = EditorGUI.PrefixLabel(rect, s_TempLabel);
  315. EditorGUIUtility.labelWidth = 10f;
  316. rect.width = rect.width * 0.5f - 2f;
  317. if (names.Length == 1)
  318. {
  319. DoFloat2(rect, names[0]);
  320. }
  321. else
  322. {
  323. DoFloat(rect, names[0], "X");
  324. rect.x += rect.width + 4f;
  325. DoFloat(rect, names[1], "Y");
  326. }
  327. EditorGUIUtility.labelWidth = labelWidth;
  328. EditorGUI.indentLevel = indentLevel;
  329. }
  330. protected void DoToggle(string name, string label)
  331. {
  332. MaterialProperty property = BeginProperty(name);
  333. s_TempLabel.text = label;
  334. bool value = EditorGUILayout.Toggle(s_TempLabel, property.floatValue == 1f);
  335. if (EndProperty())
  336. {
  337. property.floatValue = value ? 1f : 0f;
  338. }
  339. }
  340. protected void DoFloat(string name, string label)
  341. {
  342. MaterialProperty property = BeginProperty(name);
  343. Rect rect = EditorGUILayout.GetControlRect();
  344. rect.width = EditorGUIUtility.labelWidth + 55f;
  345. s_TempLabel.text = label;
  346. float value = EditorGUI.FloatField(rect, s_TempLabel, property.floatValue);
  347. if (EndProperty())
  348. {
  349. property.floatValue = value;
  350. }
  351. }
  352. protected void DoColor(string name, string label)
  353. {
  354. MaterialProperty property = BeginProperty(name);
  355. s_TempLabel.text = label;
  356. Color value = EditorGUI.ColorField(EditorGUILayout.GetControlRect(), s_TempLabel, property.colorValue, false, true, true);
  357. if (EndProperty())
  358. {
  359. property.colorValue = value;
  360. }
  361. }
  362. void DoFloat(Rect rect, string name, string label)
  363. {
  364. MaterialProperty property = BeginProperty(name);
  365. s_TempLabel.text = label;
  366. float value = EditorGUI.FloatField(rect, s_TempLabel, property.floatValue);
  367. if (EndProperty())
  368. {
  369. property.floatValue = value;
  370. }
  371. }
  372. void DoFloat2(Rect rect, string name)
  373. {
  374. MaterialProperty property = BeginProperty(name);
  375. float x = EditorGUI.FloatField(rect, "X", property.vectorValue.x);
  376. rect.x += rect.width + 4f;
  377. float y = EditorGUI.FloatField(rect, "Y", property.vectorValue.y);
  378. if (EndProperty())
  379. {
  380. property.vectorValue = new Vector2(x, y);
  381. }
  382. }
  383. protected void DoOffset(string name, string label)
  384. {
  385. MaterialProperty property = BeginProperty(name);
  386. s_TempLabel.text = label;
  387. Vector2 value = EditorGUI.Vector2Field(EditorGUILayout.GetControlRect(), s_TempLabel, property.vectorValue);
  388. if (EndProperty())
  389. {
  390. property.vectorValue = value;
  391. }
  392. }
  393. protected void DoSlider(string name, string label)
  394. {
  395. MaterialProperty property = BeginProperty(name);
  396. Vector2 range = property.rangeLimits;
  397. s_TempLabel.text = label;
  398. float value = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, property.floatValue, range.x, range.y);
  399. if (EndProperty())
  400. {
  401. property.floatValue = value;
  402. }
  403. }
  404. protected void DoSlider(string name, Vector2 range, string label)
  405. {
  406. MaterialProperty property = BeginProperty(name);
  407. s_TempLabel.text = label;
  408. float value = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, property.floatValue, range.x, range.y);
  409. if (EndProperty())
  410. {
  411. property.floatValue = value;
  412. }
  413. }
  414. protected void DoSlider(string propertyName, string propertyField, string label)
  415. {
  416. MaterialProperty property = BeginProperty(propertyName);
  417. Vector2 range = property.rangeLimits;
  418. s_TempLabel.text = label;
  419. Vector4 value = property.vectorValue;
  420. switch (propertyField)
  421. {
  422. case "X":
  423. value.x = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.x, range.x, range.y);
  424. break;
  425. case "Y":
  426. value.y = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.y, range.x, range.y);
  427. break;
  428. case "Z":
  429. value.z = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.z, range.x, range.y);
  430. break;
  431. case "W":
  432. value.w = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.w, range.x, range.y);
  433. break;
  434. }
  435. if (EndProperty())
  436. {
  437. property.vectorValue = value;
  438. }
  439. }
  440. protected void DoSlider(string propertyName, string propertyField, Vector2 range, string label)
  441. {
  442. MaterialProperty property = BeginProperty(propertyName);
  443. s_TempLabel.text = label;
  444. Vector4 value = property.vectorValue;
  445. switch (propertyField)
  446. {
  447. case "X":
  448. value.x = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.x, range.x, range.y);
  449. break;
  450. case "Y":
  451. value.y = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.y, range.x, range.y);
  452. break;
  453. case "Z":
  454. value.z = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.z, range.x, range.y);
  455. break;
  456. case "W":
  457. value.w = EditorGUI.Slider(EditorGUILayout.GetControlRect(), s_TempLabel, value.w, range.x, range.y);
  458. break;
  459. }
  460. if (EndProperty())
  461. {
  462. property.vectorValue = value;
  463. }
  464. }
  465. protected void DoVector2(string name, string label)
  466. {
  467. MaterialProperty property = BeginProperty(name);
  468. s_TempLabel.text = label;
  469. Vector4 value = EditorGUILayout.Vector3Field(s_TempLabel, property.vectorValue);
  470. if (EndProperty())
  471. {
  472. property.vectorValue = value;
  473. }
  474. }
  475. protected void DoVector3(string name, string label)
  476. {
  477. MaterialProperty property = BeginProperty(name);
  478. s_TempLabel.text = label;
  479. Vector4 value = EditorGUILayout.Vector3Field(s_TempLabel, property.vectorValue);
  480. if (EndProperty())
  481. {
  482. property.vectorValue = value;
  483. }
  484. }
  485. protected void DoVector(string name, string label, GUIContent[] subLabels)
  486. {
  487. MaterialProperty property = BeginProperty(name);
  488. Rect rect = EditorGUILayout.GetControlRect();
  489. s_TempLabel.text = label;
  490. rect = EditorGUI.PrefixLabel(rect, s_TempLabel);
  491. Vector4 vector = property.vectorValue;
  492. float[] values = s_TempFloats[subLabels.Length];
  493. for (int i = 0; i < subLabels.Length; i++)
  494. {
  495. values[i] = vector[i];
  496. }
  497. EditorGUI.MultiFloatField(rect, subLabels, values);
  498. if (EndProperty())
  499. {
  500. for (int i = 0; i < subLabels.Length; i++)
  501. {
  502. vector[i] = values[i];
  503. }
  504. property.vectorValue = vector;
  505. }
  506. }
  507. bool IsNewShader()
  508. {
  509. if (m_Material == null)
  510. return false;
  511. int currentShaderID = m_Material.shader.GetInstanceID();
  512. if (m_ShaderID == currentShaderID)
  513. return false;
  514. m_ShaderID = currentShaderID;
  515. return true;
  516. }
  517. void DoDragAndDropBegin()
  518. {
  519. m_DragAndDropMinY = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)).y;
  520. }
  521. void DoDragAndDropEnd()
  522. {
  523. Rect rect = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));
  524. Event evt = Event.current;
  525. if (evt.type == EventType.DragUpdated)
  526. {
  527. DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
  528. evt.Use();
  529. }
  530. else if (evt.type == EventType.DragPerform && Rect.MinMaxRect(rect.xMin, m_DragAndDropMinY, rect.xMax, rect.yMax).Contains(evt.mousePosition))
  531. {
  532. DragAndDrop.AcceptDrag();
  533. evt.Use();
  534. Material droppedMaterial = DragAndDrop.objectReferences[0] as Material;
  535. if (droppedMaterial && droppedMaterial != m_Material)
  536. {
  537. PerformDrop(droppedMaterial);
  538. }
  539. }
  540. else if (evt.type == EventType.DragExited)
  541. {
  542. if (IsNewShader())
  543. TMPro_EventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material);
  544. }
  545. }
  546. void PerformDrop(Material droppedMaterial)
  547. {
  548. Texture droppedTex = droppedMaterial.GetTexture(ShaderUtilities.ID_MainTex);
  549. if (!droppedTex)
  550. {
  551. return;
  552. }
  553. Texture currentTex = m_Material.GetTexture(ShaderUtilities.ID_MainTex);
  554. TMP_FontAsset requiredFontAsset = null;
  555. if (droppedTex != currentTex)
  556. {
  557. requiredFontAsset = TMP_EditorUtility.FindMatchingFontAsset(droppedMaterial);
  558. if (!requiredFontAsset)
  559. {
  560. return;
  561. }
  562. }
  563. foreach (GameObject o in Selection.gameObjects)
  564. {
  565. if (requiredFontAsset)
  566. {
  567. TMP_Text textComponent = o.GetComponent<TMP_Text>();
  568. if (textComponent)
  569. {
  570. Undo.RecordObject(textComponent, "Font Asset Change");
  571. textComponent.font = requiredFontAsset;
  572. }
  573. }
  574. TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(o, m_Material, droppedMaterial);
  575. EditorUtility.SetDirty(o);
  576. }
  577. }
  578. }
  579. }