选自过去1~2周的内容: https://twitter.com/unity3d
1 ) 点击特效居然使用RT, 偶偶,因为UI是在 Overlay层。 不可以把特效也变为Overlay层么?
https://qiita.com/jnhtt/items/3890ea7a6570a8e7747d
使用RT 的好处, 可以在UI中间穿插因为是 RawImage 组件。不好的就是性能呗
设置: Canvas-RenderMode-Screen Space-Camera
public void OnDrag(PointerEventData eventData)
{
Vector2 localPos = Vector2.zero;
var ii =RectTransformUtility.ScreenPointToLocalPointInRectangle(
transform .parent .GetComponent<RectTransform>(),
eventData.position,
Camera.main,
out localPos
);
_transform.localPosition = localPos;
}
// 将屏幕空间点转换为RectTransform的局部空间中位于其矩形平面上的位置。
Unity官方文档中: 特别优化: https://docs.unity3d.com/2018.2/Documentation/Manual/BestPracticeUnderstandingPerformanceInUnity8.html
“Application.backgroundLoadingPriority”,可以更改在后台读取数据时可在一帧内使用的最长时间。
受影响的API 有:
- Resources.LoadAsync
- AssetBundle.LoadAssetAsync
- AssetBundle.LoadAllAssetAsync
- SceneManager.LoadSceneAsync
枚举 |
最大时间 |
ThreadPriority.Low |
2毫秒 |
ThreadPriority.BelowNormal |
4毫秒 |
ThreadPriority.Normal |
10毫秒 |
ThreadPriority.High |
50毫秒 |
using UnityEngine;
public class Example : MonoBehaviour
{
private void Awake()
{
//加载尽可能多的数据
//因此,帧速率可能会降低
//适用于显示进度条的场景
Application.backgroundLoadingPriority = ThreadPriority.High;
//慢慢读取数据,
//不影响游戏性能
//适合在游戏过程中在后台加载场景
Application.backgroundLoadingPriority = ThreadPriority.Low;
}
}
文章中还提到了 特效缓存池 的 问题~~
“AsyncOperation.priority”允许您设置异步加载的优先级
https://docs.unity3d.com/2018.2/Documentation/ScriptReference/AsyncOperation-priority.html
var operation = SceneManager.LoadSceneAsync(“Hoge”);
operation.priority = 10 ;
如果有多个异步操作出现在队列中,那些更高的优先级是先在运行
过程已经开始,你一定要注意,如果你改变了优先级并不反映
yield return 0生成20B的GC Alloc
实验环境:Unity 2017.4.7f1
using System.Collections;
using UnityEngine;
public class Example : MonoBehaviour
{
private IEnumerator Start()
{
while ( true )
{
yield return 0;
}
}
}
但是 yield return null 就没有发生GC Alloc
同样环境测试: UnityEngine.Object.name会导致生成46 B的GC Alloc
using UnityEngine;
public class Example : MonoBehaviour
{
private void Update()
{
var name = gameObject.name;
}
}
GameObject.tag时出现42B的GC Alloc
using UnityEngine;
public class Example : MonoBehaviour
{
private void Update()
{
var tag = gameObject.tag;
}
}
减少GC 建议: http://baba-s.hatenablog.com/entry/2018/11/12/150500
Standalone平台 如何防止在构建的游戏中输出output_log.txt
PlayerSetting 中取消选中就可以了~
而且这个Log 在 : C:\ Users \电脑用户名\ AppData \ LocalLow \【公司名称】\【产品名称】
推荐库: https://github.com/KLab/klab-messagebuses-unity
发送示例:
public sealed class MyMessageBus : MessageBus<string> {}
public sealed class Sender : MonoBehaviour
{
private const string Message = "Hello, World!";
private MyMessageBus Bus { get; set; }
private void Start ()
{
Bus = MessageBus.GetBus<MyMessageBus>();
}
private void Update ()
{
Bus.Broadcast(Message);
}
}
接收示例:
public sealed class Receiver : MonoBehaviour
{
private void OnMessage(string message)
{
Debug.Log(message);
}
private void OnEnable()
{
MessageBus
.GetBus<MyMessageBus>()
.Connect(OnMessage);
}
private void OnDisable()
{
MessageBus
.GetBus<MyMessageBus>()
.Disconnect(OnMessage);
}
}
Unie 2018 LA 上,一个LOD and Culling Systems 的演讲 PPT
http://download.csdn.net/download/u010019717/10790598
https://www.dropbox.com/s/rznoyhg3xpvau00/culling.pptx?dl=0
今天我了解到你可以使用以下方法设置Vector3的值:
myVector.Set(x, y ,z);
代替:
myVector = new Vector3(x, y, z);
10、 “Unity-SlnGen”,它可以通过在Visual Studio和Rider编辑器上切换平台来检查代码是否又报错
https://github.com/jhett12321/Unity-SlnGen
11、 Unity 2018.3.0 b 8新功能“NET_LEGACY”符号对使用.NET 3.5的项目有效
using UnityEngine;
public class Example : MonoBehaviour
{
private void Awake()
{
#if NET_LEGACY
Debug.Log( ".NET 3.5" );
#endif
}
}
12、 Unity 2019.1.0a 9新功能现在可以在 “Scene” 视图中更改摄像机的FOV
13、 Unity 2019.1.0a 9新功能现在可以在场景视图中使用Easing进行相机操作
通过从 “Unity菜单「Edit>Preferences...」 中选择 “Scene View” ,
可以在场景视图中设置是否使用Easing进行相机操作
14、 “UnityUIExtention”,它可以用uGUI反映多个对象上的Button的Color Transition
https://github.com/eral/UnityUIExtention
还有其它扩展。。。
15、 Unity 2018.3.0 b新功能「Managed Stripping Level」减少所有平台上的代码大小
Unity 2018.3.0b中添加了「Managed Stripping Level」
此功能
允许您减少所有平台上的代码大小
您可以通过从Unity菜单中的「File>Build Settings...」中选择「Player Settings...」,从「Other Settings」的“「Optimization」字段更改设置
16、 使用“Visual Studio IntelliCode”在Unity上编程 (AI 辅助开发)
因为常用功能在输入候选的开头显示★标记
要使用“Visual Studio IntelliCode” ,需要Visual Studio 2017的15.7版
插件: https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.VSIntelliCode
17、 Unity中有雾的窗口着色器
或者刮奖的实现:https://lindenreid.wordpress.com/2018/11/19/foggy-window-shader-in-unity/
18、只知道Unity的 GameObject.Instantiate 创建时传入Parent 比,创建完成后设置Parent性能 速度上快,不知道为什么, 今天看到文档的描述了: