Tanoda
pb_InputManager.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
4using System.Collections;
5using System.Collections.Generic;
6using System.Linq;
7using GILES.Interface;
8
9namespace GILES
10{
16 public class pb_InputManager : pb_MonoBehaviourSingleton<pb_InputManager>
17 {
18 // The editor mode that is used on initialization. To set a new mode or swap between modes,
19 // use pb_InputManager.SetCurrentMode(). See pb_SceneEditor for information about implementing
20 // custom editor modes.
22
24 private EventSystem eventSystem;
25
26 // The mode that is currently in use. This is the only pb_SceneEditor that will receive
27 // events from the input manager.
28 [HideInInspector] [SerializeField] public pb_SceneEditor _editor;
29
34 public static void AddMouseInUseDelegate(MouseInUse del)
35 {
36 if(instance.mouseUsedDelegate == null)
37 instance.mouseUsedDelegate = del;
38 else
39 instance.mouseUsedDelegate += del;
40 }
41
45 public static void RemoveMouseInUseDelegate(MouseInUse del)
46 {
47 instance.mouseUsedDelegate -= del;
48 }
49
54 public static void AddKeyInUseDelegate(KeyInUse del)
55 {
56 if(instance.keyUsedDelegate == null)
57 instance.keyUsedDelegate = del;
58 else
59 instance.keyUsedDelegate += del;
60 }
61
65 public static void RemoveKeyInUseDelegate(KeyInUse del)
66 {
67 instance.keyUsedDelegate -= del;
68 }
69
75
81
87 public void SetEditor(pb_SceneEditor editor)
88 {
89 if( _editor != null )
90 _editor.Disable();
91
92 _editor = editor;
93
94 if(_editor != null)
95 _editor.Enable();
96 }
97
102 {
103 if(instance._editor == null)
104 Debug.Log("NULL! e r est");
105
106 return instance._editor;
107 }
108
112 protected override void Awake()
113 {
114 base.Awake();
115 Cursor.lockState = CursorLockMode.None;
116 }
117
121 protected virtual void Start()
122 {
123 eventSystem = EventSystem.current;
124
127
129 }
130
136 private void Update ()
137 {
138 if(_editor == null)
139 return;
140
141 if( Input.anyKeyDown && !IsKeyInUse() && !ProcessKeyInput() )
143
144 _editor.UpdateBase();
145 }
146
150 private void OnGUI()
151 {
152 _editor?.OnGUI();
153 }
154
155 private void OnLevelReset()
156 {
157 // reset the undo queue
158 if( Undo.nullableInstance != null )
159 Destroy(Undo.nullableInstance);
160 }
161
165 public static bool IsMouseInUse()
166 {
167 bool inuse = instance.mouseUsedDelegate != null && instance.mouseUsedDelegate.GetInvocationList().Any(x => ((MouseInUse)x)(Input.mousePosition));
168 return inuse;
169 }
170
174 public static bool IsKeyInUse()
175 {
176 return instance.keyUsedDelegate != null && instance.keyUsedDelegate.GetInvocationList().Any(x => ((KeyInUse)x)());
177 }
178
183 private bool ProcessKeyInput()
184 {
186 if(eventSystem != null && eventSystem.currentSelectedGameObject != null)
187 {
188 if( Input.GetKey(KeyCode.Tab) )
189 {
190 Selectable next = pb_GUIUtility.GetNextSelectable(eventSystem.currentSelectedGameObject.GetComponent<Selectable>());
191
192 if (next != null)
193 {
194 InputField inputfield = next.GetComponent<InputField>();
195
196 if (inputfield != null)
197 inputfield.OnPointerClick(new PointerEventData(eventSystem));
198 }
199 }
200
201
202 return true;
203 }
204
205#if !UNITY_EDITOR
206 if( Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.LeftControl) )
207#endif
208 {
209 if( Input.GetKey(KeyCode.Z) )
210 {
211 Undo.PerformUndo();
212 return true;
213 }
214
215 if( Input.GetKey(KeyCode.Y) )
216 {
217 Undo.PerformRedo();
218 return true;
219 }
220 }
221
222 //if( Input.GetKey(KeyCode.Backspace))
223 //{
224 // Undo.RegisterStates( new IUndo[] { new UndoDelete(pb_Selection.gameObjects), new UndoSelection() }, "Delete Selection" );
225 //
226 // pb_Selection.Clear();
227 //}
228
229 return false;
230 }
231 }
232}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
static void RemoveKeyInUseDelegate(KeyInUse del)
static bool IsKeyInUse()
pb_SceneEditor currentEditor
static bool IsMouseInUse()
pb_SceneEditor _editor
static pb_SceneEditor GetCurrentEditor()
static void AddKeyInUseDelegate(KeyInUse del)
override void Awake()
static void RemoveMouseInUseDelegate(MouseInUse del)
MouseInUse mouseUsedDelegate
static void AddMouseInUseDelegate(MouseInUse del)
void SetEditor(pb_SceneEditor editor)
virtual void OnGUI()
static void AddOnLevelLoadedListener(Callback listener)
Definition: pb_Scene.cs:107
static void AddOnLevelClearedListener(Callback listener)
Definition: pb_Scene.cs:118
delegate bool MouseInUse(Vector2 mousePosition)
delegate bool KeyInUse()