Example #1
0
    /// <summary>
    /// Gets the type of event represented by the pointer source and trigger.
    /// </summary>
    /// <param name="source">
    /// The source to test.
    /// </param>
    /// <param name="triggerType">
    /// The trigger type to check.
    /// </param>
    /// <returns>
    /// The event type
    /// </returns>
    static private ReportEventTypes GetEventType(IPointingSource source, TriggerType triggerType)
    {
        if (source == null)
        {
            throw new ArgumentNullException(nameof(source));
        }
        bool isGaze = (source is GazeManager);
        // Figure out what type of event this is
        ReportEventTypes eventType;

        switch (triggerType)
        {
        case TriggerType.Enter:
            eventType = (isGaze ? ReportEventTypes.GazeEnter : ReportEventTypes.PointerEnter);
            break;

        case TriggerType.Exit:
            eventType = (isGaze ? ReportEventTypes.GazeExit : ReportEventTypes.PointerExit);
            break;

        default:
            eventType = (isGaze ? ReportEventTypes.GazeStay : ReportEventTypes.PointerStay);
            break;
        }
        return(eventType);
    }
 /*
  * /// <summary>
  * /// On double tapped if double tapped interaction type then attach or detach
  * /// </summary>
  * /// <param name="eventArgs"></param>
  * protected void OnDoubleTapped(InputEventData eventArgs)
  * {
  *  if (m_InteractionType == AttachInteractionEnum.DoubleTapped)
  *  {
  *      if (m_bAttached && m_InteractingFocus == eventArgs.Focuser)
  *      {
  *                              m_InteractingFocus.ReleaseFocus();
  *          DetachObject();
  *      }
  *      else if (m_InteractingFocus == null)
  *      {
  *                              eventArgs.Focuser.LockFocus();
  *          AttachObject(eventArgs.Focuser);
  *      }
  *  }
  * }
  */
 private void AttachObject(IPointingSource pointer)
 {
     m_InteractingFocus = FocusManager.Instance.GetFocusDetails(pointer);
     gameObject.layer   = LayerMask.NameToLayer("Ignore Raycast");
     StartCoroutine("CarryObject");
     m_bAttached = true;
 }
Example #3
0
        private void SetPointer(IPointingSource newPointer)
        {
            if (currentPointer != newPointer)
            {
                if (currentPointer != null)
                {
                    FocusManager.Instance.UnregisterPointer(currentPointer);
                }

                currentPointer = newPointer;

                if (newPointer != null)
                {
                    FocusManager.Instance.RegisterPointer(newPointer);
                }

                if (Cursor != null)
                {
                    Cursor.Pointer = newPointer;
                }
            }

            Debug.Assert(currentPointer != null, "No Pointer Set!");

            if (IsGazePointerActive)
            {
                DetachInputSourcePointer();
            }
        }
Example #4
0
        protected override void Awake()
        {
            base.Awake();

            if (registeredPointers != null)
            {
                for (int iPointer = 0; iPointer < registeredPointers.Length; iPointer++)
                {
                    GameObject owner = registeredPointers[iPointer];

                    if (owner == null)
                    {
                        Debug.LogError("AutoRegisteredPointers contains a null (\"None\") object.");
                        break;
                    }

                    IPointingSource pointingSource = owner.GetComponent <IPointingSource>();

                    if (pointingSource == null)
                    {
                        Debug.LogErrorFormat("AutoRegisteredPointers contains object \"{0}\" which is missing its {1} component.",
                                             owner.name,
                                             typeof(IPointingSource).Name
                                             );
                        break;
                    }

                    RegisterPointer(pointingSource);
                }
            }
        }
    void focusChanged(IPointingSource pointer, GameObject oldObject, GameObject newObject)
    {
        if (oldObject != null)
        {
            oldObject.SendMessageUpwards("OnDefocus", SendMessageOptions.DontRequireReceiver);

            var handler = VisualizedTextUnfocused;
            if (handler != null)
            {
                handler.Invoke(this, new EventArgs());
            }
        }
        if (newObject != null)
        {
            newObject.SendMessageUpwards("OnFocus", SendMessageOptions.DontRequireReceiver);
            if (newObject.tag != null && newObject.tag == "visualTextCanvas")
            {
                Text   visualText  = newObject.transform.Find("Text").gameObject.GetComponent <Text>();
                string focusedtext = visualText.text;

                VisualizedTextFocusedEventArgs args = new VisualizedTextFocusedEventArgs();
                args.visualizedText = focusedtext;

                var handler = VisualizedTextFocused;
                if (handler != null)
                {
                    handler.Invoke(this, args);
                }
            }
        }
    }
