using System.Collections;using System.Collections.Generic;using UnityEditor;using UnityEditorInternal;using UnityEngine;[CustomEditor(typeof(DialogueTrigger))]public class DialogueTriggerEditor : Editor{ private SerializedProperty _dialogues; private SerializedProperty _conversations; private SerializedProperty old_Conversations; private void OnEnable() { _conversations = serializedObject.FindProperty("conversations"); old_Conversations.arraySize = _conversations.arraySize; } public override void OnInspectorGUI() { //base.OnInspectorGUI(); serializedObject.Update(); _conversations.arraySize = EditorGUILayout.IntField("Conversations Size", _conversations.arraySize); if (old_Conversations.arraySize != _conversations.arraySize) { for (int x = 0; x < _conversations.arraySize; x++) { var conversation = _conversations.GetArrayElementAtIndex(x); var Id = conversation.FindPropertyRelative("conversationName"); EditorGUILayout.PropertyField(Id); }}OnInspectorGUI 中的所有內容都非??焖俚匾槐橛忠槐榈卣{用。所以它不停地循環。我添加了 _conversations 的舊副本:private SerializedProperty old_Conversations;我第一次嘗試將它分配給 OnEnable 中的原始 _conversations:old_Conversations.arraySize = _conversations.arraySize;但是我使用了一個斷點并且 OnEnable 從未調用過。然后在循環之前我正在做檢查:if (old_Conversations.arraySize != _conversations.arraySize)在底部,我再次使兩者相等。但它不起作用。當更改 _conversations 的大小時,它總是將它改回 1 并且之后什么都不做。我的主要目標是以某種方式在每次大小更改時只調用一次循環。如果大小為 1、5 或 10,它工作正常,但如果我將大小更改為 100,一切都會變慢,幾乎凍結。
2 回答

慕娘9325324
TA貢獻1783條經驗 獲得超4個贊
您可以使用 BeginChangeCheck / EndChangeCheck 來檢測修改。
EditorGUI.BeginChangeCheck();
_conversations.arraySize = EditorGUILayout.IntField("Conversations Size", _conversations.arraySize);
if(EditorGUI.EndChangeCheck()) {
for ...
}
頁面預覽
page = EditorGUILayout.IntField("Page", page);
int index = page * countPerPage;
for(int x = index; i < Mathf.Min(_conversations.arraySize, index + countPerPage); ++i)
{
...
}

FFIVE
TA貢獻1797條經驗 獲得超6個贊
您可以嘗試僅將舊對話的數組大小保存為整數,而不保存第二個數組。但是有可能,這不會起作用,因為我認為必須在每次調用中執行 onInspectorGui 代碼(但不確定)。
- 2 回答
- 0 關注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消