当前位置:网站首页>Unity中实现判断Missing还是Null
Unity中实现判断Missing还是Null
2022-07-23 00:16:00 【Hello Bug.】
一:前言
例如脚本丢失,贴图丢失,面板上会显示missing

通过==null判断两者都会返回true,但在有些情况下,需要判断是Missing还是Null,通过try-catch可以判断出具体是Missing还是Null
二:代码实现
public void CheckReference(UnityEngine.Object reference)
{
try
{
var name = reference.name;
}
//missing
catch (MissingReferenceException)
{
Debug.LogError("The provided reference is missing!");
}
catch (MissingComponentException)
{
Debug.LogError("The provided reference is missing!");
}
catch (UnassignedReferenceException)
{
Debug.LogWarning("The provided reference is null!");
}
catch (NullReferenceException)
{
Debug.LogWarning("The provided reference is null!");
}
catch (ArgumentNullException)
{
Debug.LogWarning("The provided reference is null!");
}
finally
{
}
}边栏推荐
- SQL Server 数据库设计--SELECT语句
- 数据可视化平台的下一站 | 来自国产开源数据可视化 datart「超级铁粉」的馈赠
- 亲情诈骗盛行,搜狗号码通筑安全防火墙
- Flutter 3.0
- uva1344
- Extend the maximum memory limit of canvas and the principle of browser rendering from a bug
- ospf综合实验配置
- Svg+canvas canvas track JS special effect
- Three schemes to realize finclip wechat authorized login
- uva1467
猜你喜欢
随机推荐
讲一讲HART协议
day3 poc与exp学习之pikachu带token的暴力破解
50道经典计算机网络面试题,你答得上几个?(二)
从一个 bug 中延伸出 canvas 最大内存限制和浏览器渲染原理
30行自己写并发工具类(Semaphore, CyclicBarrier, CountDownLatch)是什么体验?
启牛开户安全性高吗?说万3的佣金靠谱吗?
Practical exercise | a simple method for MySQL processlist table and Navicat monitor to identify slow queries
babylon.js炫酷canvas背景动画js特效
(动态规划例题)石子合并
SIP账号的作用-告诉你什么是SIP线路
DALSA智能相机BOA Spot与西门子S7-1200 Profinet通讯
网络同步IO模型——多路复用(IO Multiplexing)
【C语言】文件操作
HCIP第九天笔记(OSPF的路由回馈、路由策略、以及配置指南)
HCIP第十天(初始BGP边界网关协议)
Node definition and traversal of binary tree~
uva11389
mariadb相关说明
Basic operations of DDL and DML in SQL (database)
如何防范各类联属欺诈?









