【Unity】插件

UniTask

github原网址:https://github.com/Cysharp/UniTask

简单介绍:十分好用的协程插件,速度快,容错率高

安装方法:

方法一:

通过引用git URL安装

1
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask

如果提示导入出错,可以查看文章最后的处理方法

方法二:

Releases获取.unitypackage文件后直接导入


R3

github原网址:https://github.com/Cysharp/R3

简单介绍:十分好用的观察者事件监听插件

安装步骤:

  1. 需要先安装**NuGetForUnity** ,通过引用git URL安装

    1
    https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity

    如果提示导入出错,可以查看文章最后的处理方法

    也可以在Releases获取.unitypackage文件后直接导入

    安装好后Asset根目录会多出如下文件,不要移动任何文件的位置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Assets
    │ NuGet.config // 配置文件
    │ packages.config // 配置文件
    |
    ├─NuGet // 插件功能文件
    │ ├─Editor
    │ └─Resources
    |
    ├─Packages // 安装的NuGet包体位置
  2. 再安装R3,打开NuGetForUnity窗口 NuGet => Manage NuGet Packages 搜索 “R3” 并安装

  1. 最后再安装R3.Unity包,通过引用git URL安装

    1
    https://github.com/Cysharp/R3.git?path=src/R3.Unity/Assets/R3.Unity
  2. 为了获得更好的使用体验,还需要安装配套的**ObservableCollections**


Cinemachine

简介:Unity官方插件,十分强大的相机

通过名称安装

1
com.unity.cinemachine

ProBuilder

简介:Unity官方插件,可以捏一些简单的模型

通过名称安装

1
com.unity.probuilder

Newtonsoft Json

简介:Unity官方插件,十分强大的读写json插件

通过名称安装

1
com.unity.nuget.newtonsoft-json

在序列化的时候可能会有警告如下

1
JsonSerializationException: Self referencing loop detected for property 'normalized' with type 'UnityEngine.Vector3'. Path 'Data.1.pos.normalized.normalized'

这个警告是由于 JsonConvert.SerializeObject 在序列化对象时检测到了循环引用(Self-referencing loop)。具体来说,UnityEngine.Vector3 类型的 normalized 属性会返回一个新的 Vector3 对象,而这个对象又包含 normalized 属性,从而导致无限递归。

可以通过设置 JsonSerializerSettings 来忽略循环引用。

1
2
3
4
5
6
var settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore // 忽略循环引用
};
var json = JsonConvert.SerializeObject(monsterUtil, settings);
File.WriteAllText(streamingAssetsPath, json);

LitJson

目前支持全平台编译的json工具库比较有名的有三个,分别是:JsonUtility、newtonjson还有LitJson
其中newtonjson体积过于庞大(250k),而JsonUtility又不支持键值对。所以我们只能选择使用LitJson

LitJson

直接下载Releases的unitypackage,双击安装


其他插件

Platforms

简介:Unity官方插件,Build管理插件,Experimental实验性包体

通过名称安装

1
com.unity.platforms

使用方法:

  1. 创建配置资产,命名为BaseBuild

    Create - Build Confinguration - Enpty Build Configuration

  2. 设置配置

    再创建ClientBuildServerBuild并映射BaseBuild的设置

好吧,看了一下,这个插件能控制的设置少的可怜

但是可以一键打包,不用选择路径,直接放在Assets的同路径下的Builds文件中,并且下方可以显示报错信息


拉取GitHub的package超时解决方案

  1. https://www.ipaddress.com/website/输入github.com获取github的ip地址

  1. C:\Windows\System32\drivers\etc\hosts文件中添加

    1
    140.82.113.3	github.com
  2. 刷新DNS,在cmd中键入ipconfig /flushdns

问题因素排除

  1. 使用git config --global http.proxy查看是否有使用代理

  2. 如果使用了就删除代理git config -- global unset http.proxy