关注

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,这个也差不多。

转载自CSDN-专业IT技术社区

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/u011021975/article/details/137105486

评论

赞0

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--