Files
ChunilENG/Assets/Scripts/UI/CustomTMPDropdown.cs
2025-11-21 13:07:13 +09:00

40 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class CustomTMPDropdown : TMP_Dropdown
{
public string hideItemName;
public void SetHideAndDeinteractableItems(string hideItemName)
{
this.hideItemName = hideItemName;
}
public override void OnPointerClick(UnityEngine.EventSystems.PointerEventData eventData)
{
base.OnPointerClick(eventData);
StartCoroutine(SetHideAndDeinteractableDropdownItem());
}
private IEnumerator SetHideAndDeinteractableDropdownItem()
{
yield return null;
var dropdownList = GameObject.Find("Dropdown List");
if (dropdownList == null)
yield break;
var items = dropdownList.GetComponentsInChildren<TMP_Dropdown.DropdownItem>(true).ToList();
if (items.Count > 0)
{
var hideItem = items.Find(item => item.name.Contains(hideItemName));
hideItem.gameObject.SetActive(false);
}
}
}