-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariableDisplay.cs
49 lines (42 loc) · 1.3 KB
/
VariableDisplay.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
using System;
using Screenplay.Variables;
using TMPro;
using UnityEngine;
namespace Screenplay
{
public class VariableDisplay : MonoBehaviour, IValueReadWriter
{
public TMP_Text Text;
public UInterface<IVariable> Variable;
object _variableCache;
void Update() => Variable.Reference.ReadWrite(this);
public void ReadWriteValue<T>(ref T value)
{
if (_variableCache is VariableCache<IEquatable<T>> cache)
{
if (cache.CacheValue.Equals(value) == false)
{
cache.CacheValue = (IEquatable<T>)value;
Text.text = value.ToString();
}
return;
}
if (value is IEquatable<T> equatableValue)
{
_variableCache = new VariableCache<IEquatable<T>> { CacheValue = equatableValue };
Text.text = value.ToString();
return;
}
if (_variableCache is not T || (_variableCache is T t && t.Equals(value) == false))
{
_variableCache = value;
Text.text = value.ToString();
return;
}
}
class VariableCache<T>
{
public T CacheValue;
}
}
}