Example #1
0
    public void Stop()
    {
        StopAllCoroutines();
        for (int i = 0; i < m_animDatas.Count; i++)
        {
            UIAnimData   animData = m_animDatas[i];
            GameObject[] targets  = animData.GetTargets();
            if (targets != null)
            {
                for (int t = 0; t < targets.Length; t++)
                {
                    UITweener[] tweeners = targets[t].GetComponents <UITweener>();
                    foreach (UITweener tweener in tweeners)
                    {
                        tweener.enabled = false;
                    }
                    SpringPosition[] springs = targets[t].GetComponents <SpringPosition>();
                    foreach (var spring in springs)
                    {
                        spring.enabled = false;
                    }
                }
            }

            for (int j = 0; j < animData.m_frames.Count; j++)
            {
                UIAnimFrame curFrame = animData.m_frames[j];
                if (curFrame.m_type == E_UIAnimType.SubAnimGroup)
                {
                    BaseAnimPlayer[] players = curFrame.m_animPlayerGroup.GetComponentsInImmediateChildren <BaseAnimPlayer>(false, Mathf.FloorToInt(curFrame.m_alpha));
                    for (int k = 0; k < players.Length; k++)
                    {
                        (players[k] as UIAnimController).Stop();
                    }
                }
            }
        }
    }