Example #6
0
        protected override void InitializeInternal()
        {
            if (registeredPointers != null)
            {
                for (int iPointer = 0; iPointer < registeredPointers.Length; iPointer++)
                {
                    GameObject owner = registeredPointers[iPointer];

                    if (owner == null)
                    {
                        Debug.LogError("AutoRegisteredPointers contains a null (\"None\") object.");
                        break;
                    }

                    IPointingSource pointingSource = owner.GetComponent<IPointingSource>();

                    if (pointingSource == null)
                    {
                        Debug.LogErrorFormat("AutoRegisteredPointers contains object \"{0}\" which is missing its {1} component.",
                            owner.name,
                            typeof(IPointingSource).Name
                        );
                        break;
                    }

                    RegisterPointer(pointingSource);
                }
            }

            if (pointers.Count == 0 && autoRegisterGazePointerIfNoPointersRegistered && GazeManager.ConfirmInitialized())
            {
                RegisterPointer(GazeManager.Instance);
            }
        }
Example #7
0
        private void FinishTeleport()
        {
            if (currentPointingSource != null)
            {
                currentPointingSource = null;

                if (isTeleportValid)
                {
                    RaycastHit hitInfo;
                    Vector3    hitPos = teleportMarker.transform.position + Vector3.up * (Physics.Raycast(CameraCache.Main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 2.6f);

                    fadeControl.DoFade(0.25f, 0.5f, () =>
                    {
                        if (smoothTeleport)
                        {
                            StartCoroutine(SmoothTeleport(hitPos));
                        }
                        else
                        {
                            InmediateTeleport(hitPos);
                        }
                    }, null);
                }

                DisableMarker();
            }
        }
Example #8
0
        public void RegisterPointer(IPointingSource pointingSource)
        {
            Debug.Assert(pointingSource != null);

            if (TryGetPointerIndex(pointingSource) != null)
            {
                // This pointing source is already registered and active.
                return;
            }

            PointerData pointer;

            if (pointingSource is GazeManager)
            {
                if (gazeManagerPointingData == null)
                {
                    gazeManagerPointingData = new PointerData(pointingSource);
                }
                else
                {
                    gazeManagerPointingData.ResetFocusedObjects();
                }

                pointer = gazeManagerPointingData;
            }
            else
            {
                pointer = new PointerData(pointingSource);
            }

            pointers.Add(pointer);
        }
Example #9
0
        private PointerData GetPointer(IPointingSource pointingSource)
        {
            int?iPointer = TryGetPointerIndex(pointingSource);

            Debug.Assert(iPointer != null);
            return(pointers[iPointer.Value]);
        }
Example #10
0
 private void CheckLockFocus(IPointingSource focuser)
 {
     if (_LockFocus)
     {
         //LockFocus(focuser);
     }
 }
Example #11
0
 private void ReleaseFocuser()
 {
     if (_selectingFocuser != null)
     {
         _selectingFocuser.FocusLocked = false;
         _selectingFocuser             = null;
     }
 }
Example #12
0
 private void ReleaseFocus()
 {
     if (_selectingFocuser != null)
     {
         // _selectingFocuser.ReleaseFocus();
         _selectingFocuser = null;
     }
 }
Example #13
0
        /// <summary>
        /// Checks if exactly one pointer is registered and returns it if so.
        /// </summary>
        /// <returns>The registered pointer if exactly one is registered, null otherwise.</returns>
        public IPointingSource TryGetSinglePointer()
        {
            IPointingSource singlePointer = (pointers.Count == 1)
                ? pointers[0].PointingSource
                : null;

            return(singlePointer);
        }
Example #14
0
 private void LockFocuser(IPointingSource focuser)
 {
     if (focuser != null)
     {
         ReleaseFocuser();
         _selectingFocuser             = focuser;
         _selectingFocuser.FocusLocked = true;
     }
 }
Example #15
0
        private void RaisePointerSpecificFocusChangedEvents(IPointingSource pointer, GameObject oldFocusedObject, GameObject newFocusedObject)
        {
            InputManager.Instance.RaisePointerSpecificFocusChangedEvents(pointer, oldFocusedObject, newFocusedObject);

            if (PointerSpecificFocusChanged != null)
            {
                PointerSpecificFocusChanged(pointer, oldFocusedObject, newFocusedObject);
            }
        }
Example #16
0
 private void LockFocus(IPointingSource focuser)
 {
     if (focuser != null)
     {
         ReleaseFocus();
         _selectingFocuser = focuser;
         // _selectingFocuser.LockFocus();
     }
 }
Example #17
0
        /// <summary>
        /// Checks if exactly one pointer is registered and returns it if so.
        /// </summary>
        /// <returns>The registered pointer if exactly one is registered, null otherwise.</returns>
        public bool TryGetSinglePointer(out IPointingSource pointingSource)
        {
            if (pointers.Count == 1)
            {
                pointingSource = pointers[0].PointingSource;
                return(true);
            }

            pointingSource = null;
            return(false);
        }
Example #18
0
        public void Remove()
        {
            IPointingSource pointingSource = null;

            if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
            {
                GameObject obj = FocusManager.Instance.GetFocusedObject(pointingSource);
                obj.GetComponent <MoveBlock>().ShowBoundingBox = false;
                Destroy(obj);
            }
        }
Example #19
0
 /// <summary>
 /// Updates the currently targeted object and cursor modifier upon getting
 /// an event indicating that the focused object has changed.
 /// </summary>
 /// <param name="pointer">The pointer associated with this focus change.</param>
 /// <param name="oldFocusedObject">Object that was previously being focused.</param>
 /// <param name="newFocusedObject">New object being focused.</param>
 protected virtual void OnPointerSpecificFocusChanged(IPointingSource pointer, GameObject oldFocusedObject, GameObject newFocusedObject)
 {
     if (pointer == Pointer)
     {
         TargetedObject = newFocusedObject;
         if (newFocusedObject != null)
         {
             OnActiveModifier(newFocusedObject.GetComponent <CursorModifier>());
         }
     }
 }
Example #20
0
        public GameObject GetFocusedObject(IPointingSource pointingSource)
        {
            PointerData pointerData;
            GameObject  focusedObject = null;

            if (GetPointerData(pointingSource, out pointerData))
            {
                focusedObject = pointerData.End.Object;
            }

            return(focusedObject);
        }
Example #21
0
        public FocusDetails GetFocusDetails(IPointingSource pointingSource)
        {
            PointerData  pointerData;
            FocusDetails details = default(FocusDetails);

            if (GetPointerData(pointingSource, out pointerData))
            {
                details = pointerData.End;
            }

            return(details);
        }
        public PointerInputEventData GetSpecificPointerEventData(IPointingSource pointer)
        {
            PointerData pointerEventData;

            if (!GetPointerData(pointer, out pointerEventData))
            {
                return(null);
            }

            pointerEventData.UnityUIPointerData.selectedObject = GetFocusedObject(pointer);
            return(pointerEventData.UnityUIPointerData);
        }
Example #23
0
        private bool GetPointerData(IPointingSource pointingSource, out PointerData pointerData)
        {
            int pointerIndex;

            if (TryGetPointerIndex(pointingSource, out pointerIndex))
            {
                pointerData = pointers[pointerIndex];
                return(true);
            }

            pointerData = null;
            return(false);
        }
Example #24
0
        private bool TryGetPointerIndex(IPointingSource pointingSource, out int pointerIndex)
        {
            for (int i = 0; i < pointers.Count; i++)
            {
                if (pointingSource == pointers[i].PointingSource)
                {
                    pointerIndex = i;
                    return(true);
                }
            }

            pointerIndex = -1;
            return(false);
        }
Example #25
0
        public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource pointingSource)
        {
            for (int i = 0; i < pointers.Count; i++)
            {
                if (pointers[i].PointingSource.OwnsInput(eventData))
                {
                    pointingSource = pointers[i].PointingSource;
                    return(true);
                }
            }

            pointingSource = null;
            return(false);
        }
