Example #1
0
        void AddTween(SerializedProperty tweens)
        {
            if (addTweenType == AnimType.Blink)
            {
                Debug.LogError("暂不支持该类型.请直接使用脚本执行该类型动画.");
                return;
            }

            MonoTweener tar = (MonoTweener)target;

            if (addTweenType == AnimType.UiSize || addTweenType == AnimType.UiAnchoredPosition)
            {
                if (tar.GetComponent <RectTransform>() == null)
                {
                    Debug.LogError("当前物体不是UI,不能添加UI动画");
                    return;
                }
            }

            tweens.arraySize += 1;
            SerializedProperty thisTween         = tweens.GetArrayElementAtIndex(tweens.arraySize - 1);
            SerializedProperty tweenObject       = thisTween.FindPropertyRelative("animGameObject");
            SerializedProperty thisTween_IsLocal = thisTween.FindPropertyRelative("isLocal");
            SerializedProperty thisTweenType     = thisTween.FindPropertyRelative("animType");
            SerializedProperty thisTween_Curve   = thisTween.FindPropertyRelative("curve");


            thisTweenType.enumValueIndex = (int)addTweenType;
            thisTween_IsLocal.boolValue  = true;

            thisTween_Curve.animationCurveValue = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));

            tweenObject.objectReferenceValue = tar.gameObject;

            SetCurrentValueCustomTn(thisTween, false);
            SetCurrentValueCustomTn(thisTween, true);
        }
Example #2
0
        /// <summary>
        /// UI
        /// </summary>
        public override void OnInspectorGUI()
        {
            MonoTweener tar = (MonoTweener)target;

            serializedObject.Update();

            SerializedProperty playType        = serializedObject.FindProperty("playType");
            SerializedProperty animationTime   = serializedObject.FindProperty("animationTime");
            SerializedProperty delay           = serializedObject.FindProperty("delay");
            SerializedProperty playOnAwake     = serializedObject.FindProperty("playOnAwake");
            SerializedProperty IgnoreTimeScale = serializedObject.FindProperty("ignoreTimeScale");

            SerializedProperty m_onFinish = serializedObject.FindProperty("m_onFinish");

            SerializedProperty tweens = serializedObject.FindProperty("tweens");

            GUILayout.BeginVertical(GUILayout.MinHeight(100));
            EditorGUILayout.PropertyField(playType);
            EditorGUILayout.PropertyField(animationTime);
            EditorGUILayout.PropertyField(delay);
            EditorGUILayout.PropertyField(playOnAwake);
            EditorGUILayout.PropertyField(IgnoreTimeScale);

            GUILayout.BeginVertical(EditorStyles.helpBox);

            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }
            GUILayout.Label("Preview");

            GUILayout.BeginHorizontal();
            bool play = GUILayout.Toggle(isPlaying, "▶", EditorStyles.miniButton, GUILayout.Width(20),
                                         GUILayout.Height(20));

            if (play != isPlaying)
            {
                playTime  = Time.realtimeSinceStartup;
                isPlaying = play;
            }

            if (isPlaying)
            {
                float t = Time.realtimeSinceStartup - playTime;
                if (t > 1)
                {
                    playTime = Time.realtimeSinceStartup;
                    t        = 0;
                }

                tar.previewValue = t;
                EditorGUILayout.Slider(tar.previewValue, 0f, 1f);
            }
            else
            {
                tar.previewValue = EditorGUILayout.Slider(tar.previewValue, 0f, 1f);
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.enabled = true;

            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("Tweener List");

            GUILayout.BeginHorizontal();
            addTweenType = (AnimType)EditorGUILayout.EnumPopup(addTweenType);

            if (GUILayout.Button("Add Tween", EditorStyles.miniButton))
            {
                AddTween(tweens);
            }

            GUILayout.EndHorizontal();

            // draw items
            for (int i = 0; i < tweens.arraySize; i++)
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                SerializedProperty thisTween           = tweens.GetArrayElementAtIndex(i);
                SerializedProperty thisTween_TweenType = thisTween.FindPropertyRelative("animType");

                bool deleteElement = false;

                string thisTweenName = "Tween" + (i + 1) + ":" +
                                       thisTween_TweenType.enumNames[thisTween_TweenType.enumValueIndex];
                var       tweenType = (AnimType)thisTween_TweenType.enumValueIndex;
                Texture2D tweenIcon = GetCustomTnIcon(tweenType);

                GUILayout.BeginHorizontal();

                GUILayout.BeginHorizontal();
                if (tweenIcon != null)
                {
                    GUILayout.Button(tweenIcon, EditorStyles.label, GUILayout.Height(20), GUILayout.Width(20));
                }
                GUILayout.Label(thisTweenName);
                GUILayout.EndHorizontal();

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
                {
                    if (EditorUtility.DisplayDialog("Delete Tween?", "Delete this Tween?", "Yes", "No"))
                    {
                        tweens.DeleteArrayElementAtIndex(i);
                        deleteElement = true;
                    }
                }

                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (!deleteElement)
                {
                    SerializedProperty thisTween_Curve    = thisTween.FindPropertyRelative("curve");
                    SerializedProperty thisTween_IsLocal  = thisTween.FindPropertyRelative("isLocal");
                    SerializedProperty thisTween_EaseType = thisTween.FindPropertyRelative("easeType");

                    GUILayout.TextArea("", GUILayout.Height(2));
                    if (tweenType == AnimType.Position || tweenType == AnimType.Rotate)
                    {
                        EditorGUILayout.PropertyField(thisTween_IsLocal);
                    }

                    EditorGUILayout.PropertyField(thisTween_EaseType);
                    var easeType = (Ease)thisTween_EaseType.enumValueIndex;
                    if (easeType == Ease.Default)
                    {
                        EditorGUILayout.PropertyField(thisTween_Curve);
                    }

                    GUILayout.TextArea("", GUILayout.Height(2));

                    DrawCustomTn(thisTween, tweenType);
                    DrawCustomTnAfter(thisTween, tweenType);
                }

                GUILayout.EndVertical();
            }

            GUILayout.EndVertical();

            EditorGUILayout.PropertyField(m_onFinish);
            GUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }