-
Notifications
You must be signed in to change notification settings - Fork 0
/
CachedObjectReference.cs
59 lines (48 loc) · 1.42 KB
/
CachedObjectReference.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using MyBox;
using UnityEngine;
namespace Gemserk.Leopotam.Ecs
{
public enum ReferenceType
{
Default = 0,
Name = 1,
Tag = 2,
SameScene = 3,
SceneName = 4
}
[Serializable]
public class CachedObjectReference<T> where T: MonoBehaviour
{
public ReferenceType type;
[ConditionalField(nameof(type), false, ReferenceType.Name, ReferenceType.SceneName)]
public string name;
[ConditionalField(nameof(type), false, ReferenceType.Tag)]
[Tag]
public string tag;
public T GetReference(GameObject go = null)
{
if (type == ReferenceType.Default)
{
return CachedObjectBehaviour<T>.Default;
}
if (type == ReferenceType.Name)
{
return CachedObjectBehaviour<T>.GetByName(name);
}
if (type == ReferenceType.Tag)
{
return CachedObjectBehaviour<T>.GetByTag(tag);
}
if (type == ReferenceType.SameScene && go != null)
{
return CachedObjectBehaviour<T>.GetByScene(go.scene);
}
if (type == ReferenceType.SceneName)
{
return CachedObjectBehaviour<T>.GetBySceneName(name);
}
return null;
}
}
}