RectNode.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace WXB
  6. {
  7. public abstract class RectNode : NodeBase
  8. {
  9. public float width = 0;
  10. public float height = 0;
  11. public override float getHeight()
  12. {
  13. return height;
  14. }
  15. public override float getWidth()
  16. {
  17. return width;
  18. }
  19. public override void Release()
  20. {
  21. base.Release();
  22. width = 0f;
  23. height = 0f;
  24. }
  25. protected abstract void OnRectRender(RenderCache cache, Line line, Rect rect);
  26. public override void render(float maxWidth, RenderCache cache, ref float x, ref uint yline, List<Line> lines, float offsetX, float offsetY)
  27. {
  28. float width = getWidth();
  29. float height = getHeight();
  30. if (x + width > maxWidth)
  31. {
  32. x = NextLineX;
  33. yline++;
  34. }
  35. float alignedX = AlignedFormatting(owner, formatting, maxWidth, lines[(int)(yline)].x, 0);
  36. float y_offset = offsetY;
  37. for (int i = 0; i < yline; ++i)
  38. y_offset += lines[i].y;
  39. //y_offset += lines[(int)(yline)].y;
  40. Rect areaRect = new Rect(x + offsetX + alignedX, y_offset, width, height);
  41. float newfx = 0f;
  42. while (!owner.around.isContain(areaRect, out newfx))
  43. {
  44. areaRect.x = newfx;
  45. x = newfx - alignedX - offsetX;
  46. if (x + width > maxWidth)
  47. {
  48. x = NextLineX;
  49. yline++;
  50. y_offset += lines[(int)yline].y;
  51. areaRect = new Rect(x + offsetX + alignedX, y_offset, width, height);
  52. }
  53. }
  54. OnRectRender(cache, lines[(int)yline], areaRect);
  55. x += width;
  56. if (d_bNewLine)
  57. {
  58. x = 0;
  59. yline++;
  60. }
  61. }
  62. };
  63. }