c# - 如何创建一个自定义编辑器脚本,在 Unity 的检查器中显示非本地类?
问题描述
我有一个没有扩展本机类的类,因此该类型的变量不会显示在检查器中。
如果我要通过原生类扩展所述类,则该类型的变量将显示在检查器中,但我实际上无法将它们设置为任何东西,因为它们包含在 ScriptableObject 中,显然这两种类型没有不适合。
我尝试编写 CustomPropertyDrawer,但它仍然没有显示变量。这是我的代码(在 C# 中):
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(AScriptableObjectClassThatShouldDisplayTheVariableInItsInspector))]
public class ShowVariable : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
base.OnGUI(position, property, label);
EditorGUI.BeginProperty(position, label, property);
Rect rect = new Rect(position.x, position.y, 50, position.height);
EditorGUI.PropertyField(rect, property.FindPropertyRelative("nameOfVariable"));
EditorGUI.EndProperty();
}
}
这是包含应该显示的类的变量的类:
[System.Serializable]
public class Syntax : ScriptableObject
{
public GameLevelFunction nameOfVariable;
}
这基本上就是我的类应该在检查器中显示的样子:
[System.Serializable]
public abstract class GameLevelFunction
{
//literally two methods
}
解决方案
推荐阅读
- android - 程序类型已经存在:androidx.appcompat.R$anim
- xamarin - 适用于 Xamarin 的 OneSignal SDK:没有定义 inFocusDisplayType
- python - 如何将 IANA/Olson 时区转换为 POSIX.1?
- observable - 为什么我不能用 RxJava 连接两个 Single Android Room 结果
- c# - Linq通过搜索关键字从对象的关系列表中选择对象
- r - 如何在 r 中的 ggplot 中向衰退条添加标签
- azure - 如何在 Azure CI/CD 的 Azure CLI 步骤中使用变量
- python - 将幂转换为 (lambda) 函数的应用次数
- node.js - React axios 错误:Firefox 中删除请求的请求中止,但 Chrome 中没有
- python - 响应后Django类变量没有被破坏