Exemplo n.º 1
0
    public static UIAnimFrame CreateFrom(UIAnimFrame other)
    {
        UIAnimFrame frame = new UIAnimFrame();

        frame.CopyFrom(other);
        return(frame);
    }
 void FrameFieldEditor(UIAnimData data, UIAnimFrame frame)
 {
     if (frame.HasTween(E_TweenType.Position))
     {
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField("Position");
         if (data != null && data.m_target != null && GUILayout.Button("Current"))
         {
             frame.m_position = data.m_target.transform.localPosition;
         }
         EditorGUILayout.EndHorizontal();
         frame.m_position = EditorGUILayout.Vector3Field("", frame.m_position);
     }
     if (frame.HasTween(E_TweenType.Rotation))
     {
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField("Rotation");
         if (data != null && data.m_target != null && GUILayout.Button("Current"))
         {
             frame.m_rotation = data.m_target.transform.localRotation.eulerAngles;
         }
         EditorGUILayout.EndHorizontal();
         frame.m_rotation = EditorGUILayout.Vector3Field("", frame.m_rotation);
     }
     if (frame.HasTween(E_TweenType.Scale))
     {
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField("Scale");
         if (data != null && data.m_target != null && GUILayout.Button("Current"))
         {
             frame.m_scale = data.m_target.transform.localScale;
         }
         EditorGUILayout.EndHorizontal();
         frame.m_scale = EditorGUILayout.Vector3Field("", frame.m_scale);
     }
     if (frame.HasTween(E_TweenType.Color))
     {
         frame.m_color = EditorGUILayout.ColorField("Color", frame.m_color);
     }
     if (frame.HasTween(E_TweenType.Alpha))
     {
         frame.m_alpha = EditorGUILayout.FloatField("Alpha", frame.m_alpha);
     }
 }
Exemplo n.º 3
0
    public float GetDuration()
    {
        float duration = 0f;

        for (int i = 0; i < m_frames.Count; i++)
        {
            UIAnimFrame f = m_frames[i];
            if (f.m_type == E_UIAnimType.Empty ||
                (f.m_type == E_UIAnimType.Tween && (int)f.m_tween != 0) ||
                (f.m_type == E_UIAnimType.PlayAnimation && !string.IsNullOrEmpty(f.m_audioName)))
            {
                duration += f.m_duration;
            }
            else if (f.m_type == E_UIAnimType.SubAnim && f.m_animPlayer != null && f.m_particleDestroyAfterPlay)
            {
                duration += f.m_animPlayer.Length;
            }
        }
        return(duration);
    }
Exemplo n.º 4
0
 public void CopyFrom(UIAnimFrame other)
 {
     if (other == null)
     {
         return;
     }
     m_type         = other.m_type;
     m_tween        = other.m_tween;
     m_method       = other.m_method;
     m_duration     = other.m_duration;
     m_position     = other.m_position;
     m_rotation     = other.m_rotation;
     m_scale        = other.m_scale;
     m_color        = other.m_color;
     m_alpha        = other.m_alpha;
     m_audioName    = other.m_audioName;
     m_particlePath = other.m_particlePath;
     //m_particleParent = other.m_particleParent;
     m_particleDestroyAfterPlay = other.m_particleDestroyAfterPlay;
 }
Exemplo n.º 5
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();
                    }
                }
            }
        }
    }
