Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ClickAction.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. /// <summary>
  6. /// Represents an Action to process when the user clicks a particular mouse button a certain number of times.
  7. /// </summary>
  8. public class ClickAction : HoveredControlAction
  9. {
  10. private int m_Button;
  11. private bool m_UseEvent;
  12. /// <summary>
  13. /// The number of button clicks required to satisfy the trigger condition
  14. /// </summary>
  15. public int clickCount = 1;
  16. /// <summary>
  17. /// The Action to execute when the user satisfies the trigger condition.
  18. /// </summary>
  19. public Action<IGUIState, Control> onClick;
  20. private int m_ClickCounter = 0;
  21. /// <summary>
  22. /// Initializes and returns an instance of ClickAction
  23. /// </summary>
  24. /// <param name="control">Current control</param>
  25. /// <param name="button">The mouse button to check for.</param>
  26. /// <param name="useEvent">Whether to Use the current event after the trigger condition has been met.</param>
  27. public ClickAction(Control control, int button, bool useEvent = true) : base(control)
  28. {
  29. m_Button = button;
  30. m_UseEvent = useEvent;
  31. }
  32. /// <summary>
  33. /// Checks to see if the trigger condition has been met or not.
  34. /// </summary>
  35. /// <param name="guiState">The current state of the custom editor.</param>
  36. /// <returns>Returns `true` if the trigger condition has been met. Otherwise, returns false.</returns>
  37. protected override bool GetTriggerContidtion(IGUIState guiState)
  38. {
  39. if (guiState.mouseButton == m_Button && guiState.eventType == EventType.MouseDown)
  40. {
  41. if (guiState.clickCount == 1)
  42. m_ClickCounter = 0;
  43. ++m_ClickCounter;
  44. if (m_ClickCounter == clickCount)
  45. return true;
  46. }
  47. return false;
  48. }
  49. /// <summary>
  50. /// Calls the methods in its invocation list when the trigger conditions are met.
  51. /// </summary>
  52. /// <param name="guiState">The current state of the custom editor.</param>
  53. protected override void OnTrigger(IGUIState guiState)
  54. {
  55. base.OnTrigger(guiState);
  56. if (onClick != null)
  57. onClick(guiState, hoveredControl);
  58. if (m_UseEvent)
  59. guiState.UseEvent();
  60. }
  61. /// <summary>
  62. /// Checks to see if the finish condition has been met or not. For a ClickAction, this is always `true`.
  63. /// </summary>
  64. /// <param name="guiState">The current state of the custom editor.</param>
  65. /// <returns>Returns `true`.</returns>
  66. protected override bool GetFinishContidtion(IGUIState guiState)
  67. {
  68. return true;
  69. }
  70. }
  71. }