源战役客户端
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.

57 lines
1.4 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. #endif
  7. [RequireComponent(typeof(PolygonCollider2D))]
  8. [AddComponentMenu("UI/UIPolygon")]
  9. public class UIPolygon : Image
  10. {
  11. private PolygonCollider2D _polygon = null;
  12. private PolygonCollider2D polygon
  13. {
  14. get{
  15. if(_polygon == null )
  16. _polygon = GetComponent<PolygonCollider2D>();
  17. return _polygon;
  18. }
  19. }
  20. protected UIPolygon()
  21. {
  22. useLegacyMeshGeneration = true;
  23. }
  24. protected override void OnPopulateMesh(VertexHelper vh)
  25. {
  26. vh.Clear();
  27. }
  28. public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
  29. {
  30. return polygon.OverlapPoint( eventCamera.ScreenToWorldPoint(screenPoint));
  31. }
  32. #if UNITY_EDITOR
  33. protected override void Reset()
  34. {
  35. base.Reset();
  36. transform.localPosition = Vector3.zero;
  37. float w = (rectTransform.sizeDelta.x *0.5f) + 0.1f;
  38. float h = (rectTransform.sizeDelta.y*0.5f) + 0.1f;
  39. polygon.points = new Vector2[]
  40. {
  41. new Vector2(-w,-h),
  42. new Vector2(w,-h),
  43. new Vector2(w,h),
  44. new Vector2(-w,h)
  45. };
  46. }
  47. #endif
  48. }
  49. #if UNITY_EDITOR
  50. [CustomEditor(typeof(UIPolygon), true)]
  51. public class UIPolygonInspector : Editor
  52. {
  53. public override void OnInspectorGUI()
  54. {
  55. }
  56. }
  57. #endif