Example #1
0
    private void UpdateMaterialState()
    {
        var targetMat = default(Material);

        if (drags.Count > 0)
        {
            drags.RemoveAll(e => !e.isDragging);
        }

        if (drags.Count > 0)
        {
            targetMat = dragged;
        }
        else if (presses.Count > 0)
        {
            targetMat = Pressed;
        }
        else if (hovers.Count > 0)
        {
            targetMat = Heightlight;
        }
        else
        {
            targetMat = Normal;
        }

        if (ChangeProp.Set(ref currentMat, targetMat))
        {
            SetChildRendererMaterial(targetMat);
        }
    }
Example #2
0
        private void PerformUpdate()
        {
            // So MB's override the == operator for null equality, which checks
            // if they are destroyed. This is fine if you are looking at a concrete
            // mb, but in this case we are looking at a list of ICanvasElement
            // this won't forward the == operator to the MB, but just check if the
            // interface is null. IsDestroyed will return if the backend is destroyed.
            m_LayoutRebuildQueue.RemoveAll(x => x == null || x.IsDestroyed());
            m_GraphicRebuildQueue.RemoveAll(x => x == null || x.IsDestroyed());

            m_PerformingLayoutUpdate = true;

            m_LayoutRebuildQueue.Sort(s_SortLayoutFunction);
            for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++)
            {
                for (int j = 0; j < m_LayoutRebuildQueue.Count; j++)
                {
                    try
                    {
                        if (ObjectValidForUpdate(instance.m_LayoutRebuildQueue[j]))
                        {
                            instance.m_LayoutRebuildQueue[j].Rebuild((CanvasUpdate)i);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, instance.m_LayoutRebuildQueue[j].transform);
                    }
                }
            }
            instance.m_LayoutRebuildQueue.Clear();
            m_PerformingLayoutUpdate = false;

            m_PerformingGraphicUpdate = true;
            for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++)
            {
                for (var k = 0; k < instance.m_GraphicRebuildQueue.Count; k++)
                {
                    try
                    {
                        var element = instance.m_GraphicRebuildQueue[k];
                        if (ObjectValidForUpdate(element))
                        {
                            element.Rebuild((CanvasUpdate)i);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e, instance.m_GraphicRebuildQueue[k].transform);
                    }
                }
            }
            instance.m_GraphicRebuildQueue.Clear();
            m_PerformingGraphicUpdate = false;
        }
        protected virtual void Update()
        {
            // remove inactive or disabled collider
            // because OnTriggerExit doesn't automatically called on disabled
            hoveredColliders.RemoveAll((c) => c == null || !c.enabled || c.gameObject == null || !c.gameObject.activeInHierarchy);

            // process enter & stay
            var hoveredObjectsPrev = hoveredObjects;

            hoveredObjects = IndexedSetPool <GameObject> .Get();

            for (int i = hoveredColliders.Count - 1; i >= 0; --i)
            {
                for (var tr = hoveredColliders[i].transform; 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.GetPressDown())
                {
                    ProcessPressDown(eventData);
                }
                else if (eventData.GetPress())
                {
                    ProcessPressing(eventData);
                }
                else if (eventData.GetPressUp())
                {
                    ProcessPressUp(eventData);
                }

                // process pressed button enter/exit
                if (eventData.GetPress())
                {
                    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)
                    {
                        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 = hoveredColliders.Count - 1; j >= 0; --j)
                {
                    var handler = ExecuteEvents.GetEventHandler <IColliderEventAxisChangedHandler>(hoveredColliders[j].gameObject);

                    if (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);
        }