暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SliderAction.cs 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. /// <summary>
  6. /// SliderAction implementation of a ClickAction
  7. /// </summary>
  8. public class SliderAction : ClickAction
  9. {
  10. private SliderData m_SliderData;
  11. /// <summary>
  12. /// Action for OnSliderBegin
  13. /// </summary>
  14. public Action<IGUIState, Control, Vector3> onSliderBegin;
  15. /// <summary>
  16. /// Action for OnSliderChanged
  17. /// </summary>
  18. public Action<IGUIState, Control, Vector3> onSliderChanged;
  19. /// <summary>
  20. /// Action for OnSliderEnd
  21. /// </summary>
  22. public Action<IGUIState, Control, Vector3> onSliderEnd;
  23. /// <summary>
  24. /// Initializes and returns an instance of SliderAction
  25. /// </summary>
  26. /// <param name="control">The control to execcute an action for on slide.</param>
  27. public SliderAction(Control control) : base(control, 0, false)
  28. {
  29. }
  30. /// <summary>
  31. /// Checks to see if the finish condition has been met or not.
  32. /// </summary>
  33. /// <param name="guiState">The current state of the custom editor.</param>
  34. /// <returns>Returns `true` if the finish condition has been met. Otherwise, returns `false`.</returns>
  35. protected override bool GetFinishContidtion(IGUIState guiState)
  36. {
  37. return guiState.eventType == EventType.MouseUp && guiState.mouseButton == 0;
  38. }
  39. /// <summary>
  40. /// Called when there is interaction with the slider. It updates the stored slider data with data post-interaction.
  41. /// </summary>
  42. /// <param name="guiState">The current state of the custom editor.</param>
  43. protected override void OnTrigger(IGUIState guiState)
  44. {
  45. base.OnTrigger(guiState);
  46. m_SliderData.position = hoveredControl.hotLayoutData.position;
  47. m_SliderData.forward = hoveredControl.hotLayoutData.forward;
  48. m_SliderData.right = hoveredControl.hotLayoutData.right;
  49. m_SliderData.up = hoveredControl.hotLayoutData.up;
  50. if (onSliderBegin != null)
  51. onSliderBegin(guiState, hoveredControl, m_SliderData.position);
  52. }
  53. /// <summary>
  54. /// Post-processing for when the slider interaction finishes.
  55. /// </summary>
  56. /// <param name="guiState">The current state of the custom editor.</param>
  57. protected override void OnFinish(IGUIState guiState)
  58. {
  59. if (onSliderEnd != null)
  60. onSliderEnd(guiState, hoveredControl, m_SliderData.position);
  61. guiState.UseEvent();
  62. guiState.Repaint();
  63. }
  64. /// <summary>
  65. /// Moves the slider to the new permission and executes `onSliderChanged` using the new position.
  66. /// </summary>
  67. /// <param name="guiState">The current state of the custom editor</param>
  68. protected override void OnPerform(IGUIState guiState)
  69. {
  70. Vector3 newPosition;
  71. var changed = guiState.Slider(ID, m_SliderData, out newPosition);
  72. if (changed)
  73. {
  74. m_SliderData.position = newPosition;
  75. if (onSliderChanged != null)
  76. onSliderChanged(guiState, hoveredControl, newPosition);
  77. }
  78. }
  79. }
  80. }