Пример #1
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);
        }
Пример #2
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);
        }