EditorAuxiliary.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System.IO;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. [CustomEditor(typeof(Auxiliary))]
  8. public class EditorAuxiliary : Editor
  9. {
  10. #region 变量
  11. private Auxiliary Script;
  12. #endregion
  13. private void OnEnable()
  14. {
  15. Script = (Auxiliary) target;
  16. }
  17. public override void OnInspectorGUI()
  18. {
  19. base.OnInspectorGUI();
  20. if (GUILayout.Button("ChangeFont"))
  21. {
  22. ChangeFont();
  23. }
  24. if (GUILayout.Button("PrintBounds"))
  25. {
  26. PrintBounds();
  27. }
  28. if (GUILayout.Button("ChangePivot"))
  29. {
  30. ChangePivot();
  31. }
  32. if (GUILayout.Button("AddSuffix"))
  33. {
  34. AddSuffix();
  35. }
  36. if (GUILayout.Button("AddPrefix"))
  37. {
  38. AddPrefix();
  39. }
  40. if (GUILayout.Button("ChangePrefix"))
  41. {
  42. ChangePrefix();
  43. }
  44. if (GUILayout.Button("Reset"))
  45. {
  46. //ResetAll();
  47. }
  48. if (GUILayout.Button("Temp"))
  49. {
  50. Vector3 position = Script.GoList[0].GetChild(0).localPosition;
  51. for (int i = 1; i < Script.GoList.Count; i++)
  52. {
  53. Script.GoList[i].GetChild(0).localPosition = position;
  54. }
  55. }
  56. }
  57. private void ResetAll()
  58. {
  59. for (int i = 0; i < Script.GoList.Count; i++)
  60. {
  61. Text[] texts = Script.GoList[i].GetComponentsInChildren<Text>(true); ;
  62. Graphic[] graphics = Script.GoList[i].GetComponentsInChildren<Graphic>(true);
  63. for (int j = 0; j < texts.Length; j++)
  64. {
  65. texts[j].supportRichText = false;
  66. texts[j].verticalOverflow = VerticalWrapMode.Truncate;
  67. texts[j].horizontalOverflow = HorizontalWrapMode.Wrap;
  68. }
  69. for (int j = 0; j < graphics.Length; j++)
  70. {
  71. graphics[j].raycastTarget = true;
  72. }
  73. }
  74. }
  75. private void ChangeFont()
  76. {
  77. for (int j = 0; j < Script.GoList.Count; j++)
  78. {
  79. Transform[] transforms = Script.GoList[j].GetComponentsInChildren<Transform>(true);
  80. for (int i = 0; i < transforms.Length; i++)
  81. {
  82. Text text = transforms[i].GetComponent<Text>();
  83. TextMesh textMesh = transforms[i].GetComponent<TextMesh>();
  84. if (text != null)
  85. {
  86. text.font = Script.Font;
  87. text.fontStyle = FontStyle.Normal;
  88. }
  89. if (textMesh != null)
  90. {
  91. textMesh.font = Script.Font;
  92. textMesh.fontStyle = FontStyle.Normal;
  93. }
  94. }
  95. }
  96. }
  97. private void PrintBounds()
  98. {
  99. Bounds bounds = Script.Go.GetComponent<Renderer>().bounds;
  100. Debug.Log(string.Format("x : {0:0.00} y : {1:0.00} z : {2:0.00}", bounds.extents.x, bounds.extents.y, bounds.extents.z));
  101. }
  102. private void ChangePivot()
  103. {
  104. for (int i = 0; i < Script.SrList.Count; i++)
  105. {
  106. string path = AssetDatabase.GetAssetPath(Script.SrList[i].sprite);
  107. TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(path);
  108. float offsetX = -Script.SrList[i].transform.position.x * 100 / Script.SrList[i].sprite.texture.width;
  109. float offsetY = -Script.SrList[i].transform.position.y * 100 / Script.SrList[i].sprite.texture.height;
  110. textureImporter.spritePivot = new Vector2(textureImporter.spritePivot.x + offsetX, textureImporter.spritePivot.y + offsetY);
  111. AssetDatabase.ImportAsset(path);
  112. }
  113. }
  114. private void AddSuffix()
  115. {
  116. Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
  117. for (int i = 0; i < transforms.Length; i++)
  118. {
  119. transforms[i].name = transforms[i].name + Script.String;
  120. }
  121. }
  122. private void AddPrefix()
  123. {
  124. Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
  125. for (int i = 0; i < transforms.Length; i++)
  126. {
  127. transforms[i].name = Script.String + transforms[i].name;
  128. }
  129. }
  130. private void ChangePrefix()
  131. {
  132. Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
  133. for (int i = 0; i < transforms.Length; i++)
  134. {
  135. int index = transforms[i].name.IndexOf('_');
  136. transforms[i].name = Script.String + transforms[i].name.Remove(0, index + 1);
  137. }
  138. }
  139. }