Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UIContextMenuPopper.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.EventSystems;
4
5public class UIContextMenuPopper : UIContextMenuItem, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
6{
7 [NonSerialized]
8 public RectTransform _rect;
9
10 [NonSerialized]
11 public bool isPointerOver;
12
13 [NonSerialized]
15
16 [NonSerialized]
17 public string id;
18
20
22
23 public Vector2 margin = new Vector2(8f, 10f);
24
25 public float bottomFix;
26
27 private void Awake()
28 {
29 _rect = base.transform as RectTransform;
30 }
31
32 public virtual void OnPointerEnter(PointerEventData data)
33 {
34 isPointerOver = true;
35 }
36
37 public virtual void OnPointerExit(PointerEventData data)
38 {
39 isPointerOver = false;
40 }
41
42 private void Update()
43 {
44 if (isPointerOver && !menu.gameObject.activeSelf && parent.timeSinceOpen > 0.1f && !Input.GetMouseButton(0))
45 {
46 Pop();
47 }
48 if (!isPointerOver && !Input.GetMouseButton(0) && UIContextMenu.Current.hideOnMouseLeave && !menu.isPointerOver)
49 {
50 Depop();
51 }
52 }
53
54 public void Pop()
55 {
57 {
58 UIContextMenuPopper[] componentsInChildren = UIContextMenu.Current.GetComponentsInChildren<UIContextMenuPopper>();
59 for (int i = 0; i < componentsInChildren.Length; i++)
60 {
61 componentsInChildren[i].Depop();
62 }
63 }
64 if (menu == null)
65 {
66 CreateMenu();
67 }
68 menu.Show();
69 if (parent != null)
70 {
72 }
73 }
74
75 public void Depop()
76 {
77 menu.Hide();
78 }
79
81 {
82 menu = UnityEngine.Object.Instantiate(defaultMenu);
83 menu.transform.SetParent(base.transform, worldPositionStays: false);
84 menu.popper = this;
85 menu.depth = parent.depth + 1;
86 menu.parent = parent;
87 if (parent.system)
88 {
89 menu.bg.material = parent.matBlur;
90 }
91 return menu;
92 }
93
94 public void PositionMenu()
95 {
96 RectTransform rect = menu._rect;
97 rect.RebuildLayout(recursive: true);
98 Vector2 zero = Vector2.zero;
99 zero.x = _rect.sizeDelta.x - margin.x;
100 zero.y = _rect.sizeDelta.y * -1f - margin.y;
101 rect.pivot = new Vector2(0f, 1f);
102 rect.anchoredPosition = zero;
103 if (parent.transform.position.x + parent._rect.sizeDelta.x * (1f - parent._rect.pivot.x) > (float)Screen.width - rect.sizeDelta.x || menu.alwaysPopLeft)
104 {
105 zero.x = margin.x;
106 rect.pivot = new Vector2(1f, menu._rect.pivot.y);
107 }
108 zero.x = (int)zero.x;
109 zero.y = (int)zero.y;
110 rect.anchoredPosition = zero;
111 if (rect.position.y - rect.sizeDelta.y * BaseCore.Instance.uiScale < 0f)
112 {
113 Vector3 position = rect.position;
114 position.y = rect.sizeDelta.y * BaseCore.Instance.uiScale;
115 rect.position = position;
116 }
117 }
118}
virtual float uiScale
Definition: BaseCore.cs:46
static BaseCore Instance
Definition: BaseCore.cs:11
virtual void OnPointerExit(PointerEventData data)
virtual void OnPointerEnter(PointerEventData data)
UIContextMenu CreateMenu()
void Show(UIItem i)
static UIContextMenu Current
bool hideOnMouseLeave
Material matBlur
RectTransform _rect
float timeSinceOpen