Example #26
0
        /// <summary>
        /// Raise focus enter and exit events for when an input (that supports pointing) points to a game object.
        /// </summary>
        /// <param name="pointer"></param>
        /// <param name="oldFocusedObject"></param>
        /// <param name="newFocusedObject"></param>
        public void RaisePointerSpecificFocusChangedEvents(IPointingSource pointer, GameObject oldFocusedObject, GameObject newFocusedObject)
        {
            if (oldFocusedObject != null)
            {
                pointerSpecificEventData.Initialize(pointer);
                ExecuteEvents.ExecuteHierarchy(oldFocusedObject, pointerSpecificEventData, OnPointerSpecificFocusExitEventHandler);
            }

            if (newFocusedObject != null)
            {
                pointerSpecificEventData.Initialize(pointer);
                ExecuteEvents.ExecuteHierarchy(newFocusedObject, pointerSpecificEventData, OnPointerSpecificFocusEnterEventHandler);
            }
        }
Example #27
0
        private int?TryGetPointerIndex(IPointingSource pointingSource)
        {
            int?found = null;

            for (int i = 0; i < pointers.Count; i++)
            {
                if (pointers[i].PointingSource == pointingSource)
                {
                    found = i;
                    break;
                }
            }

            return(found);
        }
Example #28
0
        /// <summary>
        /// Handle the pointer specific changes to fire focus enter and exit events
        /// </summary>
        /// <param name="pointer">The pointer associated with this focus change.</param>
        /// <param name="oldFocusedObject">Object that was previously being focused.</param>
        /// <param name="newFocusedObject">New object being focused.</param>
        private void OnPointerSpecificFocusChanged(IPointingSource pointer, GameObject oldFocusedObject, GameObject newFocusedObject)
        {
            PointerSpecificEventData eventData = new PointerSpecificEventData(EventSystem.current);

            eventData.Initialize(pointer);

            if (newFocusedObject != null && Isinteractable(newFocusedObject))
            {
                FocusEnter(newFocusedObject, eventData);
            }

            if (oldFocusedObject != null && Isinteractable(oldFocusedObject))
            {
                FocusExit(oldFocusedObject, eventData);
            }
        }
