OnBecameVisible和OnBecameInvisible ,OnWillRenderObject

本文探讨了在游戏开发中如何利用Unity引擎的OnBecameVisible和OnBecameInvisible事件来优化渲染性能,以及OnWillRenderObject事件在可见性判断上的应用。通过这些事件,开发者可以实现仅在物体可见时执行特定计算,提高效率并减少资源消耗。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.cnblogs.com/wonderKK/p/4112304.html

OnBecameVisible 和 OnBecameInvisible ,OnWillRenderObject 只有在所挂物体(不包括子物体)有render才有效

//可见
private void OnBecameVisible()
{
_isVisible = true;
}
//不可见
private void OnBecameInvisible()
{
_isVisible = false;
}

 

MonoBehaviour.OnBecameVisible 当可见

 

function OnBecameVisible () : void

Description描述

OnBecameVisible is called when the renderer became visible by any camera.

当renderer(渲染器)在任何相机上可见时调用OnBecameVisible。

This message is sent to all scripts attached to the renderer. OnBecameVisible and OnBecameInvisible is useful to avoid computations that are only necessary when the object is visible.

这个消息发送到所有附在渲染器的脚本上。OnBecameVisible 和 OnBecameInvisible可以用于只需要在物体可见时才进行的计算。



OnBecameVisible 和 OnBecameInvisible ,OnWillRenderObject 只有在所挂物体(不包括子物体)有render才有效

//可见
private void OnBecameVisible()
{
_isVisible = true;
}
//不可见
private void OnBecameInvisible()
{
_isVisible = false;
}

 

MonoBehaviour.OnBecameVisible 当可见

 

function OnBecameVisible () : void

Description描述

OnBecameVisible is called when the renderer became visible by any camera.

当renderer(渲染器)在任何相机上可见时调用OnBecameVisible。

This message is sent to all scripts attached to the renderer. OnBecameVisible and OnBecameInvisible is useful to avoid computations that are only necessary when the object is visible.

这个消息发送到所有附在渲染器的脚本上。OnBecameVisible 和 OnBecameInvisible可以用于只需要在物体可见时才进行的计算。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值