Beispiel #1
0
 public void StopPreview()
 {
     anima.EditorStopPreview(this);
     anima           = null;
     previewClip     = null;
     isPreviewingOne = false;
     isPreviewingAll = false;
 }
Beispiel #2
0
    private static X2DAnimation CreateNewX2dAnimation(X2DAnimation org, Transform parent)
    {
        X2DAnimation anim = GameObject.Instantiate <X2DAnimation>(org);

        anim.transform.parent        = parent;
        anim.transform.localPosition = Vector3.zero;
        anim.transform.localRotation = Quaternion.identity;
        anim.gameObject.SetActive(true);
        return(anim);
    }
Beispiel #3
0
 public void PreviewAll()
 {
     if (anima == null)
     {
         anima = GetComponent <X2DAnimation>();
     }
     isPreviewingAll = true;
     isPreviewingOne = false;
     anima.EditorStartPreview(this, anima.clipArray[curClipIndex], true, OnClipPlayEnd);
 }
Beispiel #4
0
 public void PreviewOne(X2DAnimationClip clip)
 {
     if (anima == null)
     {
         anima = GetComponent <X2DAnimation>();
     }
     previewClip     = clip;
     isPreviewingAll = false;
     isPreviewingOne = true;
     anima.EditorStartPreview(this, clip, false, null);
 }
