源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.2 KiB

  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEngine.UI;
  5. using System.Collections;
  6. public static class UIHelper{
  7. static UISetting globalSetting = ScriptableObject.CreateInstance<UISetting>();
  8. [MenuItem("GameObject/UI/Image")]
  9. static void CreateImage()
  10. {
  11. if (Selection.activeTransform)
  12. {
  13. if (Selection.activeTransform.GetComponentInParent<Canvas>())
  14. {
  15. GameObject go = new GameObject("image", typeof(Image));
  16. go.GetComponent<Image>().raycastTarget = false;
  17. go.transform.SetParent(Selection.activeTransform, false);
  18. Selection.activeGameObject = go;
  19. }
  20. }
  21. }
  22. [MenuItem("GameObject/UI/Raw Image")]
  23. static void CreateRawImage()
  24. {
  25. if (Selection.activeTransform)
  26. {
  27. if (Selection.activeTransform.GetComponentInParent<Canvas>())
  28. {
  29. GameObject go = new GameObject("rawImage", typeof(RawImage));
  30. go.GetComponent<RawImage>().raycastTarget = false;
  31. go.transform.SetParent(Selection.activeTransform, false);
  32. Selection.activeGameObject = go;
  33. }
  34. }
  35. }
  36. [MenuItem("GameObject/UI/Text")]
  37. static void CreateText()
  38. {
  39. if (Selection.activeTransform)
  40. {
  41. if (Selection.activeTransform.GetComponentInParent<Canvas>())
  42. {
  43. GameObject go = new GameObject("text", typeof(Text));
  44. go.GetComponent<Text>().raycastTarget = false;
  45. go.transform.SetParent(Selection.activeTransform, false);
  46. go.transform.localPosition = Vector3.zero;
  47. Selection.activeGameObject = go;
  48. }
  49. }
  50. }
  51. [MenuItem("GameObject/UI/CustomText")]
  52. static void CreateCustomText() {
  53. if (Selection.activeTransform)
  54. {
  55. if (Selection.activeTransform.GetComponentInParent<Canvas>())
  56. {
  57. GameObject go = new GameObject("text", typeof(Text));
  58. Text txt = go.GetComponent<Text>();
  59. txt.raycastTarget = false;
  60. txt.alignment = TextAnchor.MiddleCenter;
  61. txt.fontSize = 20;
  62. txt.horizontalOverflow = HorizontalWrapMode.Overflow;
  63. if (globalSetting.defaultFont != null) txt.font = globalSetting.defaultFont;
  64. go.transform.SetParent(Selection.activeTransform, false);
  65. Selection.activeGameObject = go;
  66. }
  67. }
  68. }
  69. [MenuItem("GameObject/UI/Text - TextMeshPro")]
  70. static void CreateTextMeshProUGUI() {
  71. if (Selection.activeTransform)
  72. {
  73. if (Selection.activeTransform.GetComponentInParent<Canvas>())
  74. {
  75. GameObject go = new GameObject("tmptext", typeof(TMPro.TextMeshProUGUI));
  76. TMPro.TextMeshProUGUI tmp = go.GetComponent<TMPro.TextMeshProUGUI>();
  77. tmp.raycastTarget = false;
  78. tmp.enableKerning = false;
  79. tmp.enableWordWrapping = false;
  80. go.transform.SetParent(Selection.activeTransform, false);
  81. Selection.activeGameObject = go;
  82. }
  83. }
  84. }
  85. }
  86. #endif