/// <summary>
        /// Starts animating a shadow on or off.
        /// </summary>
        /// <param name="set">If true, animate the shadow on. Otherwise animate it off.</param>
        /// <param name="tweenType">The type of tween curve to use. 'Custom' is not supported.</param>
        /// <param name="instant">Should the transition be instant and not animate?</param>
        public void SetShadow(bool set, Tween.TweenType tweenType, bool instant = false)
        {
            if (gameObject == null)
            {
                return;
            }

            isVisible = set;

            if (set)
            {
                gameObject.SetActive(true);
            }

            if (Application.isPlaying && !instant)
            {
                TweenManager.EndTween(m_Tweener);

                m_Tweener = TweenManager.TweenFloat(f => canvasGroup.alpha = f, () => canvasGroup.alpha, set ? 1f : 0f, 0.5f, 0f, () => gameObject.SetActive(set), tweenType: tweenType);
            }
            else
            {
                canvasGroup.alpha = set ? 1f : 0f;
                gameObject.SetActive(set);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Hides and destroys the dropdown object.
        /// </summary>
        public void Hide()
        {
            for (int i = 0; i < m_ListItemAutoTweeners.Count; i++)
            {
                TweenManager.EndTween(m_ListItemAutoTweeners[i]);
            }

            m_IsExapanded = false;

            if (m_BaseSelectable != null)
            {
                m_BaseSelectable.interactable = true;
            }

            for (int i = 0; i < m_ListItems.Count; i++)
            {
                int         i1          = i;
                CanvasGroup canvasGroup = m_ListItems[i].canvasGroup;
                TweenManager.TweenFloat(f => canvasGroup.alpha = f, canvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, (m_ListItems.Count - i1) * (m_AnimationDuration / 6), null, false, Tween.TweenType.Linear);
            }

            m_AutoTweeners.Add(TweenManager.TweenFloat(f => m_DropdownCanvasGroup.alpha = f, m_DropdownCanvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, m_AnimationDuration, null, false, Tween.TweenType.Linear));

            TweenManager.TweenFloat(f => m_ShadowCanvasGroup.alpha = f, m_ShadowCanvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, m_AnimationDuration, () =>
            {
                for (int i = 0; i < m_AutoTweeners.Count; i++)
                {
                    TweenManager.EndTween(m_AutoTweeners[i]);
                }

                Destroy(m_DropdownPanel.gameObject);
            }, false, Tween.TweenType.Linear);
        }
        /// <summary>
        /// Animates the slider to the 'off' state.
        /// </summary>
        private void AnimateOff()
        {
            TweenManager.EndTween(m_HandleSizeTweener);
            TweenManager.EndTween(m_PopupScaleTweener);
            TweenManager.EndTween(m_HandlePositionYTweener);
            TweenManager.EndTween(m_PopupTextColorTweener);

            if (m_HasPopup)
            {
                m_HandlePositionYTweener =
                    TweenManager.TweenFloat(
                        f => handleGraphicTransform.anchoredPosition = new Vector2(handleGraphicTransform.anchoredPosition.x, f),
                        handleGraphicTransform.anchoredPosition.y,
                        MaterialUIScaler.GetRootScaler(transform).canvas.pixelPerfect ? 1f : 0f, m_AnimationDuration, 0, null, false, Tween.TweenType.EaseOutCubed);

                m_PopupScaleTweener = TweenManager.TweenVector3(vector3 => m_PopupTransform.localScale = vector3,
                                                                m_PopupTransform.localScale, Vector3.zero, m_AnimationDuration);
            }

            m_HandleSizeTweener = TweenManager.TweenVector2(vector2 => handleGraphicTransform.sizeDelta = vector2,
                                                            handleGraphicTransform.sizeDelta, new Vector2(16, 16), m_AnimationDuration, 0, null, false,
                                                            Tween.TweenType.EaseOutSept);

            m_PopupTextColorTweener = TweenManager.TweenColor(color => m_PopupText.color = color, m_PopupText.color,
                                                              m_PopupText.color.WithAlpha(0f), m_AnimationDuration * 0.25f);
        }
Beispiel #4
0
            public override void Tween(BaseStyleElement p_sender, bool p_canAnimate, float p_animationDuration)
            {
                TweenManager.EndTween(_tweenId);

                var v_graphic = GetTarget <Graphic>();

                if (v_graphic != null)
                {
                    var v_endColor = m_color;
                    if (p_canAnimate && Application.isPlaying)
                    {
                        _tweenId = TweenManager.TweenColor(
                            (color) =>
                        {
                            if (v_graphic != null)
                            {
                                v_graphic.color = color;
                            }
                        },
                            v_graphic.color,
                            v_endColor,
                            p_animationDuration
                            );
                    }
                    else
                    {
                        v_graphic.color = v_endColor;
                    }
                }
            }
        /// <summary>
        /// Animates the slider to the 'on' state.
        /// </summary>
        private void AnimateOn()
        {
            TweenManager.EndTween(m_HandleSizeTweener);
            TweenManager.EndTween(m_PopupScaleTweener);
            TweenManager.EndTween(m_HandlePositionYTweener);
            TweenManager.EndTween(m_PopupTextColorTweener);

            if (m_HasPopup)
            {
                m_HandleSizeTweener = TweenManager.TweenVector2(vector2 => handleGraphicTransform.sizeDelta = vector2,
                                                                handleGraphicTransform.sizeDelta, new Vector2(38, 38), m_AnimationDuration, 0f, null, false,
                                                                Tween.TweenType.SoftEaseOutQuint);

                m_HandlePositionYTweener = TweenManager.TweenFloat(
                    f => handleGraphicTransform.anchoredPosition = new Vector2(handleGraphicTransform.anchoredPosition.x, f),
                    handleGraphicTransform.anchoredPosition.y, slider.wholeNumbers && m_HasDots ? 36 : 30,
                    m_AnimationDuration, 0, null, false, Tween.TweenType.EaseOutSept);

                m_PopupScaleTweener = TweenManager.TweenVector3(vector3 => m_PopupTransform.localScale = vector3,
                                                                m_PopupTransform.localScale, Vector3.one, m_AnimationDuration, 0, null, false, Tween.TweenType.EaseOutSept);
            }
            else
            {
                m_HandleSizeTweener = TweenManager.TweenVector2(vector2 => handleGraphicTransform.sizeDelta = vector2,
                                                                handleGraphicTransform.sizeDelta, new Vector2(24, 24), m_AnimationDuration, 0, null, false, Tween.TweenType.SoftEaseOutQuint);
            }

            m_PopupTextColorTweener = TweenManager.TweenColor(color => m_PopupText.color = color, () => m_PopupText.color,
                                                              () => m_PopupText.color.WithAlpha(1f), m_AnimationDuration * 0.66f, m_AnimationDuration * 0.33f);
        }
Beispiel #6
0
        protected virtual void TweenTabsContainer(int index, bool animate = true)
        {
            if (m_TabsContainer == null)
            {
                return;
            }

            var useSameSizeCalculation = /*m_ForceSameTabSize ||*/ m_Tabs.Length <= index || index < 0 || m_Tabs[index] == null;

            float targetPosition = 0;

            if (useSameSizeCalculation)
            {
                targetPosition += rectTransform.GetProperSize().x / 2;

                targetPosition = Mathf.Clamp(targetPosition, -LayoutUtility.GetPreferredWidth(m_TabsContainer) + rectTransform.GetProperSize().x, 0);
            }
            else
            {
                targetPosition = m_Tabs[index].rectTransform.anchoredPosition.x + (m_Tabs[index].rectTransform.GetProperSize().x / 2);
            }

            TweenManager.EndTween(m_TabsContainerTweener);

            if (animate)
            {
                m_TabsContainerTweener = TweenManager.TweenVector2(
                    vector2 => m_TabsContainer.anchoredPosition = vector2, m_TabsContainer.anchoredPosition,
                    new Vector2(targetPosition, 0), 0.5f);
            }
            else
            {
                m_TabsContainer.anchoredPosition = new Vector2(targetPosition, 0);
            }
        }
        public override void TabPageDrag()
        {
            Kyub.Performance.SustainedPerformanceManager.Refresh(this);
            if (m_CanScrollBetweenTabs)
            {
                if (TweenManager.TweenIsActive(m_PagesContainerTweener))
                {
                    TweenManager.EndTween(m_PagesContainerTweener);

                    m_CurrentPage = NearestPage();

                    OnPagesTweenEnd();

                    TweenIndicator(m_CurrentPage);
                }

                TweenManager.EndTween(m_IndicatorTweener);

                if (m_Indicator != null)
                {
                    float normalizedPagesContainerPosition = -m_PagesContainer.anchoredPosition.x / (m_PageSize.x * m_Pages.Count);
                    if (m_ForceSameTabSize)
                    {
                        m_Indicator.anchoredPosition = new Vector2((m_TabWidth * m_Tabs.Length) * normalizedPagesContainerPosition, 0);
                    }
                    else
                    {
                        m_Indicator.anchoredPosition = new Vector2(rectTransform.GetProperSize().x *normalizedPagesContainerPosition, 0);
                    }
                }
            }
        }
        protected override void TweenIndicator(int targetTab, bool animate = true)
        {
            if (m_Indicator == null || m_Tabs == null)
            {
                return;
            }

            float targetPosition = m_ForceSameTabSize || m_Tabs.Length <= targetTab || targetTab < 0 || m_Tabs[targetTab] == null ?
                                   targetTab * m_TabWidth :
                                   m_Tabs[targetTab].rectTransform.anchoredPosition.x - (m_Tabs[targetTab].rectTransform.GetProperSize().x / 2);

            float targetSize = m_ForceSameTabSize || m_Tabs.Length <= targetTab || targetTab < 0 || m_Tabs[targetTab] == null ?
                               m_TabWidth :
                               m_Tabs[targetTab].rectTransform.GetProperSize().x;

            TweenManager.EndTween(m_IndicatorSizeTweener);
            TweenManager.EndTween(m_IndicatorTweener);

            if (animate)
            {
                if (!m_ForceSameTabSize)
                {
                    m_IndicatorSizeTweener = TweenManager.TweenFloat(value => m_Indicator.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, value), m_Indicator.GetProperSize().x, targetSize, 0.5f);
                }
                m_IndicatorTweener = TweenManager.TweenVector2(vector2 => m_Indicator.anchoredPosition = vector2, m_Indicator.anchoredPosition, new Vector2(targetPosition, 0), 0.5f);
            }
            else
            {
                if (!m_ForceSameTabSize)
                {
                    m_Indicator.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, targetSize);
                }
                m_Indicator.anchoredPosition = new Vector2(targetPosition, 0);
            }
        }
