AbstractBind.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. * Copyright (c) 2017 ~ 2021.1 liangxie
  3. *
  4. * http://qframework.io
  5. * https://github.com/liangxiegame/QFramework
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. ****************************************************************************/
  25. using UnityEngine;
  26. using UnityEngine.UI;
  27. namespace QFramework
  28. {
  29. public abstract class AbstractBind : MonoBehaviour, IBind
  30. {
  31. [HideInInspector] public BindType MarkType = BindType.DefaultUnityElement;
  32. public string Comment
  33. {
  34. get { return CustomComment; }
  35. }
  36. public Transform Transform
  37. {
  38. get { return transform; }
  39. }
  40. [HideInInspector] public string CustomComponentName;
  41. [HideInInspector] public string ComponentGeneratePath;
  42. [HideInInspector] public string CustomComment;
  43. public BindType GetBindType()
  44. {
  45. return MarkType;
  46. }
  47. [HideInInspector] [SerializeField] private string mComponentName;
  48. public virtual string ComponentName
  49. {
  50. get
  51. {
  52. if (MarkType == BindType.DefaultUnityElement)
  53. {
  54. if (string.IsNullOrEmpty(mComponentName))
  55. {
  56. mComponentName = GetDefaultComponentName();
  57. }
  58. return mComponentName;
  59. }
  60. return CustomComponentName;
  61. }
  62. set { mComponentName = value; }
  63. }
  64. string GetDefaultComponentName()
  65. {
  66. if (GetComponent<ViewController>()) return GetComponent<ViewController>().GetType().FullName;
  67. if (GetComponent("SkeletonAnimation")) return "SkeletonAnimation";
  68. if (GetComponent<ScrollRect>()) return "UnityEngine.UI.ScrollRect";
  69. if (GetComponent<InputField>()) return "UnityEngine.UI.InputField";
  70. // text mesh pro supported
  71. if (GetComponent("TMP.TextMeshProUGUI")) return "TMP.TextMeshProUGUI";
  72. if (GetComponent("TMPro.TextMeshProUGUI")) return "TMPro.TextMeshProUGUI";
  73. if (GetComponent("TMPro.TextMeshPro")) return "TMPro.TextMeshPro";
  74. if (GetComponent("TMPro.TMP_InputField")) return "TMPro.TMP_InputField";
  75. // ugui bind
  76. if (GetComponent<Dropdown>()) return "UnityEngine.UI.Dropdown";
  77. if (GetComponent<Button>()) return "UnityEngine.UI.Button";
  78. if (GetComponent<Text>()) return "UnityEngine.UI.Text";
  79. if (GetComponent<RawImage>()) return "UnityEngine.UI.RawImage";
  80. if (GetComponent<Toggle>()) return "UnityEngine.UI.Toggle";
  81. if (GetComponent<Slider>()) return "UnityEngine.UI.Slider";
  82. if (GetComponent<Scrollbar>()) return "UnityEngine.UI.Scrollbar";
  83. if (GetComponent<Image>()) return "UnityEngine.UI.Image";
  84. if (GetComponent<ToggleGroup>()) return "UnityEngine.UI.ToggleGroup";
  85. // other
  86. if (GetComponent<Rigidbody>()) return "Rigidbody";
  87. if (GetComponent<Rigidbody2D>()) return "Rigidbody2D";
  88. if (GetComponent<BoxCollider2D>()) return "BoxCollider2D";
  89. if (GetComponent<BoxCollider>()) return "BoxCollider";
  90. if (GetComponent<CircleCollider2D>()) return "CircleCollider2D";
  91. if (GetComponent<SphereCollider>()) return "SphereCollider";
  92. if (GetComponent<MeshCollider>()) return "MeshCollider";
  93. if (GetComponent<Collider>()) return "Collider";
  94. if (GetComponent<Collider2D>()) return "Collider2D";
  95. if (GetComponent<Animator>()) return "Animator";
  96. if (GetComponent<Canvas>()) return "Canvas";
  97. if (GetComponent<Camera>()) return "Camera";
  98. if (GetComponent("Empty4Raycast")) return "QFramework.Empty4Raycast";
  99. if (GetComponent<RectTransform>()) return "RectTransform";
  100. if (GetComponent<MeshRenderer>()) return "MeshRenderer";
  101. if (GetComponent<SpriteRenderer>()) return "SpriteRenderer";
  102. // NGUI 支持
  103. if (GetComponent("UIButton")) return "UIButton";
  104. if (GetComponent("UILabel")) return "UILabel";
  105. if (GetComponent("UISprite")) return "UISprite";
  106. if (GetComponent("UISlider")) return "UISlider";
  107. if (GetComponent("UITexture")) return "UITexture";
  108. return "Transform";
  109. }
  110. }
  111. }