private void ProcessEvent(IEventSystemHandler handler, BaseEventData eventData) { // Debug.LogError("process event " + Environment.StackTrace + " " + recordInput.GetMouseButtonUp(0)); if (!didProcessThisFrame) { //Debug.LogError("Process event!"); didProcessThisFrame = true; if (recordInput.GetMouseButtonDown(0)) { CreateTouchWriter(handler); } if (currentInputWriter == null) { //Debug.LogError("Receive Event but not recorder!"); return; } currentInputWriter.ReceiveEvent(eventData as PointerEventData); //frameCount = 0; if (recordInput.GetMouseButtonUp(0)) { DestroyWriter(); } } }
public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { List <IEventSystemHandler> list = s_HandlerListPool.Get(); GetEventList <T>(target, list); for (int i = 0; i < list.Count; i++) { T handler; try { handler = (T)list[i]; } catch (Exception innerException) { IEventSystemHandler eventSystemHandler = list[i]; Debug.LogException(new Exception($"Type {typeof(T).Name} expected {eventSystemHandler.GetType().Name} received.", innerException)); continue; } try { functor(handler, eventData); } catch (Exception exception) { Debug.LogException(exception); } } int count = list.Count; s_HandlerListPool.Release(list); return(count > 0); }
/// <summary> /// Update the game object being focused on /// </summary> public void UpdateFocus() { OldPrimeFocus = PrimeFocus; PrimeFocus = null; OldUIInteractibleFocus = UIInteractibleFocus; UIInteractibleFocus = null; if (m_LockedFocus != null) { PrimeFocus = m_LockedFocus; } else if (Hit && FocusHitInfo.transform != null) { PrimeFocus = FocusHitInfo.transform.gameObject; } // Bubble up from the old focused object and record all object that should get the GazeExited message if (OldPrimeFocus != null) { Transform trans = OldPrimeFocus.transform; do { FocusExitList.Add(trans.gameObject); GetNextValidParent(ref trans); } while (trans != null); } FocusList.Clear(); if (PrimeFocus != null) { Transform trans = PrimeFocus.transform; do { bool found = FocusExitList.Remove(trans.gameObject); if (!found) { FocusEnterList.Add(trans.gameObject); } FocusList.Add(trans.gameObject); if (UIInteractibleFocus == null) { Selectable foundSelectable = trans.gameObject.GetComponent <Selectable>(); IEventSystemHandler eventHandler = trans.gameObject.GetComponent <IEventSystemHandler>(); if (eventHandler != null) { UIInteractibleFocus = (eventHandler as Component).gameObject; } else if (foundSelectable != null && foundSelectable.IsInteractable()) { UIInteractibleFocus = foundSelectable.gameObject; } } GetNextValidParent(ref trans); } while (trans != null); } }
public static IEventSystemHandler GetEvent <T>(GameObject go) where T : IEventSystemHandler { var internalHandlers = s_HandlerListPool.Get(); IEventSystemHandler handler = GetEvent <T>(go, internalHandlers); s_HandlerListPool.Release(internalHandlers); return(handler); }
public IEventSystemHandler Process(JuniperPointerEventData eventData, float pixelDragThresholdSquared, List <KeyCode> keyPresses) { IEventSystemHandler eventTarget = null; foreach (var btn in buttons) { eventTarget = btn.Process(eventData, pixelDragThresholdSquared, keyPresses); } return(eventTarget); }
private void RegisterHandler(Type handlerType, IEventSystemHandler handler) { if (eventExecutionDepth == 0) { AddHandlerToMap(handlerType, handler); } else { postponedActions.Add(Tuple.Create(Action.Add, handlerType, handler)); } }
private void UnregisterHandler(Type handlerType, IEventSystemHandler handler) { if (eventExecutionDepth == 0) { RemoveHandlerFromMap(handlerType, handler); } else { postponedActions.Add(Tuple.Create(Action.Remove, handlerType, handler)); } }
private static IEnumerator ChangeColor(IEventSystemHandler systemHandler, Image bg, Color c) { yield return(new WaitForEndOfFrame()); if (!bg || systemHandler == null) { yield break; } ReflectionUtil.SetPrivateField(systemHandler, "_normalBGColor", c); ReflectionUtil.SetPrivateField(systemHandler, "_selectedBGColor", c); bg.color = c; }
private void ProcessEvent(IEventSystemHandler handler, BaseEventData eventData) { if (!didProcessThisFrame) { didProcessThisFrame = true; targetGameObject = (handler as Component).gameObject; if (CurrentPointerData != null && CurrentPointerData.SelectGameObject == null) { CurrentPointerData.SelectGameObject = targetGameObject; } } }
/// <summary> /// Utility function for registering parent interfaces of a given handler. /// </summary> /// <remarks> /// Event handler interfaces may derive from each other. Some events will be raised using a base handler class, and are supposed to trigger on /// all derived handler classes too. Example of that is IMixedRealityBaseInputHandler hierarchy. /// To support that current implementation registers multiple dictionary entries per handler, one for each level of event handler hierarchy. /// Alternative would be to register just one root type and /// then determine which handlers to call dynamically in 'HandleEvent'. /// Implementation was chosen based on performance of 'HandleEvent'. Without determining type it is about 2+ times faster. /// There are possible ways to bypass that, but this will make implementation of classes /// that derive from Input System unnecessarily more complicated. /// </remarks> private void TraverseEventSystemHandlerHierarchy <T>(IEventSystemHandler handler, Action <Type, IEventSystemHandler> func) where T : IEventSystemHandler { var handlerType = typeof(T); // Need to call on handlerType first, because GetInterfaces below will only return parent types. func(handlerType, handler); foreach (var iface in handlerType.GetInterfaces()) { if (!iface.Equals(eventSystemHandlerType)) { func(iface, handler); } } }
/// <inheritdoc /> public virtual void UnregisterHandler <T>(IEventSystemHandler handler) where T : IEventSystemHandler { if (handler == null) { return; } // #if due to Microsoft.MixedReality.Toolkit.ReflectionExtensions overload of Type.IsInterface #if WINDOWS_UWP && !ENABLE_IL2CPP Debug.Assert(typeof(T).IsInterface(), "UnregisterHandler must be called with an interface as a generic parameter."); #else Debug.Assert(typeof(T).IsInterface, "UnregisterHandler must be called with an interface as a generic parameter."); #endif Debug.Assert(typeof(T).IsAssignableFrom(handler.GetType()), "Handler passed to UnregisterHandler doesn't implement a type given as generic parameter."); TraverseEventSystemHandlerHierarchy <T>(handler, UnregisterHandler); }
/// <inheritdoc /> public virtual void RegisterHandler <T>(IEventSystemHandler handler) where T : IEventSystemHandler { if (handler == null) { return; } // #if due to Microsoft.MixedReality.Toolkit.ReflectionExtensions overload of Type.IsInterface #if WINDOWS_UWP && !ENABLE_IL2CPP Debug.Assert(typeof(T).IsInterface(), "RegisterHandler must be called with an interface as a generic parameter."); #else Debug.Assert(typeof(T).IsInterface, "RegisterHandler must be called with an interface as a generic parameter."); #endif Debug.Assert(typeof(T).IsAssignableFrom(handler.GetType()), "Handler passed to RegisterHandler doesn't implement a type given as generic parameter."); DebugUtilities.LogVerboseFormat("Registering handler {0} against system {1}", handler.ToString().Trim(), this); TraverseEventSystemHandlerHierarchy <T>(handler, RegisterHandler); }
private InputWriter CreateTouchWriter(IEventSystemHandler handler) { if (currentInputWriter != null) { DestroyWriter(); } if (recordExecuteEvent.SkipSendTouch) { return(null); } var selectable = handler as Selectable; if (selectable != null && !selectable.interactable) { return(null); } var selectGameObject = (handler as Component).gameObject; if (selectGameObject.tag == "SkipRecord") { return(null); } Controller.WriteDelay(); var isDrag = handler is ScrollRect; var currentDragSessionName = (isDrag ? "Drag_" : "Click_") + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + selectGameObject.name + ".txt"; var currentDragSessionPath = Path.Combine(PathFileTarget, currentDragSessionName); Controller.WriteScript((isDrag ? "--drag " : "--click ") + selectGameObject.name); Controller.WriteScript("coroutine.yield(MouseInput(\"" + selectGameObject.name + "\", \"" + currentDragSessionName + "\"));" + Environment.NewLine); currentInputWriter = new TouchWriter(); currentInputWriter.StartWriter(selectGameObject, currentDragSessionPath); Controller.BeginWrite(); return(currentInputWriter); }
public static bool Execute <T>(GameObject target, BaseEventData eventData, ExecuteEvents.EventFunction <T> functor) where T : IEventSystemHandler { List <IEventSystemHandler> list = ExecuteEvents.s_HandlerListPool.Get(); ExecuteEvents.GetEventList <T>(target, list); int i = 0; while (i < list.Count) { T handler; try { handler = (T)((object)list[i]); } catch (Exception innerException) { IEventSystemHandler eventSystemHandler = list[i]; Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, eventSystemHandler.GetType().Name), innerException)); goto IL_8F; } goto Block_2; IL_8F: i++; continue; Block_2: try { functor(handler, eventData); } catch (Exception exception) { Debug.LogException(exception); } goto IL_8F; } int count = list.Count; ExecuteEvents.s_HandlerListPool.Release(list); return(count > 0); }
/// <inheritdoc /> private void RemoveHandlerFromMap(Type handlerType, IEventSystemHandler handler) { List <EventHandlerEntry> handlers; if (!EventHandlersByType.TryGetValue(handlerType, out handlers)) { return; } for (int i = handlers.Count - 1; i >= 0; i--) { if (handlers[i].handler == handler) { handlers.RemoveAt(i); } } if (handlers.Count == 0) { EventHandlersByType.Remove(handlerType); } }
private void AddHandlerToMap(Type handlerType, IEventSystemHandler handler) { bool isParentObjectRegistered = false; var componentHandler = handler as Component; if (componentHandler != null && EventListeners.Contains(componentHandler.gameObject)) { isParentObjectRegistered = true; WarnAboutConflictingApis(componentHandler.gameObject.name); } List <EventHandlerEntry> handlers; if (!EventHandlersByType.TryGetValue(handlerType, out handlers)) { handlers = new List <EventHandlerEntry> { new EventHandlerEntry(handler, isParentObjectRegistered) }; EventHandlersByType.Add(handlerType, handlers); return; } bool handlerExists = false; for (int i = handlers.Count - 1; i >= 0; i--) { if (handlers[i].handler == handler) { handlerExists = true; break; } } if (!handlerExists) { handlers.Add(new EventHandlerEntry(handler, isParentObjectRegistered)); } }
public static List <GameObject> ThroughAndExecute <T>(this IEventSystemHandler mono, PointerEventData baseData, ExecuteEvents.EventFunction <T> eventFunction) where T : IEventSystemHandler { return(ThroughAndExecute(baseData, eventFunction)); }
public static void Execute <T>(this IEventSystemHandler mono, PointerEventData baseData, ExecuteEvents.EventFunction <T> eventFunction, List <GameObject> results) where T : IEventSystemHandler { Execute(baseData, eventFunction, results); }
private static void ExecuteExit(IEventSystemHandler handler, BaseEventData eventData) { }
public EventHandlerEntry(IEventSystemHandler h, bool isParentListener = false) { handler = h; parentObjectIsInObjectCollection = isParentListener; }
public static void SetHandler(IEventSystemHandler handler) { EventSystemHandler = handler; }