Beispiel #9
0
            public override void Tween(BaseStyleElement p_sender, bool p_canAnimate, float p_animationDuration)
            {
                TweenManager.EndTween(_tweenId);

                var v_graphic = GetTarget <Graphic>();

                if (v_graphic != null)
                {
                    var v_slider         = p_sender as MaterialSlider;
                    var v_isInteractable = v_slider != null ? v_slider.m_Interactable : true;

                    var v_endColor = !v_isInteractable ? m_colorDisabled : m_colorEnabled;
                    if (p_canAnimate && Application.isPlaying)
                    {
                        _tweenId = TweenManager.TweenColor(
                            (color) =>
                        {
                            if (v_graphic != null)
                            {
                                v_graphic.color = color;
                            }
                        },
                            v_graphic.color,
                            v_endColor,
                            p_animationDuration
                            );
                    }
                    else
                    {
                        v_graphic.color = v_endColor;
                    }
                }
            }
        public virtual void AnimateHideBackground(Action callback = null, float animationDuration = 0.5f, float delay = 0f)
        {
            if (!_isHiding || _tweenId < 0)
            {
                _isHiding = true;
                canvasGroup.blocksRaycasts = false;

                TweenManager.EndTween(_tweenId);
                _tweenId = TweenManager.TweenFloat(
                    f =>
                {
                    if (this != null && canvasGroup != null)
                    {
                        canvasGroup.alpha = f;
                    }
                },
                    canvasGroup.alpha,
                    0f,
                    animationDuration,
                    delay,
                    callback += () =>
                {
                    if (this != null && gameObject != null)
                    {
                        Destroy(gameObject, 0.01f);
                    }
                },
                    false,
                    Tween.TweenType.Linear);
            }
        }
