我试图在Unity3D的自定义编辑器中“ ping”文本文件,例如使用EditorGUIUtility.PingObject(在“层次结构”中显示文件,并在其上方闪烁黄色选择字段)。
该文件在Assets/StreamingAssets/Example.csv
最简单的解决方案(我认为)将是简单地在ObjectField->中显示它,如果单击该字段,资产也会被“ ping”。所以我正在尝试:
// 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
我的错误是类型转换到TextAsset
并使用LoadAssetAtPath
它需要一个Type
参数。
现在将其保留为“(uncasted)” object
(资产),并使用LoadMainAssetAtPath
不需要Type
参数的替代方法现在可以正常工作:
// 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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句