ドロップダウンUnityでオプションを無効にする

Hikari

Unityのドロップダウンメニューから1(または2)ドロップダウンオプションを無効にする必要があります。ここに画像の説明を入力してくださいドロップダウンメニューを再設定しないでください
ドロップダウンメニューからの削除/非アクティブ化オプションはありません。

誰もがこれを行う方法を知っています。

derHugo

この回答に似ていますが、アプローチが少し異なります。

もう1つの答えは、ハードコードさtoggle.name == "Item 1: Option B"れたボタンを使用してボタンを比較します。むしろ、中央のインデックスベースのシステムを使用したいと思います。

このコンポーネントを DropDown

[RequireComponent(typeof(Dropdown))]
[DisallowMultipleComponent]
public class DropDownController : MonoBehaviour, IPointerClickHandler
{
    [Tooltip("Indexes that should be ignored. Indexes are 0 based.")]
    public List<int> indexesToDisable = new List<int>();

    private Dropdown _dropdown;

    private void Awake()
    {
        _dropdown = GetComponent<Dropdown>();
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        var dropDownList = GetComponentInChildren<Canvas>();
        if (!dropDownList) return;

        // If the dropdown was opened find the options toggles
        var toogles = dropDownList.GetComponentsInChildren<Toggle>(true);

        // the first item will always be a template item from the dropdown we have to ignore
        // so we start at one and all options indexes have to be 1 based
        for (var i = 1; i < toogles.Length; i++)
        {
            // disable buttons if their 0-based index is in indexesToDisable
            // the first item will always be a template item from the dropdown
            // so in order to still have 0 based indexes for the options here we use i-1
            toogles[i].interactable = !indexesToDisable.Contains(i - 1);
        }
    }

    // Anytime change a value by index
    public void EnableOption(int index, bool enable)
    {
        if (index < 1 || index > _dropdown.options.Count)
        {
            Debug.LogWarning("Index out of range -> ignored!", this);
            return;
        }

        if (enable)
        {
            // remove index from disabled list
            if (indexesToDisable.Contains(index)) indexesToDisable.Remove(index);
        }
        else
        {
            // add index to disabled list
            if (!indexesToDisable.Contains(index)) indexesToDisable.Add(index);
        }

        var dropDownList = GetComponentInChildren<Canvas>();

        // If this returns null than the Dropdown was closed
        if (!dropDownList) return;

        // If the dropdown was opened find the options toggles
        var toogles = dropDownList.GetComponentsInChildren<Toggle>(true);
        toogles[index].interactable = enable;
    }

    // Anytime change a value by string label
    public void EnableOption(string label, bool enable)
    {
        var index = _dropdown.options.FindIndex(o => string.Equals(o.text, label));

        // We need a 1-based index
        EnableOption(index + 1, enable);
    }
}

インスペクターで構成する

ここに画像の説明を入力してください

またはスクリプトを介して

dropDownReference.GetComponent<DropDownController>().EnableOption("Option B", false);

ここに画像の説明を入力してください

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

選択したオプションに基づいて動的に作成されたすべてのドロップダウンでオプションを無効/有効にするにはどうすればよいですか?

他のリストでの選択に基づいて、ドロップダウンリストのオプションを無効にします

select2クリアでドロップダウンオープニングを無効にする

ドロップダウン選択で特定のオプションを無効にする方法は?

オプションを選択した後、ドロップダウンメニューを動的に無効にする

Yii2でプロンプトオプションのドロップダウンリストを無効にする

ドロップダウン選択で特定のオプションを無効にする

JS-計算に基づいてドロップダウンオプションを無効にする

ngOnInitによるドロップダウンのオプションを無効にする方法は?

0以外の他のドロップダウンで選択のオプションを無効にする

ドロップダウンリストオプションを他のドロップダウンリストオプションと一緒に無効にする

apexchartsでダウンロードオプションを無効にする方法は?

選択したドロップダウンオプション角度2を無効にしますか?

マットドロップダウンオプションを1から2に無効にする方法は?

オプションが1つある場合、選択ドロップダウンを無効にするにはどうすればよいですか?

HTMLドロップダウンはJavascriptのオプションを無効にします

KendoUIドロップダウンリストオプションを無効にする

asp.netmvcドロップダウンリストオプションが無効になっています

最初のドロップダウンに基づいて2番目のドロップダウンオプションを無効にする

Struts-JQueryは、別のドロップダウンの選択に基づいてドロップダウンオプションを無効にします

ドロップダウン メニューのオプションを無効にする - d3

ドロップダウンボタンを無効にする

日付に基づいてドロップダウンオプションを無効にする方法

Javascriptを使用して選択ドロップダウンから特定のオプションフィールドを無効にする問題

jqueryなしでドロップダウンオプションを選択するまで送信ボタンを無効にします

フラッター:ドロップダウンボタンオプションを無効にする

Primevueのドロップダウンオプションを事後的に無効にする方法はありますか?

javascript / jqueryを使用して選択ドロップダウンでブートストラップオプションを有効/無効にする方法

反応型フォームで別のドロップダウンが選択されるまでオプションリストを無効にする方法