-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeAnchorBase.cs
More file actions
41 lines (32 loc) · 1.03 KB
/
RuntimeAnchorBase.cs
File metadata and controls
41 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;
using UnityEngine.Events;
using Xprees.Core;
using Xprees.EditorTools.Attributes.ReadOnly;
namespace Xprees.RuntimeAnchors.Base
{
public class RuntimeAnchorBase<T> : DescriptionBaseSO where T : Object
{
public UnityAction onAnchorProvided;
[ReadOnly] [SerializeField] private T value;
public T Value => value;
[ReadOnly] public bool isSet; // Any script can check if the value is null before using it, by just checking this bool
public void Provide(T providedValue)
{
if (providedValue == null)
{
Debug.LogError($"A null value was provided to the {name} runtime anchor.");
return;
}
value = providedValue;
isSet = true;
onAnchorProvided?.Invoke();
}
public void Unset()
{
value = null;
isSet = false;
}
private void OnDisable() => ResetState();
public override void ResetState() => Unset();
}
}