Ejemplo n.º 1
0
        public void RemoveHover(ProximityController controller)
        {
                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log(name + ": Remove hover: " + controller.name);
            }
                        #endif

            List <ProximityController> controllerList = new List <ProximityController>()
            {
                controller
            };

            // If there is a controller and it holds this object:
            int numRemaining = controller.RemoveHoveredItem(this);

            hoveredList.Remove(controller);

            CheckHoverState(controllerList);


            if (numRemaining > 0)
            {
                // turn on other hovered object
                Interactable other = controller.GetTopHoveredItem();
                if (other != null)
                {
                    if (other.GetComponent <Interactable> () != null)
                    {
                        other.GetComponent <Interactable> ().CheckHoverState(controllerList);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual bool ObjectCanBeHovered(Interactable interactable, ProximityController interactor)
        {
            if (interactable == null || !interactable.isActiveAndEnabled)
            {
                return(false);
            }

            return(interactable.CanBeHovered(interactor));
        }
Ejemplo n.º 3
0
        public bool SetHoverState(ProximityController controller, HoverState newHoverState)
        {
            if (newHoverState == HoverState.Hovered || newHoverState == HoverState.None)
            {
                Debug.LogError("Use AddHover or RemoveHover for setting hover state");
                // DSL: Might just want to re-route
                return(false);
            }

            // HoverState.Pressed or HoverState.DraggedAway
            if (newHoverState == HoverState.Pressed)
            {
                if (hoverState != HoverState.Hovered && hoverState != HoverState.DraggedAway)
                {
                    Debug.LogError("Cannot move to Pressed state from " + hoverState);
                    // DSL: Might just want to re-route
                    return(false);
                }
                if (!controller.SortedHoveredObjectsContains(this))
                {
                    controller.AddHoveredItem(this);
                }
                if (!hoveredList.Contains(controller))
                {
                    hoveredList.Add(controller);
                }
            }
            else if (newHoverState == HoverState.DraggedAway)
            {
                if (hoverState != HoverState.Pressed)
                {
                    Debug.LogError("Cannot move to DraggedAway state from " + hoverState);
                    // DSL: Might just want to re-route
                    return(false);
                }
                if (controller.SortedHoveredObjectsContains(this))
                {
                    controller.RemoveHoveredItem(this);
                }
                hoveredList.Remove(controller);
            }

            List <ProximityController> controllerList = new List <ProximityController>()
            {
                controller
            };

            ApplyHoverState(newHoverState, true, controllerList);
            hoverState = newHoverState;

            return(true);
        }
Ejemplo n.º 4
0
        public void TriggerEnter(ProximityController controller)
        {
            if (controller.downedInteractable == this)
            {
                if (hoverState == HoverState.DraggedAway)
                {
                    SetHoverState(controller, HoverState.Pressed);
                }
            }

            if (!controller.SortedHoveredObjectsContains(this))
            {
                AddHover(controller);
            }
        }
Ejemplo n.º 5
0
        public virtual float DistanceFromController(ProximityController controller)
        {
            Vector3 position         = controller.InteractionSourceTransform().position;
            float   shortestDistance = float.MaxValue;

            foreach (Collider collider in GetComponentsInChildren <Collider>())
            {
                Vector3 closest  = collider.ClosestPointOnBounds(position);
                float   distance = (closest - position).magnitude;              // Vector3.Distance (AttachPosition (), closest);

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                }
            }
            return(shortestDistance);
        }
Ejemplo n.º 6
0
        protected virtual void OnTriggerEnter(Collider c)
        {
                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("TRIGGER ENTER: " + this.name + " / " + c.gameObject.name);
            }
                        #endif

            var handle = c.gameObject.GetComponent <ControllerLimb> ();
            if (handle == null || handle.controller == null)
            {
                return;
            }

            ProximityController controller = handle.controller;
            TriggerEnter(controller);
        }
Ejemplo n.º 7
0
        public bool RemovePressedState(ProximityController controller)
        {
            if (hoverState != HoverState.Pressed && hoverState != HoverState.DraggedAway)
            {
                Debug.LogError(name + ": Cannot remove Pressed state from " + hoverState);
                return(false);
            }

            List <ProximityController> controllerList = new List <ProximityController>()
            {
                controller
            };
            HoverState newHoverState = HoverState.None;

            ApplyHoverState(newHoverState, true, controllerList);
            hoverState = newHoverState;

            controller.SurfaceTopHoveredObject();
            return(true);
        }
Ejemplo n.º 8
0
        public virtual bool CanBeHovered(ProximityController controller)
        {
            if (!interactionEnabled)
            {
                return(false);
            }

            if (!controller.CanHover(gameObject))
            {
                                #if UNITY_EDITOR
                if (debugHover)
                {
                    Debug.Log(name + ": Controller Cannot hover: Cannot be hovered");
                }
                                #endif
                return(false);
            }

            if (!controller.DriverOperationIdle(0))
            {
                                #if UNITY_EDITOR
                if (debugHover)
                {
                    Debug.Log(name + ": Driver Operation not idle: Cannot be hovered");
                }
                                #endif
                return(false);
            }

            if (PollCanHover != null)
            {
                foreach (PollCanHoverQuery canHover in PollCanHover.GetInvocationList())
                {
                    if (!canHover(controller))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
//
//		if (driver.DriverOperationIdle (0) || driver.DriverOperationStarted(0)) {
//			// If in the unpressed state, add hover if available, remove old hover if needed
//			if (hoveredInteractableUi != null) {
//				if (hoveredInteractableUi.hoverState == HoverState.None) {
//					hoveredInteractableUi.AddHover (this);
//				}
//			} else if (driver.DriverOperationStarted(0)) {
//				// No hover, and no selected object, but button tapped
//				uiLaser.ClearUiSelection();
//			}
//
//			if (lastClosestHitObject != hoveredSelectable) {
//				if (previousClosestInteractableUi != null) {
//					previousClosestInteractableUi.RemoveHover (this);
//				}
//			}
//
//		} else {
//			// Controller is in pressed or exiting state. Only process if pressed with downed object
//			if (downedInteractable != null) {
//				if (downedInteractable == hoveredInteractableUi) {
//					// We are on the downed ui object. We need to check the hover state
//					if (downedInteractable.hoverState == HoverState.DraggedAway) {
//						downedInteractable.SetHoverState (this, HoverState.Pressed);
//					}
//				} else {
//					if (downedInteractable.hoverState == HoverState.Pressed) {
//						downedInteractable.SetHoverState (this, HoverState.DraggedAway);
//					}
//				}
//			}
//		}



        public void TriggerExit(ProximityController controller)
        {
            if (controller.downedInteractable == this)
            {
                if (hoverState == HoverState.Pressed)
                {
                    SetHoverState(controller, HoverState.DraggedAway);
                }
            }

                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log(name + ": trigger exit: " + controller.name + " -- " + controller.SortedHoveredObjectsContains(this));
            }
                        #endif
            if (controller.SortedHoveredObjectsContains(this))
            {
                RemoveHover(controller);
            }
        }
Ejemplo n.º 10
0
        void Awake()
        {
            if (controller == null)
            {
                controller = GetComponentInParent <ProximityController> ();
                controller.interactionPoint = gameObject;
            }

            if (GetComponent <Rigidbody> () == null)
            {
                Rigidbody rb = gameObject.AddComponent <Rigidbody> ();
                rb.isKinematic            = true;
                rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            }

            if (GetComponentInChildren <Collider> () != null)
            {
                GetComponentInChildren <Collider> ().isTrigger = true;
            }
            else
            {
                Debug.LogError("No collider set on limb");
            }
        }
Ejemplo n.º 11
0
        void OnTriggerExit(Collider c)
        {
                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("TRIGGER EXIT: " + name + ": on trigger exit: " + c.gameObject.name + " -- handle: " + c.gameObject.GetComponent <ControllerLimb>());
            }
                        #endif
            var handle = c.gameObject.GetComponent <ControllerLimb>();
            if (handle == null || handle.controller == null)
            {
                return;
            }

            ProximityController controller = handle.controller;

                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("Call trigger exit");
            }
                        #endif
            TriggerExit(controller);
        }
Ejemplo n.º 12
0
 public override float DistanceFromController(ProximityController controller)
 {
     return((controller.InteractionSourceTransform().position - transform.position).magnitude);
 }
Ejemplo n.º 13
0
 public virtual void OnDetachedController(ProximityController controller)
 {
 }
Ejemplo n.º 14
0
        public bool AddHover(ProximityController controller)
        {
            if (!this.enabled)
            {
                return(false);
            }

            List <ProximityController> controllerList = new List <ProximityController>()
            {
                controller
            };

                        #if UNITY_EDITOR
            if (debugHover)
            {
                if (controller.gameObject == gameObject)
                {
                    Debug.LogError("Double hover on gameObject " + controller.name);
                }
            }
                        #endif
//
//			if (!CanBeHovered (controller)) {
//				#if UNITY_EDITOR
//				if (debugHover)
//				{
//					Debug.Log("Can't be hovered: " + this.name);
//				}
//				#endif
//
//				return false;
//			}
//
            if (hoveredList.Contains(controller))
            {
                                #if UNITY_EDITOR
                if (debugHover)
                {
                    Debug.Log("Hover Stay: " + this.name);
                }
                                #endif
//				CheckHoverState(controllerList); // this passes down the hover stay command
                return(false);
            }

                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("Adding Hovered controller: " + controller.name);
            }
                        #endif
            hoveredList.Add(controller);

            Interactable other = null;
            if (controller.GetHoverCount() > 0)
            {
                // There's another hovered object, grab handle for it to exit the hover state
                other = controller.GetTopHoveredItem();
            }

                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("Adding Hovered item: " + this.name);
            }
                        #endif

            controller.AddHoveredItem(this);

                        #if UNITY_EDITOR
            if (debugHover)
            {
                Debug.Log("Checking hover state: " + this.name);
            }
                        #endif

            CheckHoverState(controllerList);

            if (other != null)
            {
                if (other.GetComponent <Interactable> () != null)
                {
                    other.GetComponent <Interactable> ().CheckHoverState(controllerList);
                }
            }
            return(true);
        }