先贴各种网址
Githubhttps://github.com/Cysharp/R3.gitunity安装方法
https://github.com/Cysharp/R3?tab=readme-ov-file#unityR3文档
https://filzrev.github.io/R3/articles/index.html#classmethod-name-changes-from-dotnetreactive-and-neueccunirx
原来的UniRX已经停止维护,Unity商城最后是在2019提交,Github库也已经于2024年2月份归档
目前新项目名叫R3
将不再局限于unity平台,支持更多平台
安装
R3 的最低 Unity 支持是Unity 2021.3版本,团结基于2022版本,理论上也是支持的。
安装分为两步,安装NuGetForUnity和导入R3包
安装NuGetForUnity
项目地址:NuGetForUnityhttps://github.com/GlitchEnzo/NuGetForUnity
包发布地址:NuGetForUnity releaseshttps://github.com/GlitchEnzo/NuGetForUnity/releases/tag/v4.0.2
从 git URL 添加包...
https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity
把包导入到Unity内,
自带的包地址在国内访问可能有问题,即打开manager时没有包以及报错,
去NuGet设置一个新地址,
https://www.nuget.org/api/v2/
然后打开manager NuGet Packages,在Search内搜索R3,下拉找到R3包
点击R3然后Install
导入R3包
https://github.com/Cysharp/R3.git?path=src/R3.Unity/Assets/R3.Unity
指定版本包,#1.0.0是版本
https://github.com/Cysharp/R3.git?path=src/R3.Unity/Assets/R3.Unity#1.0.0
使用
在使用时需要进行一次全局初始化默认参数(必须)
不需要特意调用,启动时会自动回调。
using System;
using R3;
using UnityEngine;
namespace Script.AOT.Main
{
/// <summary>
/// 初始化R3响应式编程
/// </summary>
public static class UnityProviderInitializer
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
public static void SetDefaultObservableSystem()
{
SetDefaultObservableSystem(static ex => UnityEngine.Debug.LogException(ex));
}
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = UnityTimeProvider.Update;
ObservableSystem.DefaultFrameProvider = UnityFrameProvider.Update;
}
}
}
使用时和UniRX用法大体一致,其中更改了函数名,,这是官方函数名对照表:
所以只要会原来的UniRX,这个也差不多。