您当前的位置: 首页 > 

野奔在山外的猫

暂无认证

  • 3浏览

    0关注

    85博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

野奔在山外的猫 发布时间:2022-04-03 15:48:37 ,浏览量:3

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

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

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

解决方案

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

更多参考外网分析:

  • masakami 网站
  • forum 论坛 1105351
  • forum 论坛 318517
  • Unity Issuletraker
案例: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();
		}
	}
}
关注
打赏
1659777066
查看更多评论
立即登录/注册

微信扫码登录

0.0397s