Beispiel #11
0
        private void TweenPagesContainer(int index, bool animate = true)
        {
            if (m_PagesContainer == null)
            {
                return;
            }

            if (pages == null)
            {
                pages = new List <TabPage>();
            }

            for (int i = 0; i < pages.Count; i++)
            {
                int smaller = Mathf.Min(m_CurrentPage, index);
                int bigger  = Mathf.Max(m_CurrentPage, index);

                //if (i >= smaller - 1 && i <= bigger + 1)
                if (i == smaller || i == bigger)
                {
                    pages[i].gameObject.SetActive(true);
                }
                else
                {
                    pages[i].DisableIfAllowed();
                }
            }

            float targetPosition = -(index * m_PageSize.x);

            targetPosition = Mathf.Clamp(targetPosition, -(pages.Count * m_PageSize.x), 0);

            TweenManager.EndTween(m_PagesContainerTweener);

            m_CurrentPage = index;

            if (animate)
            {
                m_PagesContainerTweener =
                    TweenManager.TweenVector2(vector2 => m_PagesContainer.anchoredPosition = vector2,
                                              m_PagesContainer.anchoredPosition, new Vector2(targetPosition, 0), 0.5f, 0, OnPagesTweenEnd);
            }
            else
            {
                m_PagesContainer.anchoredPosition = new Vector2(targetPosition, 0);
                OnPagesTweenEnd();
            }
        }
