亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我如何比較編輯器腳本中的兩個列表,以便每次列表大小不同時只進行一次 for 循環?

我如何比較編輯器腳本中的兩個列表,以便每次列表大小不同時只進行一次 for 循環?

C#
胡說叔叔 2022-11-21 15:52:29
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)

{

    ...

}


查看完整回答
反對 回復 2022-11-21
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

您可以嘗試僅將舊對話的數組大小保存為整數,而不保存第二個數組。但是有可能,這不會起作用,因為我認為必須在每次調用中執行 onInspectorGui 代碼(但不確定)。



查看完整回答
反對 回復 2022-11-21
  • 2 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號