miepzerino
2025-04-08 40ac185dc7a017d95771fe580c77eab20e663908
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEngine;
using UnityEngine.InputSystem.XR;
 
public class GenericUIInteractable : Interactable
{
    [SerializeField] private GameObject targetUI;
    [SerializeField] private string interactableType;
    [SerializeField] private bool closeOtherUIs = true;
 
    [SerializeField] private GameObject[] uisToClose;
 
    public override void Interact()
    {
        // Call base interaction event
        OnInteract.Invoke();
 
        // Close other UIs if needed
        if (closeOtherUIs)
        {
            foreach (var ui in uisToClose)
            {
                if (ui != null)
                {
                    ui.SetActive(false);
                }
            }
        }
 
        // Show target UI
        if (targetUI != null)
        {
            targetUI.SetActive(true);
 
            // If there's a UI controller component, notify it of the interaction
            UIController uiController = targetUI.GetComponent<UIController>();
            if (uiController != null)
            {
                uiController.OnUIOpened(interactableType, gameObject);
            }
        }
    }
    private new void OnTriggerExit2D(Collider2D other)
    {
        if (targetUI != null)
        {
            targetUI.SetActive(false);
            base.OnTriggerExit2D(other);
        }
    }
}