错误CS0117:`unityeditorinternal.internaleditorutility'不包含`addscriptcomponentunchecked'的定义 [英] Error CS0117: `unityeditorinternal.internaleditorutility' does not contain a definition for `addscriptcomponentunchecked'

查看:532
本文介绍了错误CS0117:`unityeditorinternal.internaleditorutility'不包含`addscriptcomponentunchecked'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 AssetDatabase.Refresh(); 
AssetDatabase.ImportAsset(path,ImportAssetOptions.ForceSynchronousImport);

var gameObj = target.gameObject;
var script = AssetDatabase.LoadAssetAtPath(path.MakeRelativePath(),typeof(MonoScript))为MonoScript;
InternalEditorUtility.AddScriptComponentUnchecked(gameObj,script);

#region延迟执行

// 声明为空值消除未初始化的变量
// 下面的lambda中的编译器错误。
EditorApplication.CallbackFunction callback = null;





我尝试了什么:



我在这段代码中没有改变任何内容。

解决方案

AddScriptComponentUnchecked在InternalEditorUtility类中,因为它不适合公共使用,所以它可以随时更改,恕不另行通知 [ ^ ],看起来你正在使用的Unity版本太新了使用这种方法。



你应该检查是否有办法使用公共方法来做你想要的。如果您认为没有,那么您可以使用反射来访问 InternalEditorUtility 上的私有 AddScriptComponentUncheckedUndoable 方法(但是如果你可以避免这种情况,然后避免它)。为此,请参阅WolfieMario对创建脚本对话框Unity资产 [ ^ ]并将其调整为您的代码。

AssetDatabase.Refresh();
		AssetDatabase.ImportAsset( path, ImportAssetOptions.ForceSynchronousImport );

		var gameObj = target.gameObject;
		var script = AssetDatabase.LoadAssetAtPath( path.MakeRelativePath(), typeof( MonoScript ) ) as MonoScript;
		InternalEditorUtility.AddScriptComponentUnchecked( gameObj, script );

		#region Delayed execution

		// Declared with null value to eliminate "uninitialized variable" 
		// compiler error in lambda below.
		EditorApplication.CallbackFunction callback = null;



What I have tried:

I am not change anything in this code.

解决方案

AddScriptComponentUnchecked is in the InternalEditorUtility class because it's not intended for public use so it can change anytime without notice[^], and it looks like you're using a Unity version that's too new to use this method.

You should check if there's a way using public methods to do what you want. If you think there isn't, then you can use reflection to access the private AddScriptComponentUncheckedUndoable method on InternalEditorUtility (but if you can avoid that, then do avoid it). For that, see WolfieMario's review to the 'Create Script Dialog' Unity asset[^] and adjust that to your code.


这篇关于错误CS0117:`unityeditorinternal.internaleditorutility'不包含`addscriptcomponentunchecked'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