Exemple #1
0
 protected void StartEditorTweens()
 {
     if (!Application.isPlaying)
     {
         CUITweenPreview.PrepareTweens(tweens);
         CUITweenPreview.StartTweens();
     }
 }
Exemple #2
0
        private static IEnumerator HandleAnimationData(CUIAnimationState state)
        {
            if (state.tweens.Count <= 0 && !state.isInstant)
            {
                yield break;
            }

            //Add the new data to the list
            currentAnimations.Add(state);

            //Trigger events:
            if (state.isChangingVisibility)
            {
                if (state.isShowing)
                {
                    state.cuiGroup.OnShowing();
                }
                else
                {
                    state.cuiGroup.OnHiding();
                }
            }

            //Wait for the animation to complete
            if (!state.isInstant)
            {
                //Preview for in-editor
                if (!Application.isPlaying)
                {
                    CUITweenPreview.PrepareTweens(state.tweens);
                    CUITweenPreview.StartTweens();
                }

                yield return(new WaitForSeconds(state.animLength));

                while (state.tweens[0].active)
                {
                    yield return(null);
                }
            }

            //Check if it's still valid, if so remove it
            if (currentAnimations.Contains(state))
            {
                //Move the rect to it's final pos after the animation is done
                state.cuiGroup.rectTransform.localPosition = state.finalPos;

                //Disable the GO if needed
                if (!state.isShowing && state.cuiGroup.disableCanvasWhenHidden)
                {
                    state.cuiGroup.gameObject.SetActive(false);
                }

                currentAnimations.Remove(state);
            }
        }
        public void Select(bool instant = false)
        {
            List <Tween> tweens = new List <Tween>();

            foreach (var state in states)
            {
                GameObject cur = state.go;

                if (instant)
                {
                    cur.transform.localPosition    = state.pos;
                    cur.transform.localScale       = state.scale;
                    cur.transform.localEulerAngles = state.rot;

                    if (state.useRectTransform)
                    {
                        state.rectTransform.sizeDelta = state.rectSize;
                    }

                    if (state.useGraphic)
                    {
                        state.graphic.color = state.color;
                    }

                    if (state.useCanvasGroup)
                    {
                        state.canvasGroup.alpha = state.canvasGroupAlpha;
                    }
                }

                else
                {
                    if (cur.transform.localPosition != state.pos)
                    {
                        tweens.Add(cur.transform.DOLocalMove(state.pos, animTime));
                    }
                    if (cur.transform.localScale != state.scale)
                    {
                        tweens.Add(cur.transform.DOScale(state.scale, animTime));
                    }
                    if (cur.transform.localEulerAngles != state.rot)
                    {
                        tweens.Add(cur.transform.DOLocalRotate(state.rot, animTime));
                    }

                    if (state.useRectTransform)
                    {
                        if (state.rectTransform.sizeDelta != state.rectSize)
                        {
                            tweens.Add(state.rectTransform.DOSizeDelta(state.rectSize, animTime));
                        }
                    }

                    if (state.useGraphic)
                    {
                        if (state.graphic.color != state.color)
                        {
                            tweens.Add(state.graphic.DOColor(state.color, animTime));
                        }
                    }

                    if (state.useCanvasGroup)
                    {
                        if (Math.Abs(state.canvasGroup.alpha - state.canvasGroupAlpha) > 0.01f)
                        {
                            tweens.Add(state.canvasGroup.DOFade(state.canvasGroupAlpha, animTime));
                        }
                    }
                }
            }


            if (!instant)
            {
                foreach (Tween tween in tweens)
                {
                    if (delayAfterPrevious > 0f)
                    {
                        tween.SetDelay(delayAfterPrevious);
                    }
                    tween.SetEase(easing);
                }


                CUITweenPreview.PrepareTweens(tweens);
                CUITweenPreview.StartTweens();
            }

            if (!Application.isPlaying)
            {
                go.GetComponent <CUIKeyframer>().EditorOnKeyframeSelected(this);
            }
        }