Beispiel #12
0
        private void TweenIndicator(int targetTab, bool animate = true)
        {
            float targetPosition = targetTab * m_TabWidth;


            TweenManager.EndTween(m_IndicatorTweener);

            if (animate)
            {
                m_IndicatorTweener = TweenManager.TweenVector2(vector2 => m_Indicator.anchoredPosition = vector2, m_Indicator.anchoredPosition, new Vector2(targetPosition, 0), 0.5f);
            }
            else
            {
                m_Indicator.anchoredPosition = new Vector2(targetPosition, 0);
            }
        }
            public virtual void Transition(bool show, float attenuation, float animationDuration, float delay = 0, System.Action callback = null)
            {
                attenuation = Mathf.Clamp01(attenuation);
                if (gameObject != null && isShow != show)
                {
                    gameObject.SetActive(true);

                    isShow = show;
                    //var inverseTargetValue = show ? 0f : attenuation;
                    var targetValue  = show ? attenuation : 0f;
                    var currentValue = Mathf.Clamp01(rectTransform.localScale.y);
                    TweenManager.EndTween(tweenId);
                    tweenId = TweenManager.TweenFloat((value) =>
                    {
                        //Update Color and Scale
                        if (gameObject != null)
                        {
                            if (canvasGroup != null)
                            {
                                canvasGroup.alpha = value;
                            }
                            if (rectTransform != null)
                            {
                                rectTransform.localScale = new Vector3(rectTransform.localScale.x, value, rectTransform.localScale.z);
                            }
                        }
                    },
                                                      currentValue,
                                                      targetValue,
                                                      animationDuration,
                                                      0,
                                                      () =>
                    {
                        tweenId = -1;
                        if (gameObject != null && !isShow)
                        {
                            gameObject.SetActive(false);
                        }
                        callback.InvokeIfNotNull();
                    });
                }
                else
                {
                    isShow = show;
                    callback.InvokeIfNotNull();
                }
            }
        /// <summary>
        /// Called when [slider value changed].
        /// </summary>
        /// <param name="value">The value.</param>
        public void OnSliderValueChanged(float value)
        {
            TweenManager.EndTween(m_HandleAnchorMinTweener);
            TweenManager.EndTween(m_HandleAnchorMaxTweener);

            if (slider.wholeNumbers && SliderValueRange() < 100 && Application.isPlaying)
            {
                m_HandleAnchorMinTweener = TweenManager.TweenFloat(
                    f => handleGraphicTransform.anchorMin = new Vector2(f, handleGraphicTransform.anchorMin.y),
                    handleGraphicTransform.anchorMin.x, m_Slider.handleRect.anchorMin.x, m_AnimationDuration * 0.5f,
                    0, null, false, Tween.TweenType.EaseOutSept);

                m_HandleAnchorMaxTweener = TweenManager.TweenFloat(
                    f => handleGraphicTransform.anchorMax = new Vector2(f, handleGraphicTransform.anchorMax.y),
                    handleGraphicTransform.anchorMax.x, m_Slider.handleRect.anchorMax.x, m_AnimationDuration * 0.5f,
                    0, null, false, Tween.TweenType.EaseOutSept);
            }
            else
            {
                Vector2 anchor = handleGraphicTransform.anchorMin;
                anchor.x = m_Slider.handleRect.anchorMin.x;
                handleGraphicTransform.anchorMin = anchor;

                anchor   = handleGraphicTransform.anchorMax;
                anchor.x = m_Slider.handleRect.anchorMax.x;
                handleGraphicTransform.anchorMax        = anchor;
                handleGraphicTransform.anchoredPosition = new Vector2(0f, handleGraphicTransform.anchoredPosition.y);
            }

            if (m_DelayedInit)
            {
                m_FillTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, fillAreaTransform.GetProperSize().x *handleGraphicTransform.anchorMin.x);
            }

            m_PopupText.text = slider.value.ToString("#0.#");

            if (m_ValueText != null)
            {
                m_ValueText.text = slider.value.ToString("#0.##") + (string.IsNullOrEmpty(m_ValueTextSuffix) ? "" : m_ValueTextSuffix);
            }

            if (m_InputField != null)
            {
                m_InputField.inputField.text = slider.value.ToString("#0.##");
            }
        }
            public virtual void TransitionImmediate(bool show, float attenuation)
            {
                attenuation = Mathf.Clamp01(attenuation);
                isShow      = show;
                if (gameObject != null)
                {
                    gameObject.SetActive(isShow);
                    var targetValue = show ? attenuation : 0f;
                    TweenManager.EndTween(tweenId);
                    tweenId = -1;

                    if (canvasGroup != null)
                    {
                        canvasGroup.alpha = targetValue;
                    }
                    if (rectTransform != null)
                    {
                        rectTransform.localScale = new Vector3(rectTransform.localScale.x, targetValue, rectTransform.localScale.z);
                    }
                }
            }
 public virtual void AnimateShowBackground(Action callback = null, float animationDuration = 0.5f, float delay = 0f)
 {
     if (_isHiding || _tweenId < 0)
     {
         _isHiding = false;
         canvasGroup.blocksRaycasts = true;
         TweenManager.EndTween(_tweenId);
         _tweenId = TweenManager.TweenFloat(
             f =>
         {
             if (this != null && canvasGroup != null)
             {
                 canvasGroup.alpha = f;
             }
         },
             canvasGroup.alpha,
             m_BackgroundAlpha,
             animationDuration,
             delay,
             callback);
     }
 }
