R3(原UniRX)在unity中的安装

先贴各种网址

Githubicon-default.png?t=N7T8https://github.com/Cysharp/R3.gitunity安装方法icon-default.png?t=N7T8https://github.com/Cysharp/R3?tab=readme-ov-file#unityR3文档icon-default.png?t=N7T8https://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

项目地址:NuGetForUnityicon-default.png?t=N7T8https://github.com/GlitchEnzo/NuGetForUnity

 包发布地址:NuGetForUnity releasesicon-default.png?t=N7T8https://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,这个也差不多。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值