ExternalNode.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace WXB
  6. {
  7. public interface IExternalNode
  8. {
  9. // 删除
  10. void OnDestroy();
  11. void OnRender(Owner owner, Rect rect);
  12. float width { get; }
  13. float height { get; }
  14. }
  15. public class RectTransformNode : IExternalNode
  16. {
  17. RectTransform root;
  18. public RectTransformNode(RectTransform root)
  19. {
  20. this.root = root;
  21. root.pivot = new Vector2(0, 1);
  22. root.anchorMin = new Vector2(0, 1);
  23. root.anchorMax = new Vector2(0, 1);
  24. this.root.gameObject.SetActive(true);
  25. }
  26. // 删除
  27. void IExternalNode.OnDestroy()
  28. {
  29. if (root != null)
  30. {
  31. UnityEngine.Object.Destroy(root.gameObject);
  32. //root.gameObject.SetActive(false);
  33. }
  34. }
  35. void IExternalNode.OnRender(Owner owner, Rect rect)
  36. {
  37. if (root != null)
  38. {
  39. root.anchoredPosition = new Vector2(rect.x, -rect.y);
  40. }
  41. }
  42. float IExternalNode.width { get { return root.sizeDelta.x; } }
  43. float IExternalNode.height { get { return root.sizeDelta.y; } }
  44. }
  45. // 外部结点
  46. public class ExternalNode : RectNode
  47. {
  48. public void Set(IExternalNode node)
  49. {
  50. this.node = node;
  51. }
  52. IExternalNode node;
  53. public override float getHeight()
  54. {
  55. return node.height;
  56. }
  57. public override float getWidth()
  58. {
  59. return node.width;
  60. }
  61. public override void Release()
  62. {
  63. base.Release();
  64. if (node != null)
  65. node.OnDestroy();
  66. node = null;
  67. }
  68. protected override void OnRectRender(RenderCache cache, Line line, Rect rect)
  69. {
  70. node.OnRender(owner, rect);
  71. }
  72. };
  73. }