我该如何"ping"自定义Unity3D检查器中的文本文件? [英] How can I "ping" a text file in a custom Unity3D Inspector?

查看:164
本文介绍了我该如何"ping"自定义Unity3D检查器中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Unity3D的自定义编辑器中"ping"文本文件,例如使用 EditorGUIUtility.PingObject (在Hierachy中显示文件,并闪烁黄色选择字段).
文件位于Assets/StreamingAssets/Example.csv

I'm trying to "ping" a Textfile in a custom editor in Unity3D like e.g. using EditorGUIUtility.PingObject (Shows the file in the Hierachy and flashes a yellow selection field over it).
The file is under Assets/StreamingAssets/Example.csv

最简单的解决方案(我认为)是简单地在ObjectField中显示它->如果单击该字段,资产也会被"ping". 所以我正在尝试:

The simplest solution (I thought) would be to simply show it in an ObjectField -> if clicking on the field the asset also gets "pinged". so I'm trying:

// For debug, later the filename will be dynamic
var path = "Assets/StreamingAssets/" + "Example" + ".csv";
TextAsset file = (TextAsset)AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset));
EditorGUILayout.PrefixLabel("CSV File", EditorStyles.boldLabel);
EditorGUILayout.ObjectField(file, typeof(TextAsset), false);

但是尽管文件存在并且path正确,但file仍然是null

But though the file is there and the path correct, file is allways null

推荐答案

我的错误是对TextAsset的类型转换,并使用

My mistake was the typecasting to TextAsset and using LoadAssetAtPath which requires a Type parameter.

将其取消广播"为object(资产),并使用 LoadMainAssetAtPath 而不需要Type参数现在可以正常工作:

Leaving it "uncasted" as object (asset) and using LoadMainAssetAtPath instead which doesn't require the Type parameter works now:

// For debug, later the filename will be dynamic
var path = "Assets/StreamingAssets/" + "Example" + ".csv";
var file = AssetDatabase.LoadMainAssetAtPath(path);
EditorGUILayout.PrefixLabel("CSV File", EditorStyles.boldLabel);
EditorGUILayout.ObjectField(file, typeof(object), false);

这篇关于我该如何"ping"自定义Unity3D检查器中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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