Skip to content

Conversation

Copy link

Copilot AI commented Aug 29, 2025

This PR adds Cysharp/R3 as a package dependency to demonstrate reactive programming patterns in Unity 6.x. R3 provides powerful reactive extensions including ReactiveProperty for creating observable data that can trigger side effects when values change.

Changes Made

Package Integration

  • Added com.cysharp.r3 to Unity Package Manager via Git URL https://github.com/Cysharp/R3.git
  • Updated assembly definition files (RMC.MyProject.Runtime.asmdef and test assembly) to include R3 references

Code Implementation

Modified Scene01_Intro.cs to demonstrate R3 ReactiveProperty usage:

// R3 Reactive Property Demo
private ReactiveProperty<int> _reactiveScore = new ReactiveProperty<int>(0);
private ReactiveProperty<int> _reactiveLives = new ReactiveProperty<int>(LivesMax);

// Subscribe to changes with automatic logging
_reactiveScore.Subscribe(newScore => 
{
    Debug.Log($"[R3 Demo] Reactive Score changed to: {newScore}");
    HudUI.ScoreLabel.text = $"Score: {newScore:000}/{ScoreMax:000}";
}).AddTo(this);

The implementation showcases:

  • Reactive Data Binding: Score and lives properties automatically update UI when values change
  • Subscription Management: Uses .AddTo(this) for automatic disposal when GameObject is destroyed
  • Clean Resource Management: Proper disposal in OnDestroy() method
  • Unity 6.x Compatibility: Follows existing project patterns and coding standards

Testing

Created comprehensive unit tests (R3ReactivePropertyTest.cs) covering:

  • ReactiveProperty creation and disposal
  • Subscription triggering on value changes
  • Unity context integration with coroutines
  • Resource cleanup verification

Documentation

Updated README.md to include R3 in the Template Basics section with clear description of its reactive extensions capabilities.

Benefits

  • Reactive Programming: Enables reactive patterns for cleaner separation of data and UI updates
  • Performance: Efficient subscription-based updates only when values actually change
  • Maintainability: Reduces boilerplate code for property change notifications
  • Testing: Comprehensive test coverage ensures reliability

The implementation maintains the project's existing architecture while demonstrating modern reactive programming techniques suitable for Unity game development.

This pull request was created as a result of the following prompt from Copilot chat.

Add Cysharp/R3 as a package dependency to the Unity project.

  • Create a new branch for this work.
  • Add the R3 package using the recommended Unity Package Manager method (UPM via Git URL).
  • Ensure the project compiles successfully after the addition.
  • Demonstrate usage: Add a Cysharp.R3.ReactiveProperty instance to any existing MonoBehaviour subclass (for example, Scene01_Intro.cs). Implement a simple value assignment and subscription to show that it works (e.g., log a message when the property changes).
  • Include all necessary using statements and ensure the demo code is Unity 6.x compliant, matching the ProjectVersion.txt.
  • Provide a summary of changes in the PR description.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 29, 2025 16:48
Co-authored-by: SamuelAsherRivello <63511769+SamuelAsherRivello@users.noreply.github.com>
Co-authored-by: SamuelAsherRivello <63511769+SamuelAsherRivello@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Cysharp/R3 package and demonstrate ReactiveProperty usage Add Cysharp/R3 reactive extensions package with ReactiveProperty demonstration Aug 29, 2025
Copilot finished work on behalf of SamuelAsherRivello August 29, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants