这是一个屏幕截图,例如当有3个对话时: 我有4个按钮。添加/删除项目并保存/加载
例如,现在有100个对话: 现在按下了4个按钮,我需要向下滚动才能看到按钮:
我想要做的是以某种方式使滚动视图仅显示对话。 因此,当对话过多时,检查器将具有滚动条,而对话将具有其自己的滚动视图。因此最多只能将4个按钮移到底部,但不能移出屏幕视图。
因此,对话滚动视图在垂直方向上可以变大,直到按钮移到底部,然后才将对话保持在滚动视图中。
这是检查器的编辑器脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
[CustomEditor(typeof(ConversationTrigger))]
public class ConversationTriggerEditor : Editor
{
private ConversationTrigger conversationtrigger;
private void OnEnable()
{
conversationtrigger = (ConversationTrigger)target;
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
GUILayout.Space(20);
if (GUILayout.Button("Add new conversation"))
{
conversationtrigger.conversations.Add(new Conversation());
}
GUILayout.Space(10);
if (GUILayout.Button("Remove conversation"))
{
conversationtrigger.conversations.RemoveAt(conversationtrigger.conversations.Count - 1);
}
GUILayout.Space(100);
if (GUILayout.Button("Save Conversations"))
{
conversationtrigger.SaveConversations();
}
GUILayout.Space(10);
if (GUILayout.Button("Load Conversations"))
{
Undo.RecordObject(conversationtrigger, "Loaded conversations from JSON");
conversationtrigger.LoadConversations();
}
}
}
答案 0 :(得分:2)
尝试使用EditorGUILayout.BeginScrollView()
这里是文档:https://docs.unity3d.com/ScriptReference/EditorGUILayout.BeginScrollView.html
您只需要添加三行。
private Vector2 scrollPos; // add this line above the following line
private ConversationTrigger conversationtrigger;
...
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(250)); // add
DrawDefaultInspector(); // add the above and below lines around this existing line
EditorGUILayout.EndScrollView(); // add
250可以更改为您想要的最大高度。