Beispiel #17
0
        public void TabPageDrag()
        {
            if (m_CanScrollBetweenTabs)
            {
                if (TweenManager.TweenIsActive(m_PagesContainerTweener))
                {
                    TweenManager.EndTween(m_PagesContainerTweener);

                    m_CurrentPage = NearestPage();

                    OnPagesTweenEnd();

                    TweenIndicator(m_CurrentPage);
                }

                TweenManager.EndTween(m_IndicatorTweener);

                float normalizedPagesContainerPosition = -m_PagesContainer.anchoredPosition.x / (m_PageSize.x * m_Pages.Length);

                m_Indicator.anchoredPosition = new Vector2((m_TabWidth * m_Tabs.Length) * normalizedPagesContainerPosition, 0);
            }
        }
Beispiel #18
0
            public override void Tween(BaseStyleElement p_sender, bool p_canAnimate, float p_animationDuration)
            {
                TweenManager.EndTween(_tweenId);

                var v_graphic = GetTarget <Graphic>();

                if (v_graphic != null)
                {
                    var v_toggleBase     = p_sender as ToggleBase;
                    var v_isActive       = v_toggleBase != null ? v_toggleBase.toggle.isOn : true;
                    var v_isInteractable = v_toggleBase != null? v_toggleBase.m_Interactable : true;

                    var v_endColor = !v_isInteractable ? m_colorDisabled : (v_isActive ? m_colorOn : m_colorOff);
                    if (p_canAnimate && Application.isPlaying)
                    {
                        _tweenId = TweenManager.TweenColor(
                            (color) =>
                        {
                            if (v_graphic != null)
                            {
                                v_graphic.color = color;
                            }
                        },
                            v_graphic.color,
                            v_endColor,
                            p_animationDuration,
                            0,
                            null,
                            false,
                            MaterialUI.Tween.TweenType.SoftEaseOutQuint

                            );
                    }
                    else
                    {
                        v_graphic.color = v_endColor;
                    }
                }
            }
Beispiel #19
0
        private void TweenTabsContainer(int index, bool animate = true)
        {
            float targetPosition = -(index * m_TabWidth);

            targetPosition += rectTransform.GetProperSize().x / 2;
            targetPosition -= m_TabWidth / 2;

            targetPosition = Mathf.Clamp(targetPosition, -LayoutUtility.GetPreferredWidth(m_TabsContainer) + rectTransform.GetProperSize().x, 0);

            TweenManager.EndTween(m_TabsContainerTweener);

            if (animate)
            {
                m_TabsContainerTweener = TweenManager.TweenVector2(
                    vector2 => m_TabsContainer.anchoredPosition = vector2, m_TabsContainer.anchoredPosition,
                    new Vector2(targetPosition, 0), 0.5f);
            }
            else
            {
                m_TabsContainer.anchoredPosition = new Vector2(targetPosition, 0);
            }
        }
Beispiel #20
0
        private void TweenPagesContainer(int index, bool animate = true)
        {
            for (int i = 0; i < m_Pages.Length; i++)
            {
                int smaller = Mathf.Min(m_CurrentPage, index);
                int bigger  = Mathf.Max(m_CurrentPage, index);

                if (i >= smaller - 1 && i <= bigger + 1)
                {
                    m_Pages[i].gameObject.SetActive(true);
                }
                else
                {
                    m_Pages[i].DisableIfAllowed();
                }
            }

            float targetPosition = -(index * m_PageSize.x);

            targetPosition = Mathf.Clamp(targetPosition, -(m_Pages.Length * m_PageSize.x), 0);

            TweenManager.EndTween(m_PagesContainerTweener);

            m_CurrentPage = index;

            if (animate)
            {
                m_PagesContainerTweener =
                    TweenManager.TweenVector2(vector2 => m_PagesContainer.anchoredPosition = vector2,
                                              m_PagesContainer.anchoredPosition, new Vector2(targetPosition, 0), 0.5f);
            }
            else
            {
                m_PagesContainer.anchoredPosition = new Vector2(targetPosition, 0);
                OnPagesTweenEnd();
            }
        }
