diff --git a/Unity/Assets/Scripts/Runtime/RMC/[MyProject]/Scenes/Scene01_Intro.cs b/Unity/Assets/Scripts/Runtime/RMC/[MyProject]/Scenes/Scene01_Intro.cs index 9d1220a..6993a33 100644 --- a/Unity/Assets/Scripts/Runtime/RMC/[MyProject]/Scenes/Scene01_Intro.cs +++ b/Unity/Assets/Scripts/Runtime/RMC/[MyProject]/Scenes/Scene01_Intro.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using R3; using RMC.Audio; using RMC.MyProject.UI; using UnityEngine; @@ -27,12 +28,12 @@ public int Score { get { - return _score; + return _reactiveScore.Value; } set { - _score = value; - HudUI.ScoreLabel.text = $"Score: {_score:000}/{ScoreMax:000}"; + _reactiveScore.Value = value; + HudUI.ScoreLabel.text = $"Score: {_reactiveScore.Value:000}/{ScoreMax:000}"; } } @@ -102,11 +103,13 @@ private set private InputAction _toggleThemeInputAction; // Data - private int _score = 0; private int _lives = 0; private bool _isEnabledInput = true; private bool _isPlayerGrounded = false; + // R3 ReactiveProperty demonstration + private readonly ReactiveProperty _reactiveScore = new ReactiveProperty(0); + // Audio private const string PlayerResetAudioClip = "ItemRead01"; private const string GameWinAudioClip = "Music_Win01"; @@ -122,6 +125,12 @@ protected void Start() { Debug.Log($"{GetType().Name}.Start()"); + // R3 ReactiveProperty demonstration - Subscribe to score changes + _reactiveScore.Subscribe(newScore => + { + Debug.Log($"[R3 Demo] Score changed to: {newScore}"); + }).AddTo(this); + // Input _movePlayerInputAction = InputSystem.actions.FindAction("MovePlayer"); _jumpPlayerInputAction = InputSystem.actions.FindAction("JumpPlayer"); diff --git a/Unity/Packages/manifest.json b/Unity/Packages/manifest.json index 07cc287..9016856 100644 --- a/Unity/Packages/manifest.json +++ b/Unity/Packages/manifest.json @@ -1,5 +1,6 @@ { "dependencies": { + "com.cysharp.r3": "https://github.com/Cysharp/R3.git?path=src/R3.Unity/Assets/R3.Unity", "com.rmc.rmc-audio": "1.8.4", "com.rmc.rmc-core": "1.9.5", "com.rmc.rmc-readme": "1.2.2",