Skip to content

Commit 59a284e

Browse files
committed
Base variables now inherit from bindable scriptable object
1 parent adff6d3 commit 59a284e

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

Runtime/BindingSupport/BindableScriptableObject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
1717
/// <summary>
1818
/// Use this inside property setters to raise property changed events which are needed by bindingssss
1919
/// </summary>
20-
/// <param name="storage">storage location where value will be set</param>
20+
/// <param name="field">field to which the value will be set</param>
2121
/// <param name="value">value you want to assign to storage</param>
2222
/// <param name="propertyName">name of the property being set</param>
2323
/// <typeparam name="T">Type of the property being set</typeparam>
2424
/// <returns>True if property was set. False if it was already equal to the given value.</returns>
25-
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null )
25+
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null )
2626
{
27-
if (EqualityComparer<T>.Default.Equals(storage,value))
27+
if (EqualityComparer<T>.Default.Equals(field,value))
2828
{
2929
return false;
3030
}
31-
storage = value;
31+
field = value;
3232
OnPropertyChanged(propertyName);
3333
return true;
3434
}

Runtime/Variables/BaseVariable.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System;
22
using System.ComponentModel;
33
using System.Runtime.CompilerServices;
4+
using Gameframe.ScriptableObjects.BindingSupport;
45
using Gameframe.ScriptableObjects.Events;
56
using UnityEngine;
67

78
namespace Gameframe.ScriptableObjects.Variables
89
{
9-
public class BaseVariable : ScriptableObject, INotifyPropertyChanged
10+
public class BaseVariable : BindableScriptableObject
1011
{
1112
[SerializeField]
1213
protected GameEvent onValueChanged;
@@ -27,37 +28,15 @@ public GameEvent OnValueChanged
2728
/// INotifyPropertyChanged interface implemented to support Gameframe.Bindings
2829
/// </summary>
2930
#region INotifyPropertyChanged
30-
31-
public event PropertyChangedEventHandler PropertyChanged;
32-
33-
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
31+
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
3432
{
35-
try
36-
{
37-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
38-
}
39-
catch (Exception e)
40-
{
41-
Debug.LogException(e,this);
42-
}
33+
base.OnPropertyChanged(propertyName);
4334
if (onValueChanged != null)
4435
{
4536
onValueChanged.Raise();
4637
}
4738
}
48-
4939
#endregion
50-
51-
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
52-
{
53-
if (!Equals(field,value))
54-
{
55-
field = value;
56-
OnPropertyChanged(propertyName);
57-
return true;
58-
}
59-
return false;
60-
}
6140

6241
}
6342
}

0 commit comments

Comments
 (0)