Skip to content

Commit f2a3654

Browse files
committed
Adding OnEnableEvent and OnDisableEvent
1 parent ef4246a commit f2a3654

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEngine.Events;
4+
5+
namespace DevLocker.Utils
6+
{
7+
public class OnDisableEvent : MonoBehaviour
8+
{
9+
public bool OnlyOnce = false;
10+
11+
[NonSerialized]
12+
public bool HasBeenDisabledOnce = false;
13+
14+
public UnityEvent DisableEvent;
15+
16+
void OnDisable()
17+
{
18+
if (OnlyOnce && HasBeenDisabledOnce)
19+
return;
20+
21+
DisableEvent?.Invoke();
22+
HasBeenDisabledOnce = true;
23+
}
24+
}
25+
}

Assets/DevLocker/Utils/OnDisableEvent.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEngine.Events;
4+
5+
namespace DevLocker.Utils
6+
{
7+
public class OnEnableEvent : MonoBehaviour
8+
{
9+
public bool OnlyOnce = false;
10+
11+
[NonSerialized]
12+
public bool HasBeenEnabledOnce = false;
13+
14+
public UnityEvent EnableEvent;
15+
16+
void OnEnable()
17+
{
18+
if (OnlyOnce && HasBeenEnabledOnce)
19+
return;
20+
21+
EnableEvent?.Invoke();
22+
HasBeenEnabledOnce = true;
23+
}
24+
}
25+
}

Assets/DevLocker/Utils/OnEnableEvent.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)