Unity性能优化 对象延迟创建
来源:互联网 发布:win10网络没有本地连接 编辑:程序博客网 时间:2024/05/22 13:51
///by邓陶然
using UnityEngine;public class LaterCreator : MonoBehaviour{public delegate GameObject CreatorCallBack();public CreatorCallBack _creatorCallBack;public System.Object CallBackObj; /// <summary> /// 获取已创建成功的对象。 /// </summary> public GameObject CreatedGameObject { get; private set; } private bool allreadyCreator; private UIWidget uiw;public UIPanel panel; public bool alwaysShow; private void Start (){if(panel == null){panel = GetComponentInParent<UIPanel>();}} /// <summary> /// 设置单元大小 /// </summary> /// <param name="size"></param>public void SetSize(Vector3 size){uiw = gameObject.AddComponent<UIWidget>();uiw.SetRect(0,0,size.x,size.y);// Update();}private void OnEnable(){if(panel == null){panel = GetComponentInParent<UIPanel>();}}private void Update (){if(IsInView()){if(allreadyCreator && CreatedGameObject != null){CreatedGameObject.SetActive(true);}else{if(_creatorCallBack != null && !allreadyCreator){ CreatedGameObject = _creatorCallBack(); allreadyCreator = true; }}}else{if(allreadyCreator && CreatedGameObject != null){ if (alwaysShow) { CreatedGameObject.SetActive(true); } else { CreatedGameObject.SetActive(false); }}}} public void Reflush(){Update();} /// <summary> /// 强制创建或使对象可见 /// </summary>public void ForceOpen(){if(allreadyCreator && CreatedGameObject != null){CreatedGameObject.SetActive(true);}else{if(_creatorCallBack != null && !allreadyCreator){CreatedGameObject = _creatorCallBack();allreadyCreator = true;}}} /// <summary> /// 是否在视图中可见 /// </summary> /// <returns></returns> private bool IsInView() { if (panel == null) { return false; } return panel.IsVisible(uiw); }}
阅读全文
0 0
- Unity性能优化 对象延迟创建
- 前端性能优化:创建对象
- (Unity优化) 对象池的创建
- 前端性能优化:创建对象二
- unity性能优化(一)
- unity性能优化(二)
- unity性能优化总结
- Unity性能优化
- unity 代码性能优化
- unity 性能优化
- unity性能优化
- Unity性能优化
- Unity性能优化
- Unity性能优化
- Unity性能优化
- Unity-性能优化测试
- Unity 性能优化
- unity性能优化
- 【《Real-Time Rendering 3rd》 提炼总结】(二) 第二章 · 图形渲染管线 The Graphics Rendering Pipeline
- strcmp源码解惑
- JAVA 对象引用,以及对象赋值
- Ambari--主机管理
- 今天开通了CNSD博客
- Unity性能优化 对象延迟创建
- spring boot + kafka 使用详细步骤
- Maven学习总结(四)——Maven核心概念
- Oracle goldengate 实现mysql到kafka同步配置
- Spark Streaming消息的传输与保证及编程示例
- 【《Real-Time Rendering 3rd》 提炼总结】(一) 全书知识点总览
- 自然语言分词处理,词频统计
- 有关NSValue
- Lambda 详解