rimworld-animation-studio/Assets/Scripts/GUI/DropdownMenu.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2022-10-12 05:22:29 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace RimWorldAnimationStudio
{
public class DropdownMenu : MonoBehaviour, IDeselectHandler
{
public Transform dropdownMenu;
public void OpenMenu()
{
dropdownMenu.gameObject.SetActive(true);
EventSystem.current.SetSelectedGameObject(this.gameObject);
}
public void CloseMenu()
{
2022-10-20 05:32:13 +00:00
if (EventSystem.current.currentSelectedGameObject != null)
{
Transform child = transform.FindDeepChild(EventSystem.current.currentSelectedGameObject.name);
if (child != null)
{
EventSystem.current.SetSelectedGameObject(this.gameObject);
return;
}
}
2022-10-12 05:22:29 +00:00
dropdownMenu.gameObject.SetActive(false);
}
public void OnDeselect(BaseEventData eventData)
{
Invoke("CloseMenu", 0.15f);
}
}
}