-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathContextMenuExample.cs
More file actions
58 lines (53 loc) · 1.7 KB
/
ContextMenuExample.cs
File metadata and controls
58 lines (53 loc) · 1.7 KB
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
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using ChosenConcept.APFramework.UI;
using ChosenConcept.APFramework.UI.Menu;
using UnityEngine;
using UnityEngine.InputSystem;
public class ContextMenuExample : MonoBehaviour
{
[SerializeField] SimpleMenu _return;
bool _contextMenuOpen;
bool _exampleOpen;
bool _exampleMenuInstantiated;
public void Open()
{
_exampleOpen = true;
if (!_exampleMenuInstantiated)
{
_exampleMenuInstantiated = true;
_return = new SimpleMenu("Return");
_return.AddText("Mouse right click to open a context menu");
_return.AddButton("Return", () =>
{
_exampleOpen = false;
_return.CloseMenu();
WindowManager.instance.GetMenu<ExampleMenu>().OpenMenu(true);
});
WindowManager.instance.RegisterMenu(_return);
}
_return.OpenMenu(true);
}
void Update()
{
if (!_exampleOpen)
return;
Mouse mouse = Mouse.current;
if (mouse != null)
{
if (!_contextMenuOpen && mouse.rightButton.wasPressedThisFrame)
{
_contextMenuOpen = true;
List<string> choices = new List<string>();
List<Action> actions = new List<Action>();
for (int i = 0; i <= 5; i++)
{
choices.Add(i.ToString());
actions.Add(() => Debug.Log("Clicked"));
}
WindowManager.instance.GetContextMenu(choices, actions, mouse.position.ReadValue(),
() => { _contextMenuOpen = false; });
}
}
}
}