Example #29
0
        private void FinishTeleport()
        {
            if (currentPointingSource != null)
            {
                currentPointingSource = null;

                if (isTeleportValid)
                {
                    fadeControl.DoFade(0.25f, 0.5f, () =>
                    {
                        SetWorldPosition(teleportMarker.transform.position);
                    }, null);
                }

                DisableMarker();
            }
        }
Example #30
0
    private void RecordEvent(IPointingSource source, TriggerType triggerType)
    {
        // Get the event type
        var eventType = GetEventType(source, triggerType);

        // Is this gaze or controller?
        bool isGaze = (source is GazeManager);

        // Placeholders
        Vector3 worldPosition, localPosition;

        // Exit events need to be handled differently because exit events do not occur "on object"
        if (triggerType != TriggerType.Exit)
        {
            // Use the position from the pointing source
            worldPosition = source.Result.End.Point;
            localPosition = transform.InverseTransformPoint(worldPosition);

            // Update last known positions for eventual exit event
            lastWorldPosition = worldPosition;
            lastLocalPosition = localPosition;
        }
        else
        {
            // It is an exit event, use the last known position "on object"
            worldPosition = lastWorldPosition;
            localPosition = lastLocalPosition;
        }

        // If recording for this event is not enabled, skip the rest of this event
        if (!IsEnabled(eventType))
        {
            return;
        }

        // Calculate remaining parameters
        string packageToken = HardwareIdentification.GetPackageSpecificToken();
        string sourceName   = (isGaze ? "Gaze" : "Controller");

        // Create event
        ReportableFocusEvent evt = new ReportableFocusEvent(packageToken, EntityName, sourceName, eventType, DateTimeOffset.Now, localPosition, worldPosition);

        // Report event
        AnalyticsFocusReporter.Instance.InsertReportableFocusEvent(evt);
    }