目录
基础资料
Unity wiki 百科 :http://wiki.unity3d.com/index.php/Main_Page
http://wiki.unity3d.com/index.php/Category:C_Sharp
Unity 资源提取工具:UnityStudio
Unity 时序图:https://docs.unity3d.com/Manual/ExecutionOrder.html
Unity机器学习Github地址:https://github.com/Unity-Technologies/ml-agents
Unity项目单元测试工具:https://github.com/ThrowTheSwitch/Unity
Unity实验室:https://unity.com/cn/labs
Unity MARS 入门:https://docs.unity3d.com/cn/Packages/com.unity.mars@1.0/manual/GettingStarted.html
问题库
VSCode 工具
untiy 工具选择:https://code.visualstudio.com/docs/other/unity
常用插件:
- C# XML Documentation Comments
- Bracket Pair Colorizer
- C#
- Chinese (Simplified) Language Pack for Visual Studio Code
- Debugger for Unity
- Unity Tools
- Auto-Using for C#
运行 NuGet 包还原以生成此文件
TakePhoto Unity 拍照功能不能连续拍摄
unity特别说明了一下内容 StartPhotoModeAsync:在任何给定时间,只有一个PhohotCapture实列可以启动拍照模式。所以用线程安全的单例进行控制拍摄。
'PrefabUtility.GetPrefabType(Object)' is obsolete: 'Use GetPrefabAssetType
PrefabUtility.GetPrefabAssetType(go) == PrefabAssetType.Regular
游戏常用设计模式
FPS
[Header("是否显示帧率")] public bool IsShowFPS; void Update() { deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f; } void OnGUI() { if (IsShowFPS) { int w = Screen.width, h = Screen.height; GUIStyle style = new GUIStyle(); Rect rect = new Rect(20, 20, w, h * 2 / 100); style.alignment = TextAnchor.UpperLeft; style.fontSize = h * 2 / 80; //new Color (0.0f, 0.0f, 0.5f, 1.0f); style.normal.textColor = Color.red; float msec = deltaTime * 1000.0f; float fps = 1.0f / deltaTime; string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps); GUI.Label(rect, text, style); } }
内存泄漏问题
后来做完这次优化,我再次感受到,出现这些泄露的原因归根结底还是代码不够规范引起的,不注重必要的初始化和释放成对调用等,大致总结起来有以下几点:
- 错误使用了过多的
readonly,并且引用了其他的类型,甚至项目引用,最终形成引用环,并且环的某一个节点又被全局对象引用,造成“蝌蚪的尾巴被拴住”的情况,因此连带了很多的对象无法释放。 - 每一个类应该是有
Initialize就有Release,但实际情况大多是有Initialize而没有Release。 - 注意 Coroutine,如果使用了全局的
MonoBehaviour对象A去StartCoroutine其他对象B的函数,那么这时B对象会被A对象引用,如果协程为正确执行结束在无线等待,那么B也会永远被A对象引用而不得释放,即使StopAllCoroutine也不行。 - 慎用
Delegate,这时大家经常使用的功能,但是也容易造成内存泄露,如果只是+=而没有在合适的地方-=,那么代理的方法所属的对象是会被一直引用而无法释放的。
总结起来很简单,这次优化就大致发现这几条,但是都不经意间,日积月累,引起了比较严重的问题,所以不要小看代码规范,和框架的遵守。
Detecting current sdk build tools version
安卓平台发布卡住在Detecting 问题,原因网络问题,解决办法:
方法1:断开无线网发布。
方法2:修改网络属性的DNS服务器地址:首选地址:114,114,114,114。然后断网重连或者重启计算机。
Unity 配置Visual Studio 2022 环境
Editor→Preferences→External Tool→External Script Editor 选择vs安装路径。
打开PackageManager 选择Unity Registry 搜索 Visual Studio 安装Visual Studio Code Editor,Visual Studio Editor.
Unity 服务器 无界面模式
-batchmode -nographics
Vulkan detection: 0 No supported renderers found, exiting
Player→Vulkan Settings →select SRGB Write Mode*


