GenericControl.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. public class GenericControl : Control
  6. {
  7. public Func<IGUIState, LayoutData> onBeginLayout;
  8. public Action<IGUIState> onEndLayout;
  9. public Action<IGUIState, Control, int> onRepaint;
  10. public Func<int> count;
  11. public Func<int, Vector3> position;
  12. public Func<IGUIState, int, float> distance;
  13. public Func<int, Vector3> forward;
  14. public Func<int, Vector3> up;
  15. public Func<int, Vector3> right;
  16. public Func<int, object> userData;
  17. public GenericControl(string name) : base(name)
  18. {
  19. }
  20. protected override int GetCount()
  21. {
  22. if (count != null)
  23. return count();
  24. return base.GetCount();
  25. }
  26. protected override void OnEndLayout(IGUIState guiState)
  27. {
  28. if (onEndLayout != null)
  29. onEndLayout(guiState);
  30. }
  31. protected override void OnRepaint(IGUIState guiState, int index)
  32. {
  33. if (onRepaint != null)
  34. onRepaint(guiState, this, index);
  35. }
  36. protected override LayoutData OnBeginLayout(LayoutData data, IGUIState guiState)
  37. {
  38. if (onBeginLayout != null)
  39. return onBeginLayout(guiState);
  40. return data;
  41. }
  42. protected override Vector3 GetPosition(IGUIState guiState, int index)
  43. {
  44. if (position != null)
  45. return position(index);
  46. return base.GetPosition(guiState,index);
  47. }
  48. protected override float GetDistance(IGUIState guiState, int index)
  49. {
  50. if (distance != null)
  51. return distance(guiState, index);
  52. return base.GetDistance(guiState, index);
  53. }
  54. protected override Vector3 GetForward(IGUIState guiState, int index)
  55. {
  56. if (forward != null)
  57. return forward(index);
  58. return base.GetForward(guiState,index);
  59. }
  60. protected override Vector3 GetUp(IGUIState guiState, int index)
  61. {
  62. if (up != null)
  63. return up(index);
  64. return base.GetUp(guiState,index);
  65. }
  66. protected override Vector3 GetRight(IGUIState guiState, int index)
  67. {
  68. if (right != null)
  69. return right(index);
  70. return base.GetRight(guiState,index);
  71. }
  72. protected override object GetUserData(IGUIState guiState, int index)
  73. {
  74. if (userData != null)
  75. return userData(index);
  76. return base.GetUserData(guiState,index);
  77. }
  78. }
  79. }