예제 #1
0
 public static bool AddTarget(ICanvasRaycastTarget obj)
 {
     return(obj == null ? false : canvases.AddUnique(obj));
 }
예제 #2
0
 public static bool AddNewPosesListener(INewPoseListener listener)
 {
     return(s_listeners.AddUnique(listener));
 }
예제 #3
0
 public void AddRaycastMethod(IRaycastMethod obj)
 {
     methods.AddUnique(obj);
 }
예제 #4
0
 public void AddGenerator(IRaySegmentGenerator generator)
 {
     generators.AddUnique(generator);
 }
예제 #5
0
 public virtual void AddElement(BaseCurved3DElement element)
 {
     m_elements.AddUnique(element);
 }
예제 #6
0
        protected virtual void Update()
        {
            // need remove because OnTriggerExit doesn't automatically called when collider destroied
            hoveredColliderCount.RemoveAll(RemoveDestroiedCollider);

            // process enter
            var hoveredObjectsPrev = hoveredObjects;

            hoveredObjects = IndexedSetPool <GameObject> .Get();

            for (int i = hoveredColliderCount.Count - 1; i >= 0; --i)
            {
                var collider = hoveredColliderCount.GetKeyByIndex(i);

                if (!collider.gameObject.activeInHierarchy || !collider.enabled)
                {
                    continue;
                }

                for (var tr = collider.transform; !ReferenceEquals(tr, null); tr = tr.parent)
                {
                    var go = tr.gameObject;

                    if (!hoveredObjects.AddUnique(go))
                    {
                        break;
                    }

                    if (!hoveredObjectsPrev.Remove(go))
                    {
                        ExecuteEvents.Execute(go, HoverEventData, ExecuteColliderEvents.HoverEnterHandler);
                    }
                }
            }

            // process button events
            for (int i = 0, imax = buttonEventDataList.Count; i < imax; ++i)
            {
                var eventData = buttonEventDataList[i];

                // process button press
                if (!eventData.isPressed)
                {
                    if (eventData.GetPress())
                    {
                        ProcessPressDown(eventData);
                        ProcessPressing(eventData);
                    }
                }
                else
                {
                    if (eventData.GetPress())
                    {
                        ProcessPressing(eventData);
                    }
                    else
                    {
                        ProcessPressUp(eventData);
                    }
                }

                // process pressed button enter/exit
                if (eventData.isPressed)
                {
                    var pressEnteredObjectsPrev = eventData.pressEnteredObjects;
                    eventData.pressEnteredObjects = IndexedSetPool <GameObject> .Get();

                    for (int j = hoveredObjects.Count - 1; j >= 0; --j)
                    {
                        var go = hoveredObjects[j];

                        if (!eventData.pressEnteredObjects.AddUnique(go))
                        {
                            continue;
                        }

                        if (!pressEnteredObjectsPrev.Remove(go))
                        {
                            ExecuteEvents.Execute(go, eventData, ExecuteColliderEvents.PressEnterHandler);
                        }
                    }

                    for (int j = pressEnteredObjectsPrev.Count - 1; j >= 0; --j)
                    {
                        if (eventData.clickingHandlers.Count > 0)
                        {
                            eventData.clickingHandlers.Remove(pressEnteredObjectsPrev[j]);
                        }

                        ExecuteEvents.Execute(pressEnteredObjectsPrev[j], eventData, ExecuteColliderEvents.PressExitHandler);
                    }

                    IndexedSetPool <GameObject> .Release(pressEnteredObjectsPrev);
                }
                else
                {
                    for (int j = eventData.pressEnteredObjects.Count - 1; j >= 0; --j)
                    {
                        ExecuteEvents.Execute(eventData.pressEnteredObjects[j], eventData, ExecuteColliderEvents.PressExitHandler);
                    }

                    eventData.pressEnteredObjects.Clear();
                }
            }

            // process axis events
            for (int i = 0, imax = axisEventDataList.Count; i < imax; ++i)
            {
                var eventData = axisEventDataList[i];

                if (!eventData.IsValueChangedThisFrame())
                {
                    continue;
                }

                for (int j = hoveredColliderCount.Count - 1; j >= 0; --j)
                {
                    var handler = ExecuteEvents.GetEventHandler <IColliderEventAxisChangedHandler>(hoveredColliderCount.GetKeyByIndex(j).gameObject);

                    if (ReferenceEquals(handler, null))
                    {
                        continue;
                    }

                    if (!s_gos.Add(handler.GetInstanceID()))
                    {
                        continue;
                    }

                    ExecuteEvents.Execute(handler, eventData, ExecuteColliderEvents.AxisChangedHandler);
                }
            }
            s_gos.Clear();

            // process leave
            // now stayingObjectsPrev left with handlers that are exited
            for (int i = hoveredObjectsPrev.Count - 1; i >= 0; --i)
            {
                ExecuteEvents.Execute(hoveredObjectsPrev[i], HoverEventData, ExecuteColliderEvents.HoverExitHandler);
            }

            IndexedSetPool <GameObject> .Release(hoveredObjectsPrev);
        }