Beispiel #5
0
    public static X2DAnimation GetX2dAniamtion(string animationName, Transform parent)
    {
        X2DAnimation prefab = Resources.Load <X2DAnimation>(x2dAnimationFolder + animationName);

        if (prefab == null)
        {
            Debug.LogError("X2DAnimation is not exist: " + x2dAnimationFolder + animationName);
        }
        else
        {
            return(CreateNewX2dAnimation(prefab, parent));
        }
        return(null);
    }
 //编辑器中刷新clip数组
 public void UpdateClipArrayInEditor(X2DAnimation anima)
 {
     X2DAnimationClip[] clipArray = anima.GetComponentsInChildren <X2DAnimationClip>(true);
     anima.clipArray = clipArray;
     //剪辑名字排列
     for (int i = 0; i < clipArray.Length - 1; i++)
     {
         for (int j = 0; j < clipArray.Length - 1 - i; j++)
         {
             if (clipArray[j].clipName.CompareTo(clipArray[j + 1].clipName) > 0)
             {
                 X2DAnimationClip t = clipArray[j];
                 clipArray[j]     = clipArray[j + 1];
                 clipArray[j + 1] = t;
             }
         }
     }
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        X2DAnimation anima = target as X2DAnimation;

        anima.flipX       = EditorGUILayout.Toggle("flipX", anima.flipX);
        anima.flipY       = EditorGUILayout.Toggle("flipY", anima.flipY);
        anima.isFaceRight = EditorGUILayout.Toggle("isFaceRight", anima.isFaceRight);

        if (GUILayout.Button("UpdateClipArray", GUILayout.Width(120)))
        {
            UpdateClipArrayInEditor(anima);
        }

        GUI.enabled = Application.isPlaying;
        if (!anima.isPreviewing)
        {
            if (GUILayout.Button("StartPreviewAll", GUILayout.Width(150)))
            {
                X2DAnimationPreviewer previewer = anima.GetComponent <X2DAnimationPreviewer>();
                if (previewer == null)
                {
                    previewer = anima.gameObject.AddComponent <X2DAnimationPreviewer>();
                }
                previewer.PreviewAll();
            }
        }
        else
        {
            if (GUILayout.Button("StopPreviewAll", GUILayout.Width(150)))
            {
                X2DAnimationPreviewer previewer = anima.GetComponent <X2DAnimationPreviewer>();
                if (previewer != null)
                {
                    previewer.StopPreview();
                }
            }
        }
        GUI.enabled = true;
    }
    void OnGUI()
    {
        X2DAnimationClip clip = null;

        if (Selection.activeGameObject != null)
        {
            clip = Selection.activeGameObject.GetComponent <X2DAnimationClip>();
        }
        if (clip != null)
        {
            curSelectedClip = clip;
        }
        else
        {
            clip = curSelectedClip;            //如果当前没选中动画剪辑,则继续显示当前的动画剪辑
        }
        if (clip == null)
        {
            return;
        }

        GUI.color = new Color(255 / 255f, 204 / 255f, 255 / 255f);
        GUILayout.Label("[" + clip.name + "]");
        GUI.color = Color.white;

        if (clip.frameList == null)
        {
            GUI.color = Color.red;
            GUILayout.Label("剪辑列未创建");
            GUI.color = Color.white;
            return;
        }

        //分左右两组
        GUILayout.BeginHorizontal();
        //第一组
        GUILayout.BeginVertical(GUILayout.Width(300));
        //OneKeyFrameTime
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("OneKeyFrameTime", GUILayout.Width(132)))
        {
            for (int i = 0; i < clip.frameList.Count; i++)
            {
                clip.frameList[i].duration = oneKeyFrameTime;
            }
        }
        oneKeyFrameTime = EditorGUILayout.FloatField(oneKeyFrameTime, GUILayout.Width(150));
        GUILayout.EndHorizontal();

        //OneKeyFrameSize
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("OneKeyFrameSize", GUILayout.Width(132)))
        {
            for (int i = 0; i < clip.frameList.Count; i++)
            {
                clip.frameList[i].size = oneKeyFrameSize;
            }
        }
        oneKeyFrameSize = TqmGUILayoutUtility.SimpleVector2(oneKeyFrameSize, 60);
        GUILayout.EndHorizontal();

        //OneKeyFrameRegion
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("OneKeyFrameRegion", GUILayout.Width(132)))
        {
            for (int i = 0; i < clip.frameList.Count; i++)
            {
                clip.frameList[i].region = oneKeyFrameRegion;
            }
        }
        oneKeyFrameRegion = TqmGUILayoutUtility.SimpleVector2(oneKeyFrameRegion, 60);
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        //第二组
        GUILayout.BeginVertical();
        //clip name
        GUILayout.BeginHorizontal();
        GUILayout.Label("ClipName", GUILayout.Width(100));
        clip.clipName = GUILayout.TextField(clip.clipName, GUILayout.Width(100));
        GUILayout.EndHorizontal();

        //duration
        clip.duration = 0;
        for (int i = 0; i < clip.frameList.Count; i++)
        {
            clip.duration += clip.frameList[i].duration;
        }
        GUILayout.BeginHorizontal();
        GUILayout.Label("Duration", GUILayout.Width(100));
        clip.duration = EditorGUILayout.FloatField(clip.duration, GUILayout.Width(100));
        GUILayout.EndHorizontal();

        //play mode
        GUILayout.BeginHorizontal();
        GUILayout.Label("PlayMode", GUILayout.Width(100));
        clip.playMode = (EmX2DAnimationPlayMode)EditorGUILayout.EnumPopup(clip.playMode, GUILayout.Width(100));
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        //pos correct
        GUILayout.BeginHorizontal();
        if (clip.posCorrecting)
        {
            GUI.color = Color.red;
            if (GUILayout.Button("StopCorrecting", GUILayout.Width(100)))
            {
                GameObject   animaGO = clip.transform.parent.gameObject;
                X2DAnimation anima   = animaGO.GetComponent <X2DAnimation>();
                if (anima != null)
                {
                    anima.EditorShowRenderer();
                }
                clip.posCorrecting = false;
            }
            GUI.color = Color.white;
        }
        else
        {
            if (GUILayout.Button("StartCorrecting", GUILayout.Width(100)))
            {
                GameObject   animaGO = clip.transform.parent.gameObject;
                X2DAnimation anima   = animaGO.GetComponent <X2DAnimation>();
                if (anima != null)
                {
                    anima.EditorHideRenderer();
                }
                clip.posCorrecting = true;
            }
        }
        clip.Update_PosCorrecting();

        //fill with seleced textures
        if (GUILayout.Button("fill with selected textures", GUILayout.Width(160)))
        {
            if (Selection.objects.Length == 0)
            {
                Debug.LogError("no object selected");
            }
            else
            {
                Object[] array = Selection.objects;
                SortByName(array);
                for (int i = 0; i < array.Length && i < clip.frameList.Count; i++)
                {
                    clip.frameList[i].tex = array[i] as Texture2D;
                }
            }
        }

        //load frame info
        if (GUILayout.Button("load frame info", GUILayout.Width(100)))
        {
            LoadTextureInfo(clip);
        }

        //load org tex size
        useTexutreSize = GUILayout.Button("load org tex size", GUILayout.Width(120));

        GUILayout.EndHorizontal();


        //list length
        GUILayout.BeginHorizontal();
        GUILayout.Label("FrameList", GUILayout.Width(100));
        GUILayout.Label(clip.frameList.Count.ToString(), GUILayout.Width(10));
        frameListSize = EditorGUILayout.IntField(frameListSize, GUILayout.Width(86));
        bool resize = GUILayout.Button("Resize", GUILayout.Width(50));

        GUILayout.EndHorizontal();
        if (resize)
        {
            if (frameListSize > clip.frameList.Count)
            {
                for (int i = clip.frameList.Count; i < frameListSize; i++)
                {
                    X2DAnimationFrame f = new X2DAnimationFrame();
                    clip.frameList.Add(f);
                }
            }
            else if (frameListSize < clip.frameList.Count)
            {
                for (int i = clip.frameList.Count; i > frameListSize; i--)
                {
                    clip.frameList.RemoveAt(clip.frameList.Count - 1);
                }
            }
        }

        //list成员
        int insertAt = -1;
        int removeAt = -1;

        mScroll = GUILayout.BeginScrollView(mScroll);
        float frameStartTime = 0f;

        for (int i = 0; i < clip.frameList.Count; i++)
        {
            X2DAnimationFrame frame = clip.frameList[i];
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            //order
            GUILayout.Label(i.ToString(), GUILayout.Width(10));
            //Duration
            TqmGUILayoutUtility.ColorLable(Color.blue, "duration", GUILayout.Width(60));
            clip.frameList[i].duration = EditorGUILayout.FloatField(frame.duration, GUILayout.Width(40));
            //startTime
            frame.startTime = frameStartTime;
            frameStartTime += frame.duration;
            GUILayout.Label(frame.startTime.ToString("f2"), GUILayout.Width(30));
            //size
            TqmGUILayoutUtility.ColorLable(Color.blue, " size", GUILayout.Width(30));
            frame.size.x = EditorGUILayout.FloatField(frame.size.x, GUILayout.Width(40));
            frame.size.y = EditorGUILayout.FloatField(frame.size.y, GUILayout.Width(40));
            if (useTexutreSize)
            {
                frame.size = new Vector2(frame.tex.width, frame.tex.height);
            }
            //pos
            TqmGUILayoutUtility.ColorLable(Color.blue, " pos", GUILayout.Width(28));
            frame.pos.x = EditorGUILayout.FloatField(frame.pos.x, GUILayout.Width(40));
            frame.pos.y = EditorGUILayout.FloatField(frame.pos.y, GUILayout.Width(40));
            //frameRegion
            TqmGUILayoutUtility.ColorLable(Color.blue, " region", GUILayout.Width(44));
            frame.region.x = EditorGUILayout.FloatField(frame.region.x, GUILayout.Width(40));
            frame.region.y = EditorGUILayout.FloatField(frame.region.y, GUILayout.Width(40));
            //texture
            TqmGUILayoutUtility.ColorLable(Color.blue, " tex", GUILayout.Width(26));
            frame.tex = EditorGUILayout.ObjectField(frame.tex, typeof(Object), true) as Texture2D;
            //insert remove
            if (GUILayout.Button("-"))
            {
                removeAt = i;
            }
            if (GUILayout.Button("+"))
            {
                insertAt = i;
            }

            GUILayout.EndHorizontal();
        }
        if (GUILayout.Button("+"))
        {
            insertAt = clip.frameList.Count;
        }

        //进行插入删除
        if (removeAt > -1)
        {
            clip.frameList.RemoveAt(removeAt);
        }
        if (insertAt > -1)
        {
            clip.frameList.Insert(insertAt, new X2DAnimationFrame());
        }

        GUILayout.EndScrollView();
        useTexutreSize = false;
    }