当前位置:网站首页>Unity tips for reducing the amount of code -- empty protection extension
Unity tips for reducing the amount of code -- empty protection extension
2022-07-01 09:28:00 【Thynn_】
In the process of writing code , There are many places that need air protection , Here's a tip to reduce the amount of code written , Here's the code
namespace UnityEngine.UI
{
public static class UIExtension
{
public static void SetActive(this GameObject go, bool bActive)
{
if(go == null)
{
// You can add null prompt logic here
return;
}
go.SetActive(bActive);
}
public static void SetActive(this Transform trans,bool bActive)
{
if(trans == null)
{
// You can add null prompt logic here
return;
}
trans.gameObject.SetActive(bActive);
}
}
}This code is for GameObject Of SetActive Method is empty protected , At the same time Transform Expanded , Other components can also be developed in a similar way .
边栏推荐
- Design and manufacture of simple digital display electronic scale
- 短路运算符惰性求值
- JS prototype inheritance can only inherit instances, not constructors
- Can diffusion models be regarded as an autoencoder?
- Vsync+ triple cache mechanism +choreographer
- Installation and use of NoSQL database
- 集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常
- 类加载
- NiO zero copy
- ES6-const本质与完全不可改实现(Object.freeze)
猜你喜欢

Understanding and implementation of AVL tree

Microcomputer principle - bus and its formation

Construction of esp8266 FreeRTOS development environment

Structure de l'arbre - - - arbre binaire 2 traversée non récursive

MapReduce programming basics

Phishing identification app

2.4 activation function

NoSQL数据库的安装和使用

js作用域链与闭包
![[pytorch] softmax function](/img/97/b8ae22e8496a77e665d716cb0e9ee3.png)
[pytorch] softmax function
随机推荐
delete和delete[]引发的问题
ESP8266 FreeRTOS开发环境搭建
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
NoSQL数据库的安装和使用
Analysis and solution of JS this loss
SQL learning notes (02) - database table operation
Promise asynchronous programming
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + MQ Series + nodejs local service + MySQL storage
Understand shallow replication and deep replication through code examples
Installation and use of NoSQL database
类加载
Design and manufacture of simple digital display electronic scale
SQL learning notes (01) - basic knowledge of database
ES6 decoupling top-level objects from windows
An overview of the design of royalties and service fees of mainstream NFT market platforms
Microcomputer principle - bus and its formation
短路运算符惰性求值
js this丢失问题分析 及 解决方案
node. How to implement the SQL statement after JS connects to the database?
JS variable lifting