Answers:
编辑器友好路径是“自定义检查器”。用Unity API术语,这意味着扩展Editor类。
这是一个有效的示例,但是上面的doc链接将带您了解许多详细信息和其他选项:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
private Test targetObject;
void OnEnable()
{
targetObject = (Test) this.target;
}
// Implement this function to make a custom inspector.
public override void OnInspectorGUI()
{
// Using Begin/End ChangeCheck is a good practice to avoid changing assets on disk that weren't edited.
EditorGUI.BeginChangeCheck();
// Use the editor auto-layout system to make your life easy
EditorGUILayout.BeginVertical();
targetObject.testBool = EditorGUILayout.Toggle("Bool", targetObject.testBool);
// GUI.enabled enables or disables all controls until it is called again
GUI.enabled = targetObject.testBool;
targetObject.testString = EditorGUILayout.TextField("String", targetObject.testString);
// Re-enable further controls
GUI.enabled = true;
targetObject.testInt = EditorGUILayout.IntField("Int", targetObject.testInt);
EditorGUILayout.EndVertical();
// If anything has changed, mark the object dirty so it's saved to disk
if(EditorGUI.EndChangeCheck())
EditorUtility.SetDirty(target);
}
}
请记住,此脚本使用仅编辑器的API,因此必须将其放置在名为Editor的文件夹中。上面的代码会将您的检查器变为以下内容:
在您对编辑器脚本更加满意之前,这应该可以使您滚动。
[System.Serializable]
public class Test : ScriptableObject
{
private bool testbool;
public string teststring;
public int testint;
public string TestString
{
get
{
return teststring;
}
set
{
if (testbool)
teststring = value;
}
}
}
true
。