Exemplo n.º 6
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();
        }
    }
    void AnimFrameEditor(System.Object animDataObj, UIAnimFrame frame)
    {
        //EditorGUILayout.BeginHorizontal("box");
        {
            EditorGUILayout.BeginVertical("box");
            {
                //EditorGUILayout.BeginHorizontal();
                //{
                //    if (GUILayout.Button("Copy"))
                //    {
                //        SaveProtoBuff<UIAnimFrame>(frame, TEMP_PATH_ROOT + "AnimFrame.bytes");
                //    }
                //    if (GUILayout.Button("Paste"))
                //    {
                //        frame.CopyFrome(LoadProtoBuff<UIAnimFrame>(TEMP_PATH_ROOT + "AnimFrame.bytes"));
                //    }
                //}
                //EditorGUILayout.EndHorizontal();
                frame.m_type = (E_UIAnimType)EditorGUILayout.EnumPopup("Type", frame.m_type);
                switch (frame.m_type)
                {
                case E_UIAnimType.Empty:
                {
                    Color gc = GUI.color;
                    GUI.color        = Color.green;
                    frame.m_duration = EditorGUILayout.FloatField("Duration", frame.m_duration);
                    GUI.color        = gc;
                }
                break;

                case E_UIAnimType.Set:
                    frame.m_tween = (E_TweenType)EditorGUILayout.EnumMaskField(frame.m_tween.ToString(), frame.m_tween);
                    FrameFieldEditor((UIAnimData)animDataObj, frame);
                    break;

                case E_UIAnimType.PlaySFX:
                    frame.m_audioName      = EditorGUILayout.TextField("Audio Name", frame.m_audioName);
                    frame.m_duration       = EditorGUILayout.FloatField("Minimum Delay", frame.m_duration);
                    frame.m_alpha          = EditorGUILayout.FloatField("Maximum Delay", frame.m_alpha);
                    frame.m_scale.x        = EditorGUILayout.FloatField("Minimum Pitch", frame.m_scale.x);
                    frame.m_scale.y        = EditorGUILayout.FloatField("Maximum Pitch", frame.m_scale.y);
                    frame.m_particleParent = EditorGUILayout.ObjectField("Parent", frame.m_particleParent, typeof(Transform), true) as Transform;
                    break;

                case E_UIAnimType.PlayBGM:
                case E_UIAnimType.PlayVOX:
                    frame.m_audioName = EditorGUILayout.TextField("Audio Name", frame.m_audioName);
                    break;

                case E_UIAnimType.AddParticle:
                    frame.m_particlePath             = EditorGUILayout.TextField("Path", frame.m_particlePath);
                    frame.m_particleParent           = EditorGUILayout.ObjectField("Parent", frame.m_particleParent, typeof(Transform), true) as Transform;
                    frame.m_position                 = EditorGUILayout.Vector3Field("Position", frame.m_position);
                    frame.m_particleDestroyAfterPlay = EditorGUILayout.Toggle("One Shot", frame.m_particleDestroyAfterPlay);
                    break;

                case E_UIAnimType.Tween:
                {
                    Color gc = GUI.color;
                    GUI.color        = Color.green;
                    frame.m_duration = EditorGUILayout.FloatField("Duration", frame.m_duration);
                    GUI.color        = gc;
                    frame.m_tween    = (E_TweenType)EditorGUILayout.EnumMaskField(frame.m_tween.ToString(), frame.m_tween);
                    frame.m_method   = (UITweener.Method)EditorGUILayout.EnumPopup("Method", frame.m_method);

                    FrameFieldEditor((UIAnimData)animDataObj, frame);
                }
                break;

                case E_UIAnimType.SubAnim:
                {
                    frame.m_animPlayer = EditorGUILayout.ObjectField("Anim Player", frame.m_animPlayer, typeof(BaseAnimPlayer), true) as BaseAnimPlayer;
                    frame.m_particleDestroyAfterPlay = EditorGUILayout.Toggle("Block While Playing", frame.m_particleDestroyAfterPlay);
                    if (frame.m_animPlayer != null)
                    {
                        Color gc = GUI.color;
                        GUI.color = Color.green;
                        GUILayout.Label("Anim Player found.");
                        GUI.color = gc;
                    }
                    else
                    {
                        Color gc = GUI.color;
                        GUI.color = Color.red;
                        GUILayout.Label("Anim Player NOT found!");
                        GUI.color = gc;
                    }
                }
                break;

                case E_UIAnimType.SubAnimGroup:
                    frame.m_animPlayerGroup          = EditorGUILayout.ObjectField(frame.m_animPlayerGroup, typeof(GameObject), true) as GameObject;
                    frame.m_duration                 = EditorGUILayout.FloatField("Interval", frame.m_duration);
                    frame.m_alpha                    = EditorGUILayout.IntField("Index", Mathf.FloorToInt(frame.m_alpha));
                    frame.m_particleDestroyAfterPlay = EditorGUILayout.Toggle("Block While Playing", frame.m_particleDestroyAfterPlay);
                    break;

                case E_UIAnimType.EnableBehaviour:
                    //frame.m_behaviour = EditorGUILayout.ObjectField(frame.m_behaviour, typeof(Behaviour), true) as Behaviour;
                    frame.m_behaviour = ComponentField <Behaviour>("Behaviour", frame.m_behaviour);
                    frame.m_particleDestroyAfterPlay = EditorGUILayout.Toggle("Enabled", frame.m_particleDestroyAfterPlay);
                    break;

                case E_UIAnimType.PlayAnimation:
                    frame.m_audioName = EditorGUILayout.TextField("AnimationClip", frame.m_audioName);
                    Color c = GUI.color;
                    GUI.color        = Color.green;
                    frame.m_duration = EditorGUILayout.FloatField("Duration", frame.m_duration);
                    GUI.color        = c;
                    break;

                case E_UIAnimType.SendEvent:
                    frame.m_audioName = EditorGUILayout.TextField("EventName", frame.m_audioName);
                    break;

                default: break;
                }
                EditorGUILayout.Separator();
            }
            EditorGUILayout.EndVertical();
        }
        //EditorGUILayout.EndHorizontal();
    }