Beispiel #21
0
        /// <summary>
        /// Instantiates the dropdown object and expands it.
        /// </summary>
        public void Show()
        {
            Canvas rootCanvas = m_BaseTransform.GetRootCanvas();

            rootCanvas.CopySettingsToOtherCanvas(m_DropdownCanvas);
            m_DropdownCanvas.pixelPerfect = true;
            m_DropdownCanvas.sortingOrder = 30000;

            m_DropdownPanel       = PrefabManager.InstantiateGameObject(PrefabManager.ResourcePrefabs.dropdownPanel, m_DropdownCanvas.transform).GetComponent <RectTransform>();
            m_PanelLayer          = m_DropdownPanel.GetChildByName <RectTransform>("PanelLayer");
            m_DropdownCanvasGroup = m_DropdownPanel.GetComponent <CanvasGroup>();
            m_ShadowCanvasGroup   = m_DropdownPanel.GetChildByName <CanvasGroup>("Shadow");

            m_DropdownPanel.GetRootCanvas().scaleFactor = rootCanvas.scaleFactor;

            m_CancelPanel           = m_DropdownPanel.GetChildByName <RectTransform>("Cancel Panel");
            m_CancelPanel.sizeDelta = scaler.canvas.pixelRect.size * 2;
            DropdownTrigger trigger = m_DropdownPanel.gameObject.GetChildByName <DropdownTrigger>("Cancel Panel");

            trigger.index    = -1;
            trigger.dropdown = this;

            m_DropdownPanel.gameObject.GetChildByName <Image>("ScrollRect").color = m_PanelColor;

            m_ListItemTemplate = new DropdownListItem();

            m_ListItemTemplate.rectTransform = m_DropdownPanel.GetChildByName <RectTransform>("Item");
            m_ListItemTemplate.canvasGroup   = m_ListItemTemplate.rectTransform.GetComponent <CanvasGroup>();
            m_ListItemTemplate.text          = m_ListItemTemplate.rectTransform.GetChildByName <Text>("Text");

            if (m_OptionDataList.imageType == ImageDataType.Sprite)
            {
                m_ListItemTemplate.image = m_ListItemTemplate.rectTransform.GetChildByName <Image>("Icon");
                Destroy(m_ListItemTemplate.rectTransform.GetChildByName <VectorImage>("Icon").gameObject);
            }
            else
            {
                m_ListItemTemplate.image = m_ListItemTemplate.rectTransform.GetChildByName <VectorImage>("Icon");
                Destroy(m_ListItemTemplate.rectTransform.GetChildByName <Image>("Icon").gameObject);
            }

            m_ListItems = new List <DropdownListItem>();

            for (int i = 0; i < m_OptionDataList.options.Count; i++)
            {
                m_ListItems.Add(CreateItem(m_OptionDataList.options[i], i));
            }

            for (int i = 0; i < m_ListItems.Count; i++)
            {
                Selectable selectable = m_ListItems[i].rectTransform.GetComponent <Selectable>();
                Navigation navigation = new Navigation();
                navigation.mode = Navigation.Mode.Explicit;

                if (i > 0)
                {
                    navigation.selectOnUp = m_ListItems[i - 1].rectTransform.GetComponent <Selectable>();
                }
                if (i < m_ListItems.Count - 1)
                {
                    navigation.selectOnDown = m_ListItems[i + 1].rectTransform.GetComponent <Selectable>();
                }

                selectable.navigation = navigation;
            }

            if (m_BaseSelectable != null)
            {
                if (m_ListItems.Count > 0)
                {
                    Navigation navigation = Navigation.defaultNavigation;
                    navigation.selectOnDown     = m_ListItems[0].rectTransform.GetComponent <Selectable>();
                    m_BaseSelectable.navigation = navigation;
                }
            }

            float maxWidth    = CalculateMaxItemWidth();
            float buttonWidth = m_BaseTransform.rect.width;

            m_FullHeight = m_OptionDataList.options.Count * LayoutUtility.GetPreferredHeight(m_ListItemTemplate.rectTransform) + 16;

            m_ExpandedSize = new Vector2(Mathf.Max(maxWidth, buttonWidth), m_FullHeight);

            m_TempMaxHeight = m_MaxHeight;

            if (m_TempMaxHeight == 0)
            {
                m_TempMaxHeight = MaterialUIScaler.GetRootScaler(m_DropdownPanel).canvas.GetComponent <RectTransform>().rect.height - 32;
            }

            if (m_ExpandedSize.y > m_TempMaxHeight)
            {
                m_ExpandedSize.y = m_TempMaxHeight;
            }
            else
            {
                m_DropdownPanel.GetChildByName <Image>("Handle").gameObject.SetActive(false);
            }

            Destroy(m_ListItemTemplate.rectTransform.gameObject);

            m_DropdownPanel.position = m_BaseTransform.GetPositionRegardlessOfPivot();

            if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformWidth)
            {
                if (m_VerticalPivotType == VerticalPivotType.BelowBase)
                {
                    m_DropdownPanel.position = new Vector3(m_DropdownPanel.position.x, m_DropdownPanel.position.y - m_BaseTransform.GetProperSize().y / 2, m_DropdownPanel.position.z);
                }
                else if (m_VerticalPivotType == VerticalPivotType.AboveBase)
                {
                    m_DropdownPanel.position = new Vector3(m_DropdownPanel.position.x, m_DropdownPanel.position.y + m_BaseTransform.GetProperSize().y / 2, m_DropdownPanel.position.z);
                }
            }


            m_ExpandedPosition   = CalculatedPosition();
            m_ExpandedPosition.z = m_BaseTransform.position.z;

            m_DropdownCanvasGroup.alpha = 0f;
            m_ShadowCanvasGroup.alpha   = 0f;

            if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformWidth)
            {
                m_DropdownPanel.sizeDelta = new Vector2(m_BaseTransform.rect.size.x, 0f);
            }
            else if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformHeight)
            {
                m_DropdownPanel.sizeDelta = new Vector2(0f, m_BaseTransform.rect.size.y);
            }
            else if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformSize)
            {
                m_DropdownPanel.sizeDelta = m_BaseTransform.rect.size;
            }
            else
            {
                m_DropdownPanel.sizeDelta = Vector2.zero;
            }

            m_DropdownPanel.gameObject.SetActive(true);

            for (int i = 0; i < m_ListItemAutoTweeners.Count; i++)
            {
                TweenManager.EndTween(m_ListItemAutoTweeners[i]);
            }

            m_AutoTweeners         = new List <int>();
            m_ListItemAutoTweeners = new List <int>();

            m_AutoTweeners.Add(TweenManager.TweenFloat(f => m_DropdownCanvasGroup.alpha = f, m_DropdownCanvasGroup.alpha, 1f, m_AnimationDuration * 0.66f, 0, null, false, Tween.TweenType.Linear));
            m_AutoTweeners.Add(TweenManager.TweenFloat(f => m_ShadowCanvasGroup.alpha   = f, m_ShadowCanvasGroup.alpha, 1f, m_AnimationDuration * 0.66f, 0, null, false, Tween.TweenType.Linear));

            m_AutoTweeners.Add(TweenManager.TweenVector2(vector2 => m_DropdownPanel.sizeDelta = vector2, m_DropdownPanel.sizeDelta, m_ExpandedSize, m_AnimationDuration, m_AnimationDuration / 3, null, false, Tween.TweenType.EaseInOutQuint));

            m_AutoTweeners.Add(TweenManager.TweenVector3(UpdateDropdownPos, m_DropdownPanel.position, m_ExpandedPosition, m_AnimationDuration, m_AnimationDuration / 3, () =>
            {
                if (m_BaseSelectable != null && m_IsExapanded)
                {
                    m_BaseSelectable.interactable = false;
                }

                Vector2 tempVector2           = m_PanelLayer.anchoredPosition;
                tempVector2.x                 = Mathf.RoundToInt(tempVector2.x);
                tempVector2.y                 = Mathf.RoundToInt(tempVector2.y);
                m_PanelLayer.anchoredPosition = tempVector2;
            }, false, Tween.TweenType.EaseInOutQuint));

            for (int i = 0; i < m_ListItems.Count; i++)
            {
                int         i1          = i;
                CanvasGroup canvasGroup = m_ListItems[i].canvasGroup;
                m_ListItemAutoTweeners.Add(TweenManager.TweenFloat(f => canvasGroup.alpha = f, canvasGroup.alpha, 1f, m_AnimationDuration * 1.66f, (i1 * (m_AnimationDuration / 6) + m_AnimationDuration) - m_ScrollPosOffset / 800, null, false, Tween.TweenType.Linear));
            }

            if (m_FullHeight > m_TempMaxHeight)
            {
                m_DropdownPanel.GetChildByName <ScrollRect>("ScrollRect").gameObject.AddComponent <RectMask2D>();
            }

            m_IsExapanded = true;

            m_TimeShown = Time.unscaledTime;
        }
