Skip to content

Commit 69e78be

Browse files
committed
Adding bindings support
1 parent d36514f commit 69e78be

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Editor/BindingSupport.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel;
3+
using System.Runtime.CompilerServices;
4+
using UnityEngine;
5+
6+
namespace Gameframe.ScriptableObjects.BindingSupport
7+
{
8+
public class BindableScriptableObject : ScriptableObject, INotifyPropertyChanged
9+
{
10+
public event PropertyChangedEventHandler PropertyChanged;
11+
12+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
13+
{
14+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
15+
}
16+
17+
/// <summary>
18+
/// Use this inside property setters to raise property changed events which are needed by bindingssss
19+
/// </summary>
20+
/// <param name="storage">storage location where value will be set</param>
21+
/// <param name="value">value you want to assign to storage</param>
22+
/// <param name="propertyName">name of the property being set</param>
23+
/// <typeparam name="T">Type of the property being set</typeparam>
24+
/// <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 )
26+
{
27+
if (EqualityComparer<T>.Default.Equals(storage,value))
28+
{
29+
return false;
30+
}
31+
storage = value;
32+
OnPropertyChanged(propertyName);
33+
return true;
34+
}
35+
}
36+
}

Editor/BindingSupport/BindableScriptableObject.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.

0 commit comments

Comments
 (0)