-
Notifications
You must be signed in to change notification settings - Fork 0
/
SharedVariable.cs
113 lines (92 loc) · 1.76 KB
/
SharedVariable.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
namespace BehaviorTree
{
public abstract class SharedVariable
{
public bool IsShared
{
get => m_IsShared;
set => m_IsShared = value;
}
public bool IsGlobal
{
get => m_IsGlobal;
set => m_IsGlobal = value;
}
public string Name
{
get => m_Name;
set => m_Name = value;
}
public string PropertyMapping
{
get => m_PropertyMapping;
set => m_PropertyMapping = value;
}
public bool IsNone => m_IsShared && string.IsNullOrEmpty(m_Name);
public void ValueChanged()
{
}
public abstract object GetValue();
public abstract void SetValue(object value);
public abstract SharedVariable Clone();
[SerializeField]
protected bool m_IsShared;
[SerializeField]
protected bool m_IsGlobal;
[SerializeField]
protected string m_Name;
[SerializeField]
protected string m_PropertyMapping;
}
public abstract class SharedVariable<T> : SharedVariable
{
public T Value
{
get => (m_Getter == null) ? m_Value : m_Getter();
set
{
bool flag = !(m_Value?.Equals(value) ?? false);
if (m_Setter != null)
{
m_Setter(value);
}
else
{
m_Value = value;
}
if (flag)
{
ValueChanged();
}
}
}
public override object GetValue()
{
return Value;
}
public override void SetValue(object value)
{
if (m_Setter != null)
{
m_Setter((T)value);
}
else
{
m_Value = (T)value;
}
}
public override string ToString()
{
return Value?.ToString() ?? "(null)";
}
public override SharedVariable Clone()
{
return (SharedVariable)this.MemberwiseClone();
}
private Func<T> m_Getter;
private Action<T> m_Setter;
[SerializeField]
protected T m_Value;
}
}