void OnShellSelectEvent(InputSourceBase inputSource, bool newState) { AFocuser focuser = InputSourceFocuser.GetFocuserForInputSource(inputSource); if (focuser != null) { if (newState) { if (inputSource != InputSources.Instance.hands) // && inputSource != InputSources.Instance.fawkes) { OnPressedEvent(focuser); // Need to track hold time before firing this HoldStartedEvent(focuser, focuser.FocusRay); } } else { if (inputSource != InputSources.Instance.hands) // && inputSource != InputSources.Instance.fawkes) { OnReleasedEvent(focuser); // Only fire this if HoldStarted was fired HoldCompletedEvent(focuser, focuser.FocusRay); // Need to only fire this if hold wasn't started? TappedEvent(focuser, focuser.FocusRay); } } } }
public static AFocuser GetFocuserForInputSource(InputSourceBase inputSource) { AFocuser focuser = null; if (FocusManager.Instance != null) { for (int index = 0; index < FocusManager.Instance.Focusers.Length; index++) { InputSourceFocuser sourceFocuser = FocusManager.Instance.Focusers[index] as InputSourceFocuser; if (sourceFocuser != null && sourceFocuser.m_InputSource == inputSource) { focuser = FocusManager.Instance.Focusers[index]; break; } } //If we haven't found a specific focuser use the gaze. if (focuser == null) { focuser = FocusManager.Instance.GazeFocuser; } } return(focuser); }
/// <summary> /// Updates all control states. See InputControlState.cs. /// </summary> void UpdateStates() { // Hand zoom gesture stateHandZoom.ApplyState(inputSources.hands.dragControl); // Mouse wheel zoom stateMouseWheelZoom.AddState(false, new Vector2(0, inputSources.editor.mouseSource.ScrollWheelDelta)); stateMouseWheelZoom.AddState(false, new Vector2(0, inputSources.worldCursorMouse.mouseSource.ScrollWheelDelta)); stateMouseWheelZoom.FinalizeState(); // SixDOF zoom gesture stateSixDOFZoom.ApplyDelta(false, new Vector2(0, inputSources.touch6D.dragControl.delta.y)); // Controller input maps to scrolling, zooming, and freecam input stateLeftJoyScroll.ApplyDelta(false, inputSources.gamepad.leftJoyVector); stateLeftJoyTranslate.ApplyDelta(false, inputSources.gamepad.leftJoyVector); stateTrigZoom.ApplyDelta(false, new Vector2(0, -inputSources.gamepad.trigVector.x + inputSources.gamepad.trigVector.y)); stateRightJoyRotate.ApplyDelta(false, inputSources.gamepad.rightJoyVector); statePadTranslate.ApplyDelta(false, inputSources.gamepad.padVector); statePadCardinal.ApplyDelta(false, inputSources.gamepad.padVector); // Joystick cardinal state Vector2 joyPos = Vector2.zero; if (inputSources.gamepadCardinal.IsActiveTargetingSource()) { float mag = 0.7f; if (inputSources.gamepad.leftJoyVector.sqrMagnitude > mag * mag) { joyPos = inputSources.gamepad.leftJoyVector; // Quantize joyPos.x = (float)Mathf.RoundToInt(5f * joyPos.x) / 5f; joyPos.y = (float)Mathf.RoundToInt(5f * joyPos.y) / 5f; } } stateLeftJoyCardinal.ApplyDelta(false, joyPos); // Update drag gesture InputSourceBase curSource = inputSwitchLogic.CurrentTargetingSource as InputSourceBase; if (curSource != null && curSource.IsManipulating()) { stateTargetScroll.ApplyPos(true, curSource.GetManipulationPlaneProjection()); //Debug.Log("scroll state delta: " + stateTargetScroll.delta); } else { stateTargetScroll.ApplyPos(false, Vector2.zero); //Debug.Log("scroll (done) state delta: " + stateTargetScroll.delta); } }
/// <summary> /// Returns true if something is being updated /// </summary> public bool IsAnyManipulating() { bool manipulating = false; InputSourceBase[] sources = InputShellMap.Instance.inputSources.sources; for (int index = 0; index < sources.Length && !manipulating; index++) { InputSourceBase source = sources[index]; manipulating = (source != null && source.IsManipulating()); } return(manipulating); }
void OnShellSelectEvent(InputSourceBase inputSource, bool newState) { AFocuser focuser = InputSourceFocuser.GetFocuserForInputSource(inputSource); if (focuser != null) { if (newState) { if (inputSource != InputSources.Instance.hands) { OnPressedEvent(focuser); // Need to track hold time before firing this HoldStartedEvent(focuser, focuser.FocusRay); } } else { if (inputSource != InputSources.Instance.hands) { OnReleasedEvent(focuser); // Only fire this if HoldStarted was fired HoldCompletedEvent(focuser, focuser.FocusRay); // Send double tap (should be multi-tap someday) if (Time.time - lastHoldReleaseTime <= MultiTapWindow) { DoubleTappedEvent(focuser, focuser.FocusRay); } // Need to only fire this if hold wasn't started? TappedEvent(focuser, focuser.FocusRay); lastHoldReleaseTime = Time.time; } } } }
private void DoTargetSourceSelectChanged(InputSourceBase inputSource, bool newState) { OnTargetSourceSelectChanged(inputSource, newState); }
private void OnSelectChanged(InputSourceBase sourceBase, bool arg2) { AddMessage("Select Activated"); }
private void OnMenuChanged(InputSourceBase sourceBase, bool arg2) { AddMessage("Menu Activated"); }
/// <summary> /// Returns true if the specified source is the active targeting source /// </summary> public bool IsTargetingSourceActive(InputSourceBase source) { return(CurrentTargetingSource == source as ITargetingInputSource); }
/// <summary> /// Initialization. Gets all input sources that exist in the scene, then sorts virtual sources /// to the end. Finally, the input source fields in InputSources are automatically assigned using reflection. /// </summary> public void Init(GameObject owner) { Instance = this; // Currently looks for all input sources in scene sources = GameObject.FindObjectsOfType <InputSourceBase>(); // Sort so that virtual sources are after physical for (int i = 0; i < sources.Length; ++i) { // If we find a virtual source, look for non-virtual sources if (sources[i].IsVirtual) { int h = sources.Length - 1; for (; h > i; --h) { // Found a non-virtual source, swap them if (!sources[h].IsVirtual) { InputSourceBase temp = sources[i]; sources[i] = sources[h]; sources[h] = temp; break; } } // There were no non-virtual sources after this one! if (h <= i) { break; } } } List <InputSourceBase> addedSources = new List <InputSourceBase>(); // Auto-assign all InputSourceBase fields to the corresponding instance #if USE_WINRT foreach (FieldInfo field in GetType().GetTypeInfo().DeclaredFields) #else FieldInfo[] myFields = GetType().GetFields(); foreach (FieldInfo field in myFields) #endif { // Found an InputSourceBase field #if USE_WINRT if (field.FieldType.GetTypeInfo().IsSubclassOf(typeof(InputSourceBase))) #else if (field.FieldType.IsSubclassOf(typeof(InputSourceBase))) #endif { // Con: Must create in editor, Pro: can configure properties // Find the matching component bool didSet = false; foreach (InputSourceBase isb in sources) { if (isb.GetType() == field.FieldType) { field.SetValue(this, isb); didSet = true; break; } } if (!didSet) { //Debug.LogError("Didn't find InputSourceBase for field " + field.Name); // Pro: Don't need to create in editor, Con: can't configure // Create the component if not found. It will just have default values. Component c = owner.AddComponent(field.FieldType); field.SetValue(this, c); addedSources.Add(c as InputSourceBase); } } else if (field.FieldType.IsArray #if USE_WINRT && field.FieldType.GetElementType().GetTypeInfo().IsSubclassOf(typeof(InputSourceBase)) #else && field.FieldType.GetElementType().IsSubclassOf(typeof(InputSourceBase)) #endif ) { Type elementType = field.FieldType.GetElementType(); List <InputSourceBase> typeSources = new List <InputSourceBase>(); foreach (InputSourceBase isb in sources) { if (isb.GetType() == elementType) { typeSources.Add(isb); } } object[] arr = (object[])Array.CreateInstance(elementType, typeSources.Count); for (int index = 0; index < arr.Length; index++) { arr[index] = typeSources[index]; } field.SetValue(this, arr); } } // Add the added soruces back into the source array InputSourceBase[] newSourceArray = new InputSourceBase[addedSources.Count + sources.Length]; sources.CopyTo(newSourceArray, 0); addedSources.CopyTo(newSourceArray, sources.Length); sources = newSourceArray; ConfigureActiveSources(); }