Skip to content

Commit

Permalink
BindableRP compatible with UniRx
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 30, 2024
1 parent a0b24da commit f26c78a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace R3
public class SerializableReactiveProperty<T> : ReactiveProperty<T>, ISerializationCallbackReceiver
{
[SerializeField]
T serializableValue;
T value;

public SerializableReactiveProperty()
: base(default!)
Expand All @@ -25,7 +25,7 @@ public SerializableReactiveProperty(T value)

protected override void OnSetValue(T value)
{
serializableValue = value;
this.value = value;
}

public void OnBeforeSerialize()
Expand All @@ -34,7 +34,7 @@ public void OnBeforeSerialize()

public void OnAfterDeserialize()
{
OnNext(serializableValue); // force set and update
OnNext(this.value); // force set and update
}
}

Expand All @@ -45,7 +45,7 @@ internal class SerializableReactivePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var p = property.FindPropertyRelative("serializableValue");
var p = property.FindPropertyRelative("value");
if (p.propertyType == SerializedPropertyType.Quaternion)
{
label.text += "(EulerAngles)";
Expand All @@ -59,7 +59,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var p = property.FindPropertyRelative("serializableValue");
var p = property.FindPropertyRelative("value");
if (p.propertyType == SerializedPropertyType.Quaternion)
{
// Quaternion is Vector3(EulerAngles)
Expand Down
10 changes: 10 additions & 0 deletions src/R3.Unity/Assets/Scenes/NewBehaviourScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class NewBehaviourScript : MonoBehaviour
public SerializableReactiveProperty<FruitFlagsEnum> rpFlagsEnum;


public SerializableReactiveProperty<int> NANTOKAMARU;
//public NantonakuProperty NANTOKAMARU;


Button button;
Text text;

Expand Down Expand Up @@ -63,3 +67,9 @@ public enum FruitFlagsEnum
Grape = 2,
Orange = 4
}

[Serializable]
public class NantonakuProperty
{
public int value;
}
67 changes: 65 additions & 2 deletions src/R3.Unity/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,72 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
rpInt:
serializableValue: 1339
value: 1339
rpLong:
serializableValue: 183
value: 183
rpByte:
value: 0
rpFloat:
value: 3.55
rpDouble:
value: 0
rpString:
value:
rpBool:
value: 0
rpVector2:
value: {x: 0, y: 0}
rpVector2Int:
value: {x: 0, y: 0}
rpVector3:
value: {x: 0, y: 0, z: 0}
rpVector3Int:
value: {x: 0, y: 0, z: 0}
rpVector4:
value: {x: 0, y: 0, z: 0, w: 0}
rpColor:
value: {r: 0, g: 0, b: 0, a: 0}
rpRect:
value:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
rpBounds:
value:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
rpBoundsInt:
value:
m_Position: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 0}
rpQuaternion:
value: {x: 0, y: 0, z: 0, w: 0}
rpMatrix4x4:
value:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
rpEnum:
value: 0
rpFlagsEnum:
value: 0
NANTOKAMARU:
value: 747
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit f26c78a

Please sign in to comment.