我正在写一个统一的字符控制器。我是C#编程的新手,我已经写了一些代码
using UnityEngine;
using UnityEditor;
[CustomPorpertyDrawer(typeof(AxisKeys))]
public class PlayerAxisKeysDrawer: PropertyDrawer{
public override void onGUI(Rect position, SerializedProperty property, GUIContent label)
{
//don't indent
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
//ensure override works on entire property
EditorGUI.BeginProperty(position, label, property);
//label
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
//set position rects;
Rect posLabel = new Rect(position.x, position.y, 15, position.height);
Rect posField = new Rect(position.x + 20, position.y, 50, position.height);
Rect negLabel = new Rect(position.x, position.y, 15, position.height);
Rect negField = new Rect(position.x + 20, position.y, 50, position.height);
GUIContent posGUI = new GUIContent("+");
GUIContent negGUI = new GUIContent("-");
//draw fields
EditorGUI.LabelField(posLabel, posGUI);
EditorGUI.PropertyField(posField, property.FindPropertyRelative("positive"), GUIContent.none);
EditorGUI.LabelField(negLabel, negGUI);
EditorGUI.PropertyField(negField, property.FindPropertyRelative("negative"), GUIContent.none);
//reset indent
EditorGUI.indentlevel = indent;
//end property
EditorGUI.EndProperty();
}
}
但是出现此错误。有人可以帮助吗?
error CS0115: `PlayerAxisKeysDrawer.onGUI(UnityEngine.Rect, UnityEditor.SerializedProperty, UnityEngine.GUIContent)' is marked as an override but no suitable method found to override
答案 0 :(得分:1)
您遇到拼写错误,将OnInspectecorGUI
更改为OnInspectorGUI
,它应该可以工作:)