예제 #7
0
        protected virtual void Update()
        {
            isUpdating = true;

            // process enter
            var hoveredObjectsPrev = hoveredObjects;

            hoveredObjects = IndexedSetPool <GameObject> .Get();

            for (int i = stayingColliders.Count - 1; i >= 0; --i)
            {
                var collider = stayingColliders[i];

                if (collider == null)
                {
                    continue;
                }

                // travel from collider's gameObject to its root
                for (var tr = collider.transform; !ReferenceEquals(tr, null); tr = tr.parent)
                {
                    var go = tr.gameObject;

                    if (!hoveredObjects.AddUnique(go))
                    {
                        break;
                    }                                             // hit traveled gameObject, break and travel from the next collider

                    if (hoveredObjectsPrev.Remove(go))
                    {
                        continue;
                    }                                                // gameObject already existed in last frame, no need to execute enter event

                    hoverEnterHandlers.Add(go);
                }
            }

            // process leave
            for (int i = hoveredObjectsPrev.Count - 1; i >= 0; --i)
            {
                hoverExitHandlers.Add(hoveredObjectsPrev[i]);
            }

            IndexedSetPool <GameObject> .Release(hoveredObjectsPrev);

            // process button events
            for (int i = 0, imax = buttonEventDataList.Count; i < imax; ++i)
            {
                var eventData = buttonEventDataList[i];
                var handlers  = GetButtonHandlers(i);

                eventData.draggingHandlers.RemoveAll(CannotHandlerDragAnymore);

                // process button press
                if (!eventData.isPressed)
                {
                    if (eventData.GetPress())
                    {
                        ProcessPressDown(eventData, handlers);
                        ProcessPressing(eventData, handlers);
                    }
                }
                else
                {
                    if (eventData.GetPress())
                    {
                        ProcessPressing(eventData, handlers);
                    }
                    else
                    {
                        ProcessPressUp(eventData, handlers);
                    }
                }

                // process pressed button enter/exit
                if (eventData.isPressed)
                {
                    var pressEnteredObjectsPrev = eventData.pressEnteredObjects;
                    eventData.pressEnteredObjects = IndexedSetPool <GameObject> .Get();

                    for (int j = hoveredObjects.Count - 1; j >= 0; --j)
                    {
                        eventData.pressEnteredObjects.Add(hoveredObjects[j]);

                        if (pressEnteredObjectsPrev.Remove(hoveredObjects[j]))
                        {
                            continue;
                        }                                                                    // gameObject already existed in last frame, no need to execute enter event

                        handlers.pressEnterHandlers.Add(hoveredObjects[j]);
                    }

                    for (int j = pressEnteredObjectsPrev.Count - 1; j >= 0; --j)
                    {
                        eventData.clickingHandlers.Remove(pressEnteredObjectsPrev[j]); // remove the obj from clicking obj if it leaved

                        handlers.pressExitHandlers.Add(pressEnteredObjectsPrev[j]);
                    }

                    IndexedSetPool <GameObject> .Release(pressEnteredObjectsPrev);
                }
                else
                {
                    for (int j = eventData.pressEnteredObjects.Count - 1; j >= 0; --j)
                    {
                        handlers.pressExitHandlers.Add(eventData.pressEnteredObjects[j]);
                    }

                    eventData.pressEnteredObjects.Clear();
                }
            }

            // process axis events
            for (int i = 0, imax = axisEventDataList.Count; i < imax; ++i)
            {
                var eventData = axisEventDataList[i];

                if ((eventData.v4 = eventData.GetDelta()) == Vector4.zero)
                {
                    continue;
                }

                var handlers = GetAxisHandlers(i);

                GetEventHandlersFromHoveredColliders <IColliderEventAxisChangedHandler>(handlers.axisChangedHandlers);
            }

            ExecuteAllEvents();

            if (isDisabled)
            {
                CleanUp();
            }

            isUpdating = false;
        }
예제 #8
0
 protected virtual void OnTriggerStay(Collider other)
 {
     stayingColliders.AddUnique(other);
 }
예제 #9
0
 protected virtual void OnTriggerStay(Collider other)
 {
     // 相当于set,只有唯一的成员,是用字典实现的
     stayingColliders.AddUnique(other);
 }