Example #2
0
    IEnumerator PlayAnim(float delay, UIAnimData animData, System.Action onPlayEnd)
    {
        if (delay > 0)
        {
            yield return(new WaitForSeconds(delay));
        }

        for (int i = 0; i < animData.m_frames.Count; i++)
        {
            UIAnimFrame curFrame = animData.m_frames[i];
            switch (curFrame.m_type)
            {
            case E_UIAnimType.Empty:
            {
                yield return(new WaitForSeconds(animData.m_frames[i].m_duration));
            }
            break;

            case E_UIAnimType.Set:
            {
                GameObject[] targets = animData.GetTargets();
                for (int t = 0; t < targets.Length; t++)
                {
                    if (curFrame.HasTween(E_TweenType.Position))
                    {
                        SetPosition(targets[t], curFrame.m_position);
                    }
                    if (curFrame.HasTween(E_TweenType.Rotation))
                    {
                        SetRotation(targets[t], Quaternion.Euler(curFrame.m_rotation));
                    }
                    if (curFrame.HasTween(E_TweenType.Scale))
                    {
                        SetScale(targets[t], curFrame.m_scale);
                    }
                    if (curFrame.HasTween(E_TweenType.Color))
                    {
                        SetColor(targets[t], curFrame.m_color);
                    }
                    if (curFrame.HasTween(E_TweenType.Alpha))
                    {
                        SetAlpha(targets[t], curFrame.m_alpha);
                    }
                }
            }
            break;

            case E_UIAnimType.PlaySFX:
            {
                //AudioSource audioSrc = AudioManager.ins.PlaySFX(curFrame.m_audioName, Random.Range(curFrame.m_duration, curFrame.m_alpha), curFrame.m_particleParent);
                //if (audioSrc != null)
                //{
                //    float pitch = Random.Range(curFrame.m_scale.x, curFrame.m_scale.y);
                //    audioSrc.pitch = pitch;
                //}
//						if (curFrame.m_audioName != null)
//							SoundMgr.GetSingle().play_se(curFrame.m_audioName);
            }
            break;

            case E_UIAnimType.PlayBGM:
                //if (string.IsNullOrEmpty(curFrame.m_audioName))
                //{
                //    AudioManager.ins.StopBGM();
                //}
                //else
                //{
                //    AudioManager.ins.PlayBGM(curFrame.m_audioName);
                //}
                break;

            case E_UIAnimType.PlayVOX:
            {
                //AudioManager.ins.StopAllVOX();
                //AudioManager.ins.PlayVOX(curFrame.m_audioName);
            }
            break;

            case E_UIAnimType.AddParticle:
            {
                GameObject prefab        = Resources.Load(curFrame.m_particlePath) as GameObject;
                Transform  particleTrans = MonoUtil.CreatePrefab(prefab, "particle", curFrame.m_particleParent, curFrame.m_position);
                if (curFrame.m_particleDestroyAfterPlay)
                {
                    particleTrans.gameObject.AddComponent <OneShotParticle>();
                }
            }
            break;

            case E_UIAnimType.Tween:
            {
                bool isTweening                   = true;
                bool assignedOnTweenEnd           = false;
                EventDelegate.Callback onTweenEnd = () => {
                    isTweening = false;
                };
                UITweener    tw      = null;
                GameObject[] targets = animData.GetTargets();
                for (int t = 0; t < targets.Length; t++)
                {
                    if (curFrame.HasTween(E_TweenType.Position))
                    {
                        tw        = TweenPosition.Begin(targets[t], curFrame.m_duration, curFrame.m_position);
                        tw.method = curFrame.m_method;
                        if (!assignedOnTweenEnd)
                        {
                            assignedOnTweenEnd = true;
                            tw.SetOnFinished(onTweenEnd);
                        }
                    }
                    if (curFrame.HasTween(E_TweenType.Rotation))
                    {
                        tw        = TweenRotation.Begin(targets[t], curFrame.m_duration, Quaternion.Euler(curFrame.m_rotation));
                        tw.method = curFrame.m_method;
                        if (!assignedOnTweenEnd)
                        {
                            assignedOnTweenEnd = true;
                            tw.SetOnFinished(onTweenEnd);
                        }
                    }
                    if (curFrame.HasTween(E_TweenType.Scale))
                    {
                        tw        = TweenScale.Begin(targets[t], curFrame.m_duration, curFrame.m_scale);
                        tw.method = curFrame.m_method;
                        if (!assignedOnTweenEnd)
                        {
                            assignedOnTweenEnd = true;
                            tw.SetOnFinished(onTweenEnd);
                        }
                    }
                    if (curFrame.HasTween(E_TweenType.Color))
                    {
                        tw        = TweenColor.Begin(targets[t], curFrame.m_duration, curFrame.m_color);
                        tw.method = curFrame.m_method;
                        if (!assignedOnTweenEnd)
                        {
                            assignedOnTweenEnd = true;
                            tw.SetOnFinished(onTweenEnd);
                        }
                    }
                    if (curFrame.HasTween(E_TweenType.Alpha))
                    {
                        tw        = TweenAlpha.Begin(targets[t], curFrame.m_duration, curFrame.m_alpha);
                        tw.method = curFrame.m_method;
                        if (!assignedOnTweenEnd)
                        {
                            assignedOnTweenEnd = true;
                            tw.SetOnFinished(onTweenEnd);
                        }
                    }
                }
                while (assignedOnTweenEnd && isTweening)
                {
                    yield return(null);
                }
            }
            break;

            case E_UIAnimType.SubAnim:
                if (curFrame.m_animPlayer != null)
                {
                    bool isPlaying = true;
                    curFrame.m_animPlayer.Play(() => isPlaying = false, 0f);
                    while (curFrame.m_particleDestroyAfterPlay && isPlaying)
                    {
                        yield return(null);
                    }
                }
                break;

            case E_UIAnimType.SubAnimGroup:
            {
                if (curFrame.m_animPlayerGroup != null)
                {
                    BaseAnimPlayer[] players = curFrame.m_animPlayerGroup.GetComponentsInImmediateChildren <BaseAnimPlayer>(false, Mathf.FloorToInt(curFrame.m_alpha));
                    if (players != null && players.Length > 0)
                    {
                        if (curFrame.m_duration >= 0f)
                        {
                            float duration     = curFrame.m_duration;
                            bool  isPlaying    = true;
                            float maxLength    = 0f;
                            int   maxLengthIdx = -1;
                            for (int j = 0; j < players.Length; j++)
                            {
                                if (!players[j].gameObject.activeInHierarchy)
                                {
                                    continue;
                                }
                                float curLength = players[j].Length + duration * j;
                                if (curLength > maxLength)
                                {
                                    maxLength    = curLength;
                                    maxLengthIdx = j;
                                }
                            }
                            if (maxLengthIdx == -1)
                            {
                                isPlaying = false;
                            }
                            for (int j = 0; j < players.Length; j++)
                            {
                                if (j == maxLengthIdx)
                                {
                                    players[j].Play(() => isPlaying = false, duration * j);
                                }
                                else
                                {
                                    players[j].Play(null, duration * j);
                                }
                            }
                            while (curFrame.m_particleDestroyAfterPlay && isPlaying)
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            for (int j = 0; j < players.Length; j++)
                            {
                                bool isPlaying = true;
                                players[j].Play(() => isPlaying = false, 0f);
                                while (isPlaying)
                                {
                                    yield return(null);
                                }
                            }
                        }
                    }
                }
            }
            break;

            case E_UIAnimType.EnableBehaviour:
                if (curFrame.m_behaviour != null)
                {
                    curFrame.m_behaviour.enabled = curFrame.m_particleDestroyAfterPlay;
                }
                else
                {
                    GameObject[] targets = animData.GetTargets();
                    for (int t = 0; t < targets.Length; t++)
                    {
                        targets[t].SetActive(curFrame.m_particleDestroyAfterPlay);
                    }
                }
                break;

            case E_UIAnimType.PlayAnimation:
                if (!string.IsNullOrEmpty(curFrame.m_audioName))
                {
                    var animation = animData.m_target.GetComponent <Animation>();
                    var animator  = animData.m_target.GetComponent <Animator>();
                    if (animation != null)
                    {
                        var clip = animation[curFrame.m_audioName];
                        clip.speed = 1;
                        if (clip != null && curFrame.m_duration > 0)
                        {
                            clip.speed = clip.length / curFrame.m_duration;
                        }
                        animation.Stop();
                        animation.Play(curFrame.m_audioName);
                        yield return(new WaitForSeconds(curFrame.m_duration));
                    }
                    if (animator != null)
                    {
                        animator.Play(curFrame.m_audioName);
                    }
                }
                break;

            case E_UIAnimType.SendEvent:
                if (!string.IsNullOrEmpty(curFrame.m_audioName))
                {
                    EventManager.Instance.SendEvent(curFrame.m_audioName);
                }
                break;

            default:
                break;
            }
        }
        if (onPlayEnd != null)
        {
            onPlayEnd();
        }
    }