Beispiel #22
0
 public void TabItemPointerDown(int id)
 {
     TweenManager.EndTween(m_TabsContainerTweener);
 }
Beispiel #23
0
        private void UpdateSelectionState()
        {
            if (m_Interactable)
            {
                m_CurrentSelectionState = inputField.isFocused ? ColorSelectionState.EnabledSelected : ColorSelectionState.EnabledDeselected;

                if (lineImage != null)
                {
                    lineImage.sprite = null;
                }
            }
            else
            {
                m_CurrentSelectionState = inputField.isFocused ? ColorSelectionState.DisabledSelected : ColorSelectionState.DisabledDeselected;

                if (lineImage != null)
                {
                    lineImage.sprite = lineDisabledSprite;
                    lineImage.type   = Image.Type.Tiled;
                }
            }

            if (m_CurrentSelectionState != m_LastSelectionState)
            {
                m_LastSelectionState = m_CurrentSelectionState;

                TweenManager.EndTween(m_LeftContentTweener);

                if (Application.isPlaying)
                {
                    if (m_LeftContentGraphic)
                    {
                        m_LeftContentTweener = TweenManager.TweenColor(color => m_LeftContentGraphic.color = color,
                                                                       m_LeftContentGraphic.color,
                                                                       IsSelected() ? m_LeftContentActiveColor : m_LeftContentInactiveColor, m_AnimationDuration);
                    }
                }
                else
                {
                    if (m_LeftContentGraphic)
                    {
                        m_LeftContentGraphic.color = IsSelected()
                            ? m_LeftContentActiveColor
                            : m_LeftContentInactiveColor;
                    }
                }

                TweenManager.EndTween(m_RightContentTweener);

                if (Application.isPlaying)
                {
                    if (m_RightContentGraphic)
                    {
                        m_RightContentTweener = TweenManager.TweenColor(color => m_RightContentGraphic.color = color,
                                                                        m_RightContentGraphic.color,
                                                                        IsSelected() ? m_RightContentActiveColor : m_RightContentInactiveColor, m_AnimationDuration);
                    }
                }
                else
                {
                    if (m_RightContentGraphic)
                    {
                        m_RightContentGraphic.color = IsSelected()
                            ? m_RightContentActiveColor
                            : m_RightContentInactiveColor;
                    }
                }

                TweenManager.EndTween(m_HintTextTweener);

                if (Application.isPlaying)
                {
                    m_HintTextTweener = TweenManager.TweenColor(color => m_HintTextObject.color = color,
                                                                m_HintTextObject.color, IsSelected() ? m_HintTextActiveColor : m_HintTextInactiveColor,
                                                                m_AnimationDuration);
                }
                else
                {
                    m_HintTextObject.color = IsSelected() ? m_HintTextActiveColor : m_HintTextInactiveColor;
                }

                TweenManager.EndTween(m_CounterTweener);

                if (Application.isPlaying)
                {
                    m_CounterTweener = TweenManager.TweenColor(color => m_CounterText.color = color,
                                                               m_CounterText.color, IsSelected() ? m_CounterActiveColor : m_CounterInactiveColor,
                                                               m_AnimationDuration);
                }
                else
                {
                    try
                    {
                        m_CounterText.color = IsSelected() ? m_CounterActiveColor : m_CounterInactiveColor;
                    }
                    catch
                    {
                        Debug.LogWarning("MaterialInputField:1127");
                    }
                }

                TweenManager.EndTween(m_ValidationColorTweener);

                if (Application.isPlaying)
                {
                    m_ValidationColorTweener = TweenManager.TweenColor(color => m_ValidationText.color = color,
                                                                       m_ValidationText.color, IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor,
                                                                       m_AnimationDuration);
                }
                else
                {
                    m_ValidationText.color = IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor;
                }

                m_LineTransform.GetComponent <Graphic>().color       = m_LineInactiveColor;
                m_ActiveLineTransform.GetComponent <Graphic>().color = m_LineActiveColor;

                canvasGroup.alpha          = m_Interactable ? 1 : 0.5f;
                canvasGroup.interactable   = m_Interactable;
                canvasGroup.blocksRaycasts = m_Interactable;
            }
        }
