Skip to content

Commit a7c3d75

Browse files
committed
Base variable. Default game event.
1 parent 4ab8a9e commit a7c3d75

File tree

9 files changed

+53
-65
lines changed

9 files changed

+53
-65
lines changed

Runtime/Variables/BaseVariable.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Gameframe.ScriptableObjects.Events;
2+
using UnityEngine;
3+
4+
namespace Gameframe.ScriptableObjects.Variables
5+
{
6+
public class BaseVariable : ScriptableObject
7+
{
8+
[SerializeField]
9+
protected GameEvent onValueChanged;
10+
11+
public GameEvent OnValueChanged
12+
{
13+
get
14+
{
15+
if (onValueChanged == null)
16+
{
17+
onValueChanged = CreateInstance<GameEvent>();
18+
}
19+
return onValueChanged;
20+
}
21+
}
22+
}
23+
}
24+

Runtime/Variables/BaseVariable.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.

Runtime/Variables/ColorVariable.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using Gameframe.ScriptableObjects.Events;
1+
using Gameframe.ScriptableObjects.Events;
42
using UnityEngine;
53

64
namespace Gameframe.ScriptableObjects.Variables
75
{
86
[CreateAssetMenu(menuName=MenuNames.Variables+"Color")]
9-
public class ColorVariable : ScriptableObject, IVariable<Color>
7+
public class ColorVariable : BaseVariable, IVariable<Color>
108
{
119
[SerializeField]
1210
private Color value;
@@ -25,8 +23,5 @@ public Color Value
2523
}
2624
}
2725
}
28-
29-
[SerializeField]
30-
private GameEvent onValueChanged;
3126
}
3227
}

Runtime/Variables/FloatVariable.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using Gameframe.ScriptableObjects.Events;
4-
using UnityEngine;
1+
using UnityEngine;
52

63
namespace Gameframe.ScriptableObjects.Variables
74
{
85
[CreateAssetMenu(menuName=MenuNames.Variables+"Float")]
9-
public class FloatVariable : ScriptableObject, IVariable<float>
6+
public class FloatVariable : BaseVariable, IVariable<float>
107
{
118
[SerializeField]
129
private float value;
@@ -25,8 +22,5 @@ public float Value
2522
}
2623
}
2724
}
28-
29-
[SerializeField]
30-
private GameEvent onValueChanged;
3125
}
3226
}

Runtime/Variables/GameObjectVariable.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,14 @@
55
namespace Gameframe.ScriptableObjects.Variables
66
{
77
[CreateAssetMenu(menuName=MenuNames.Variables+"GameObject")]
8-
public class GameObjectVariable : ScriptableObject, IVariable<GameObject>
8+
public class GameObjectVariable : BaseVariable, IVariable<GameObject>
99
{
1010
[SerializeField]
1111
private bool clearOnEnable = false;
1212

1313
[SerializeField]
1414
private GameObject gameObject = null;
1515

16-
[SerializeField]
17-
private GameEvent onValueChanged = null;
18-
19-
[SerializeField]
20-
private UnityEvent valueChanged = new UnityEvent();
21-
public UnityEvent OnValueChanged => valueChanged;
22-
2316
public GameObject Value
2417
{
2518
get => gameObject;
@@ -28,8 +21,10 @@ public GameObject Value
2821
if (gameObject != value)
2922
{
3023
gameObject = value;
31-
valueChanged.Invoke();
32-
onValueChanged?.Raise();
24+
if (onValueChanged != null)
25+
{
26+
onValueChanged.Raise();
27+
}
3328
}
3429
}
3530
}
@@ -41,15 +36,6 @@ private void OnEnable()
4136
Value = null;
4237
}
4338
}
44-
45-
public void RaisedPropertyChanged()
46-
{
47-
onValueChanged.Raise();
48-
}
49-
50-
public void Clear()
51-
{
52-
Value = null;
53-
}
39+
5440
}
5541
}

Runtime/Variables/IntVariable.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using Gameframe.ScriptableObjects.Events;
4-
using UnityEngine;
1+
using UnityEngine;
52

63
namespace Gameframe.ScriptableObjects.Variables
74
{
85
[CreateAssetMenu(menuName = MenuNames.Variables+"Int")]
9-
public class IntVariable : ScriptableObject, IVariable<int>
6+
public class IntVariable : BaseVariable, IVariable<int>
107
{
118
[SerializeField]
129
private int value;
@@ -25,8 +22,5 @@ public int Value
2522
}
2623
}
2724
}
28-
29-
[SerializeField]
30-
private GameEvent onValueChanged;
3125
}
3226
}

Runtime/Variables/StringVariable.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using Gameframe.ScriptableObjects.Events;
4-
using UnityEngine;
1+
using UnityEngine;
52

63
namespace Gameframe.ScriptableObjects.Variables
74
{
85
[CreateAssetMenu(menuName = MenuNames.Variables+"String")]
9-
public class StringVariable : ScriptableObject, IVariable<string>
6+
public class StringVariable : BaseVariable, IVariable<string>
107
{
118
[SerializeField]
129
private string value;
@@ -25,8 +22,5 @@ public string Value
2522
}
2623
}
2724
}
28-
29-
[SerializeField]
30-
private GameEvent onValueChanged;
3125
}
3226
}

Runtime/Variables/Vector2Variable.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using Gameframe.ScriptableObjects.Events;
4-
using UnityEngine;
1+
using UnityEngine;
52

63
namespace Gameframe.ScriptableObjects.Variables
74
{
85
[CreateAssetMenu(menuName = MenuNames.Variables+"Vector2")]
9-
public class Vector2Variable : ScriptableObject, IVariable<Vector2>
6+
public class Vector2Variable : BaseVariable, IVariable<Vector2>
107
{
118
[SerializeField]
129
private Vector2 value;
@@ -25,8 +22,5 @@ public Vector2 Value
2522
}
2623
}
2724
}
28-
29-
[SerializeField]
30-
private GameEvent onValueChanged;
3125
}
3226
}

Runtime/Variables/Vector3Variable.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using Gameframe.ScriptableObjects.Events;
2-
using UnityEngine;
1+
using UnityEngine;
32

43
namespace Gameframe.ScriptableObjects.Variables
54
{
65
[CreateAssetMenu(menuName=MenuNames.Variables+"Vector3")]
7-
public class Vector3Variable : ScriptableObject, IVariable<Vector3>
6+
public class Vector3Variable : BaseVariable, IVariable<Vector3>
87
{
98
[SerializeField]
109
private Vector3 value;
@@ -23,8 +22,5 @@ public Vector3 Value
2322
}
2423
}
2524
}
26-
27-
[SerializeField]
28-
private GameEvent onValueChanged;
2925
}
3026
}

0 commit comments

Comments
 (0)