UnityEssentials
Small but useful tools and features for Unity
DoN.cs
Go to the documentation of this file.
1 using System;
2 using UnityEngine.Events;
3 
4 namespace UnityEngine
5 {
9  [Serializable]
10  public class DoN
11  {
15  [Tooltip("The amount of times the events can be invoked")]
16  [SerializeField] public int invokingTimes = 1;
20  [NonSerialized] public int invokedTimes = 0;
24  [Tooltip("The events called at every invoke")]
25  [SerializeField] public UnityEvent calledEvent;
26 
27  public DoN(UnityAction unityAction, int invokingTimes)
28  {
29  UnityEvent unityEvent = new UnityEvent();
30  unityEvent.AddListener(unityAction);
31  this.calledEvent = unityEvent;
32  this.invokingTimes = invokingTimes;
33  }
34 
35  public DoN(UnityEvent calledEvent, int invokingTimes)
36  {
37  this.calledEvent = calledEvent;
38  this.invokingTimes = invokingTimes;
39  }
40 
44  public void Invoke()
45  {
47  {
48  calledEvent?.Invoke();
49  invokedTimes++;
50  }
51  }
52 
53  }
54 
55 }
Allows the limitation of how many times an event can be executed.
Definition: DoN.cs:11
int invokingTimes
The amount of times the events can be invoked.
Definition: DoN.cs:16
int invokedTimes
How many times the events have been invoked.
Definition: DoN.cs:20
DoN(UnityAction unityAction, int invokingTimes)
Definition: DoN.cs:27
DoN(UnityEvent calledEvent, int invokingTimes)
Definition: DoN.cs:35
UnityEvent calledEvent
The events called at every invoke.
Definition: DoN.cs:25
void Invoke()
Invokes all registered events callbacks (runtime and persistent).
Definition: DoN.cs:44