【解决】Assertion failed on expression: ‘ShouldRunBehaviour()’

开发平台:Unity
编程平台:Visual Studio 2020以上
使用语言:C#

问题描述

描 述
原意Assertion failed on expression: ‘ShouldRunBehaviour()’
翻译对表达内容的断句上产生错误:‘ShouldRunBehaviour()’

注:该问题可能不会影响实际项目中操作。


解决方案

  应用【ExecuteInEditMode】特性。Unity对一部分方法调用只允许其在Runtime模式下运行使用,对Editor模式下不支持允许。尽管该方法仍可能运行出结果。

更多参考外网分析:

案例:StartCoroutine 协程

  开发过程中,寄希望于Editor模式下直接解析数据内容。有应用到协程开发内容(省略DLL引用)。但在实际问题反馈中,认为Unity Editor模式不支持协程使用 。如下所示:

[ExecuteInEditMode]
public class Example : Monobehaviour
{
	public void RequestData()
	{
		StartCoroutinue(nameof(DatabaseRequest));
	}
	
	IEnmerator DatabaseReqeust() { yield return ... }
}

  应用UnityEditor API对组件内容扩充,使其允许Editor模式下直接使用(省略DLL引用)。如下所示:

[CustomeEditor(typeof(Example))]
public class EditExample : Editor
{
	private Example _example;
	private void OnEnable() { _example = target as Example; }
	public override void OnInspectorGUI()
	{
		base.OnInspectorGUI();
		
		if(GUILayout.Button("请求数据内容"))
		{
			_example.RequsetData();
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值