Beispiel #24
0
 private void CancelHintTextTweeners()
 {
     TweenManager.EndTween(m_HintTextFloatingValueTweener);
     m_AnimateHintText = false;
 }
Beispiel #25
0
 private void CancelActivelineTweeners()
 {
     TweenManager.EndTween(m_ActiveLineSizeTweener);
     TweenManager.EndTween(m_ActiveLinePosTweener);
     TweenManager.EndTween(m_ActiveLineAlphaTweener);
 }
 public virtual void EndTween()
 {
     TweenManager.EndTween(_tweenId);
 }
 public override void Tween(BaseStyleElement p_sender, bool p_canAnimate, float p_animationDuration)
 {
     TweenManager.EndTween(_tweenId);
 }
Beispiel #28
0
        private void ValidateText()
        {
            if (validationText == null)
            {
                return;
            }

            if (!m_ValidateOnStart && !m_HasBeenSelected)
            {
                return;
            }

            m_ValidationText.color = IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor;

            ITextValidator validator = null;

            if (m_TextValidator != null && m_TextValidator.GetComponent <ITextValidator>() != null)
            {
                validator = m_TextValidator.GetComponent <ITextValidator>();
                validator.Init(this);
            }

            if (m_CustomTextValidator != null)
            {
                validator       = customTextValidator;
                m_HasValidation = true;
            }

            if (validator != null && m_HasValidation)
            {
                TweenManager.EndTween(m_ValidationTweener);

                if (!validator.IsTextValid())
                {
                    if (Application.isPlaying)
                    {
                        validationCanvasGroup.gameObject.SetActive(true);
                        validationCanvasGroup.interactable   = true;
                        validationCanvasGroup.blocksRaycasts = true;

                        m_ValidationTweener = TweenManager.TweenFloat(f => validationCanvasGroup.alpha = f, validationCanvasGroup.alpha, 1f, m_AnimationDuration / 2, tweenType: Tween.TweenType.Linear);
                        return;
                    }
                }
                else
                {
                    if (Application.isPlaying)
                    {
                        m_ValidationTweener = TweenManager.TweenFloat(f => validationCanvasGroup.alpha = f, validationCanvasGroup.alpha, 0f, m_AnimationDuration / 2, 0, () =>
                        {
                            validationCanvasGroup.interactable   = false;
                            validationCanvasGroup.blocksRaycasts = false;
                            validationCanvasGroup.gameObject.SetActive(false);
                        }, false, Tween.TweenType.Linear);
                        return;
                    }
                }
            }

            validationCanvasGroup.alpha          = 0;
            validationCanvasGroup.interactable   = false;
            validationCanvasGroup.blocksRaycasts = false;
            validationCanvasGroup.gameObject.SetActive(false);
        }
 public virtual void StopTransition()
 {
     TweenManager.EndTween(tweenId);
     tweenId = -1;
 }