Unity 编辑器开发实战【Custom Editor】- 为UI视图制作动画编辑器

简介: Unity 编辑器开发实战【Custom Editor】- 为UI视图制作动画编辑器

 image.gif

为了更方便地为UI视图添加动画,将动画的编辑功能封装在了UI View类中,可以通过编辑器快速的为视图编辑动画。动画分为两种类型,一种是Unity中的Animator动画,该类型直接通过一个字符串类型变量记录动画State状态的名称即可,播放时调用Animator类中的Play方法传入该名称。另一种是DoTween动画,支持视图的移动、旋转、缩放、淡入淡出动画的编辑:

image.gif

首先看一下动画相关的几个类的数据结构:

usingSystem;
usingUnityEngine;
usingDG.Tweening;
namespaceSK.Framework{
/// <summary>/// UI移动动画/// </summary>    [Serializable]
publicclassUIMoveAnimation    {
publicenumMoveMode        {
MoveIn,
MoveOut        }
/// <summary>/// UI移动动画方向/// </summary>publicenumUIMoveAnimationDirection        {
Left,
Right,
Top,
Bottom,
TopLeft,
TopRight,
MiddleCenter,
BottomLeft,
BottomRight,
        }
publicfloatduration=1f;
publicfloatdelay;
publicEaseease=Ease.Linear;
publicUIMoveAnimationDirectiondirection=UIMoveAnimationDirection.Left;
publicboolisCustom;
publicVector3startValue;
publicVector3endValue;
publicMoveModemoveMode=MoveMode.MoveIn;
publicTweenPlay(RectTransformtarget, boolinstant=false)
        {
Vector3pos=Vector3.zero;
floatxOffset=target.rect.width/2+target.rect.width*target.pivot.x;
floatyOffset=target.rect.height/2+target.rect.height*target.pivot.y;
switch (direction)
            {
caseUIMoveAnimationDirection.Left: pos=newVector3(-xOffset, 0f, 0f); break;
caseUIMoveAnimationDirection.Right: pos=newVector3(xOffset, 0f, 0f); break;
caseUIMoveAnimationDirection.Top: pos=newVector3(0f, yOffset, 0f); break;
caseUIMoveAnimationDirection.Bottom: pos=newVector3(0f, -yOffset, 0f); break;
caseUIMoveAnimationDirection.TopLeft: pos=newVector3(-xOffset, yOffset, 0f); break;
caseUIMoveAnimationDirection.TopRight: pos=newVector3(xOffset, yOffset, 0f); break;
caseUIMoveAnimationDirection.MiddleCenter: pos=Vector3.zero; break;
caseUIMoveAnimationDirection.BottomLeft: pos=newVector3(-xOffset, -yOffset, 0f); break;
caseUIMoveAnimationDirection.BottomRight: pos=newVector3(xOffset, -yOffset, 0f); break;
            }
switch (moveMode)
            {
caseMoveMode.MoveIn:
target.anchoredPosition3D=isCustom?startValue : pos;
returntarget.DOAnchorPos3D(endValue, instant?0f : duration).SetDelay(instant?0f : delay).SetEase(ease);
caseMoveMode.MoveOut:
target.anchoredPosition3D=startValue;
returntarget.DOAnchorPos3D(isCustom?endValue : pos, instant?0f : duration).SetDelay(instant?0f : delay).SetEase(ease);
default: returnnull;
            }
        }
    }
}

image.gif

usingSystem;
usingUnityEngine;
usingDG.Tweening;
namespaceSK.Framework{
/// <summary>/// UI旋转动画/// </summary>    [Serializable]
publicclassUIRotateAnimation    {
publicfloatduration=1f;
publicfloatdelay;
publicEaseease=Ease.Linear;
publicVector3startValue;
publicVector3endValue;
publicRotateModerotateMode=RotateMode.Fast;
publicboolisCustom;
publicTweenPlay(RectTransformtarget, boolinstant=false)
        {
if (isCustom)
            {
target.localRotation=Quaternion.Euler(startValue);
            }
returntarget.DORotate(endValue, instant?0f : duration, rotateMode).SetDelay(instant?0f : delay).SetEase(ease);
        }
    }
}

image.gif

usingSystem;
usingUnityEngine;
usingDG.Tweening;
namespaceSK.Framework{
/// <summary>/// UI缩放动画/// </summary>    [Serializable]
publicclassUIScaleAnimation    {
publicfloatduration=1f;
publicfloatdelay;
publicEaseease=Ease.Linear;
publicVector3startValue=Vector3.zero;
publicVector3endValue=Vector3.one;
publicboolisCustom;
publicTweenPlay(RectTransformtarget, boolinstant=false)
        {
if (isCustom)
            {
target.localScale=startValue;
            }
returntarget.DOScale(endValue, instant?0f : duration).SetDelay(instant?0f : delay).SetEase(ease);
        }
    }
}

image.gif

usingSystem;
usingDG.Tweening;
usingUnityEngine;
namespaceSK.Framework{
/// <summary>/// UI淡入淡出动画/// </summary>    [Serializable]
publicclassUIFadeAnimation    {
publicfloatduration=1f;
publicfloatdelay;
publicEaseease=Ease.Linear;
publicfloatstartValue;
publicfloatendValue=1f;
publicboolisCustom;
publicTweenPlay(CanvasGrouptarget, boolinstant=false)
        {
if (isCustom)
            {
target.alpha=startValue;
            }
returntarget.DOFade(endValue, instant?0f : duration).SetDelay(instant?0f : delay).SetEase(ease);
        }
    }
}

image.gif

namespaceSK.Framework{
/// <summary>/// UI动画类型/// </summary>publicenumUIAnimationType    {
/// <summary>/// DoTween动画/// </summary>Tween,
/// <summary>/// Animator动画/// </summary>Animator,
    }
}

image.gif

usingSystem;
usingUnityEngine;
namespaceSK.Framework{
/// <summary>/// UI动画/// </summary>    [Serializable]
publicclassUIAnimation    {
publicUIAnimationTypeanimationType=UIAnimationType.Tween;
publicstringstateName;
publicboolmoveToggle;
publicUIMoveAnimationmoveAnimation;
publicboolrotateToggle;
publicUIRotateAnimationrotateAnimation;
publicboolscaleToggle;
publicUIScaleAnimationscaleAnimation;
publicboolfadeToggle;
publicUIFadeAnimationfadeAnimation;
publicboolHasTweenAnimation        {
get            {
returnmoveToggle||rotateToggle||scaleToggle||fadeToggle;
            }
        }
publicIChainPlay(UIViewview, boolinstant=false, Actioncallback=null)
        {
switch (animationType)
            {
caseUIAnimationType.Tween:
if (HasTweenAnimation)
                    {
varchain=view.Sequence();
varcc=newConcurrentChain();
if (moveToggle) cc.Tween(() =>moveAnimation.Play(view.RectTransform, instant));
if (rotateToggle) cc.Tween(() =>rotateAnimation.Play(view.RectTransform, instant));
if (scaleToggle) cc.Tween(() =>scaleAnimation.Play(view.RectTransform, instant));
if (fadeToggle) cc.Tween(() =>fadeAnimation.Play(view.CanvasGroup, instant));
chain.Append(cc).Event(() =>callback?.Invoke()).Begin();
returnchain;
                    }
else                    {
callback?.Invoke();
returnnull;
                    }
caseUIAnimationType.Animator:
returnview.Sequence()
                        .Animation(view.GetComponent<Animator>(), stateName)
                        .Event(() =>callback?.Invoke())
                        .Begin();
default: returnnull;
            }
        }
    }
}

image.gif

在UI View类中的相关变量如下:

image.gif

usingSystem;
usingUnityEngine.Events;
namespaceSK.Framework{
    [Serializable]
publicclassViewVisibilityChangedEvent    {
publicUIAnimationanimation=newUIAnimation();
publicUnityEventonBeginEvent;
publicUnityEventonEndEvent;
    }
}

image.gif

为UI View创建Custom Editor:

usingSystem;
usingUnityEngine;
usingUnityEditor;
usingDG.Tweening;
usingSystem.Reflection;
usingUnityEditor.Animations;
usingUnityEditor.AnimatedValues;
namespaceSK.Framework{
    [CustomEditor(typeof(UIView), true)]
publicclassUIViewInspector : Editor    {
privateenumMenu        {
Animation,
UnityEvent,
        }
privateUIViewTarget;
privateSerializedPropertyvariables;
privateViewVisibilityChangedEventonShow;
privateViewVisibilityChangedEventonHide;
privatestaticstringuiViewOnShowFoldout="UIView OnShow Foldout";
privatestaticstringuiViewOnHideFoldout="UIView OnHide Foldout";
privateboolonShowFoldout;
privateboolonHideFoldout;
privateMenuonShowMenu=Menu.Animation;
privateMenuonHideMenu=Menu.Animation;
privateSerializedPropertyonShowBeginEvent;
privateSerializedPropertyonShowEndEvent;
privateSerializedPropertyonHideBeginEvent;
privateSerializedPropertyonHideEndEvent;
privateAnimBoolonShowMoveAnimBool;
privateAnimBoolonShowRotateAnimBool;
privateAnimBoolonShowScaleAnimBool;
privateAnimBoolonShowFadeAnimBool;
privateAnimBoolonHideMoveAnimBool;
privateAnimBoolonHideRotateAnimBool;
privateAnimBoolonHideScaleAnimBool;
privateAnimBoolonHideFadeAnimBool;
privateconstfloattitleWidth=80f;
privateconstfloatlabelWidth=60f;
publicoverridevoidOnInspectorGUI()
        {
if (Target==null)
            {
Target=targetasUIView;
onShow=typeof(UIView).GetField("onVisible", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(Target) asViewVisibilityChangedEvent;
onHide=typeof(UIView).GetField("onInvisible", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(Target) asViewVisibilityChangedEvent;
variables=serializedObject.FindProperty("variables");
onShowFoldout=EditorPrefs.GetBool(uiViewOnShowFoldout);
onHideFoldout=EditorPrefs.GetBool(uiViewOnHideFoldout);
onShowBeginEvent=serializedObject.FindProperty("onVisible").FindPropertyRelative("onBeginEvent");
onShowEndEvent=serializedObject.FindProperty("onVisible").FindPropertyRelative("onEndEvent");
onHideBeginEvent=serializedObject.FindProperty("onInvisible").FindPropertyRelative("onBeginEvent");
onHideEndEvent=serializedObject.FindProperty("onInvisible").FindPropertyRelative("onEndEvent");
onShowMoveAnimBool=newAnimBool(onShow.animation.moveToggle, Repaint);
onShowRotateAnimBool=newAnimBool(onShow.animation.rotateToggle, Repaint);
onShowScaleAnimBool=newAnimBool(onShow.animation.scaleToggle, Repaint);
onShowFadeAnimBool=newAnimBool(onShow.animation.fadeToggle, Repaint);
onHideMoveAnimBool=newAnimBool(onHide.animation.moveToggle, Repaint);
onHideRotateAnimBool=newAnimBool(onHide.animation.rotateToggle, Repaint);
onHideScaleAnimBool=newAnimBool(onHide.animation.scaleToggle, Repaint);
onHideFadeAnimBool=newAnimBool(onHide.animation.fadeToggle, Repaint);
            }
EditorGUILayout.PropertyField(variables);
//On Show 折叠栏varnewOnShowFoldout=EditorGUILayout.Foldout(onShowFoldout, "On Visible", true);
if (newOnShowFoldout!=onShowFoldout)
            {
onShowFoldout=newOnShowFoldout;
EditorPrefs.SetBool(uiViewOnShowFoldout, onShowFoldout);
            }
//Showif (onShowFoldout)
            {
GUILayout.BeginHorizontal();
Colorcolor=GUI.color;
GUI.color=onShowMenu==Menu.Animation?Color.cyan : color;
if (GUILayout.Button("Animation", "ButtonLeft"))
                {
onShowMenu=Menu.Animation;
                }
GUI.color=onShowMenu==Menu.UnityEvent?Color.cyan : color;
if (GUILayout.Button("Event", "ButtonRight"))
                {
onShowMenu=Menu.UnityEvent;
                }
GUI.color=color;
GUILayout.EndHorizontal();
switch (onShowMenu)
                {
caseMenu.Animation:
//Animation TypeGUILayout.BeginHorizontal();
GUILayout.Label("Mode", GUILayout.Width(titleWidth));
varnewOnShowAnimationType= (UIAnimationType)EditorGUILayout.EnumPopup(onShow.animation.animationType);
if (newOnShowAnimationType!=onShow.animation.animationType)
                        {
Undo.RecordObject(Target, "On Show Animation Type");
onShow.animation.animationType=newOnShowAnimationType;
EditorUtility.SetDirty(Target);
                        }
GUILayout.EndHorizontal();
UIAnimationanimation=onShow.animation;
switch (animation.animationType)
                        {
caseUIAnimationType.Tween:
//Move、Rotate、Scale、FadeGUILayout.BeginHorizontal();
                                {
GUI.color=animation.moveToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("MoveTool"), "ButtonLeft", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Show Animation Move Toggle");
animation.moveToggle=!animation.moveToggle;
onShowMoveAnimBool.target=animation.moveToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.rotateToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("RotateTool"), "ButtonMid", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Show Animation Rotate Toggle");
animation.rotateToggle=!animation.rotateToggle;
onShowRotateAnimBool.target=animation.rotateToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.scaleToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("ScaleTool"), "ButtonMid", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Show Animation Scale Toggle");
animation.scaleToggle=!animation.scaleToggle;
onShowScaleAnimBool.target=animation.scaleToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.fadeToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("ViewToolOrbit"), "ButtonRight", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Show Animation Fade Toggle");
animation.fadeToggle=!animation.fadeToggle;
onShowFadeAnimBool.target=animation.fadeToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=color;
                                }
GUILayout.EndHorizontal();
//MoveAnimationvarmoveAnimation=animation.moveAnimation;
if (EditorGUILayout.BeginFadeGroup(onShowMoveAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(40f);
GUILayout.Label(EditorGUIUtility.IconContent("MoveTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(moveAnimation.duration);
if (newDuration!=moveAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Show Animation Move Duration");
moveAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(moveAnimation.delay);
if (newDelay!=moveAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Show Animation Move Delay");
moveAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(moveAnimation.isCustom?"Custom Position" : "Direction", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Direction"), !moveAnimation.isCustom, () => { moveAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Custom Position"), moveAnimation.isCustom, () => { moveAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
//FromGUILayout.BeginHorizontal();
                                            {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
if (moveAnimation.isCustom)
                                                {
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, moveAnimation.startValue);
if (newStartValue!=moveAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Show Animation Move From");
moveAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
else                                                {
varnewMoveDirection= (UIMoveAnimationDirection)EditorGUILayout.EnumPopup(moveAnimation.direction);
if (newMoveDirection!=moveAnimation.direction)
                                                    {
Undo.RecordObject(Target, "On Show Animation Move Direction");
moveAnimation.direction=newMoveDirection;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
                                            }
GUILayout.EndHorizontal();
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, moveAnimation.endValue);
if (newEndValue!=moveAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Show Animation Move To");
moveAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(moveAnimation.ease);
if (newEase!=moveAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Show Animation Move Ease");
moveAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//RotateAnimationvarrotateAnimation=animation.rotateAnimation;
if (EditorGUILayout.BeginFadeGroup(onShowRotateAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(rotateAnimation.isCustom?50f : 40f);
GUILayout.Label(EditorGUIUtility.IconContent("RotateTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(rotateAnimation.duration);
if (newDuration!=rotateAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Show Animation Rotate Duration");
rotateAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(rotateAnimation.delay);
if (newDelay!=rotateAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Show Animation Rotate Delay");
rotateAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(rotateAnimation.isCustom?"Fixed Rotation" : "Current Rotation", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Rotation"), !rotateAnimation.isCustom, () => { rotateAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Rotation"), rotateAnimation.isCustom, () => { rotateAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (rotateAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, rotateAnimation.startValue);
if (newStartValue!=rotateAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Show Animation Rotate From");
rotateAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, rotateAnimation.endValue);
if (newEndValue!=rotateAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Show Animation Rotate To");
rotateAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Rotate ModeGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Mode", GUILayout.Width(labelWidth));
varnewRotateMode= (RotateMode)EditorGUILayout.EnumPopup(rotateAnimation.rotateMode);
if (newRotateMode!=rotateAnimation.rotateMode)
                                                {
Undo.RecordObject(Target, "On Show Animation Rotate Mode");
rotateAnimation.rotateMode=newRotateMode;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(rotateAnimation.ease);
if (newEase!=rotateAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Show Animation Rotate Ease");
rotateAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//ScaleAnimationvarscaleAnimation=animation.scaleAnimation;
if (EditorGUILayout.BeginFadeGroup(onShowScaleAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(scaleAnimation.isCustom?40f : 30f);
GUILayout.Label(EditorGUIUtility.IconContent("ScaleTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(scaleAnimation.duration);
if (newDuration!=scaleAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Show Animation Scale Duration");
scaleAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(scaleAnimation.delay);
if (newDelay!=scaleAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Show Animation Scale Delay");
scaleAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(scaleAnimation.isCustom?"Fixed Scale" : "Current Scale", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Scale"), !scaleAnimation.isCustom, () => { scaleAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Scale"), scaleAnimation.isCustom, () => { scaleAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (scaleAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, scaleAnimation.startValue);
if (newStartValue!=scaleAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Show Animation Scale From");
scaleAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, scaleAnimation.endValue);
if (newEndValue!=scaleAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Show Animation Scale To");
scaleAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(scaleAnimation.ease);
if (newEase!=scaleAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Show Animation Scale Ease");
scaleAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//FadeAnimationvarfadeAnimation=animation.fadeAnimation;
if (EditorGUILayout.BeginFadeGroup(onShowFadeAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(fadeAnimation.isCustom?40f : 30f);
GUILayout.Label(EditorGUIUtility.IconContent("ViewToolOrbit"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(fadeAnimation.duration);
if (newDuration!=fadeAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Show Animation Fade Duration");
fadeAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(fadeAnimation.delay);
if (newDelay!=fadeAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Show Animation Fade Delay");
fadeAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(fadeAnimation.isCustom?"Fixed Alpha" : "Current Alpha", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Alpha"), !fadeAnimation.isCustom, () => { fadeAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Alpha"), fadeAnimation.isCustom, () => { fadeAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (fadeAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
floatnewStartValue=EditorGUILayout.FloatField(GUIContent.none, fadeAnimation.startValue);
if (newStartValue!=fadeAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Show Animation Fade From");
fadeAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
floatnewEndValue=EditorGUILayout.FloatField(GUIContent.none, fadeAnimation.endValue);
if (newEndValue!=fadeAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Show Animation Fade To");
fadeAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(fadeAnimation.ease);
if (newEase!=fadeAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Show Animation Fade Ease");
fadeAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
break;
caseUIAnimationType.Animator:
varanimator=Target.GetComponent<Animator>();
if (animator!=null)
                                {
varanimatorController=animator.runtimeAnimatorControllerasAnimatorController;
varstateMachine=animatorController.layers[0].stateMachine;
if (stateMachine.states.Length==0)
                                    {
EditorGUILayout.HelpBox("no animator state was found.", MessageType.Info);
                                    }
else                                    {
string[] stateNames=newstring[stateMachine.states.Length];
for (inti=0; i<stateNames.Length; i++)
                                        {
stateNames[i] =stateMachine.states[i].state.name;
                                        }
varindex=Array.FindIndex(stateNames, m=>m==animation.stateName);
GUILayout.BeginHorizontal();
GUILayout.Label("State Name", GUILayout.Width(titleWidth));
varnewIndex=EditorGUILayout.Popup(index, stateNames);
if (newIndex!=index)
                                        {
Undo.RecordObject(Target, "Show Animation State Name");
animation.stateName=stateNames[newIndex];
EditorUtility.SetDirty(Target);
                                        }
GUILayout.EndHorizontal();
                                    }
                                }
else                                {
EditorGUILayout.HelpBox("no animator component on this view.", MessageType.Error);
                                }
break;
default:
break;
                        }
break;
caseMenu.UnityEvent:
//OnBeginEvent、OnEndEventEditorGUILayout.PropertyField(onShowBeginEvent);
EditorGUILayout.PropertyField(onShowEndEvent);
break;
default:
break;
                }
            }
//On Hide 折叠栏varnewOnHideFoldout=EditorGUILayout.Foldout(onHideFoldout, "On Invisible", true);
if (newOnHideFoldout!=onHideFoldout)
            {
onHideFoldout=newOnHideFoldout;
EditorPrefs.SetBool(uiViewOnHideFoldout, onHideFoldout);
            }
//Hideif (onHideFoldout)
            {
GUILayout.BeginHorizontal();
Colorcolor=GUI.color;
GUI.color=onHideMenu==Menu.Animation?Color.cyan : color;
if (GUILayout.Button("Animation", "ButtonLeft"))
                {
onHideMenu=Menu.Animation;
                }
GUI.color=onHideMenu==Menu.UnityEvent?Color.cyan : color;
if (GUILayout.Button("Event", "ButtonRight"))
                {
onHideMenu=Menu.UnityEvent;
                }
GUI.color=color;
GUILayout.EndHorizontal();
switch (onHideMenu)
                {
caseMenu.Animation:
//Animation TypeGUILayout.BeginHorizontal();
GUILayout.Label("Mode", GUILayout.Width(titleWidth));
varnewOnHideAnimationType= (UIAnimationType)EditorGUILayout.EnumPopup(onHide.animation.animationType);
if (newOnHideAnimationType!=onHide.animation.animationType)
                        {
Undo.RecordObject(Target, "On Hide Animation Type");
onHide.animation.animationType=newOnHideAnimationType;
                        }
GUILayout.EndHorizontal();
UIAnimationanimation=onHide.animation;
switch (animation.animationType)
                        {
caseUIAnimationType.Tween:
//Move、Rotate、Scale、FadeGUILayout.BeginHorizontal();
                                {
GUI.color=animation.moveToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("MoveTool"), "ButtonLeft", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Hide Animation Move Toggle");
animation.moveToggle=!animation.moveToggle;
onHideMoveAnimBool.target=animation.moveToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.rotateToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("RotateTool"), "ButtonMid", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Hide Animation Rotate Toggle");
animation.rotateToggle=!animation.rotateToggle;
onHideRotateAnimBool.target=animation.rotateToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.scaleToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("ScaleTool"), "ButtonMid", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Hide Animation Scale Toggle");
animation.scaleToggle=!animation.scaleToggle;
onHideScaleAnimBool.target=animation.scaleToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=animation.fadeToggle?color : Color.gray;
if (GUILayout.Button(EditorGUIUtility.IconContent("ViewToolOrbit"), "ButtonRight", GUILayout.Width(25f)))
                                    {
Undo.RecordObject(Target, "On Hide Animation Fade Toggle");
animation.fadeToggle=!animation.fadeToggle;
onHideFadeAnimBool.target=animation.fadeToggle;
EditorUtility.SetDirty(Target);
                                    }
GUI.color=color;
                                }
GUILayout.EndHorizontal();
//MoveAnimationvarmoveAnimation=animation.moveAnimation;
if (EditorGUILayout.BeginFadeGroup(onHideMoveAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(40f);
GUILayout.Label(EditorGUIUtility.IconContent("MoveTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(moveAnimation.duration);
if (newDuration!=moveAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Hide Animation Move Duration");
moveAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(moveAnimation.delay);
if (newDelay!=moveAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Hide Animation Move Delay");
moveAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//FromGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth));
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, moveAnimation.startValue);
if (newStartValue!=moveAnimation.startValue)
                                                {
Undo.RecordObject(Target, "On Hide Animation Move From");
moveAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(moveAnimation.isCustom?"Custom Position" : "Direction", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Direction"), !moveAnimation.isCustom, () => { moveAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Custom Position"), moveAnimation.isCustom, () => { moveAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
if (moveAnimation.isCustom)
                                                {
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, moveAnimation.endValue);
if (newEndValue!=moveAnimation.endValue)
                                                    {
Undo.RecordObject(Target, "On Hide Animation Move End");
moveAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
else                                                {
varnewMoveDirection= (UIMoveAnimationDirection)EditorGUILayout.EnumPopup(moveAnimation.direction);
if (newMoveDirection!=moveAnimation.direction)
                                                    {
Undo.RecordObject(Target, "On Hide Animation Move Direction");
moveAnimation.direction=newMoveDirection;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(moveAnimation.ease);
if (newEase!=moveAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Hide Animation Move Ease");
moveAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//RotateAnimationvarrotateAnimation=animation.rotateAnimation;
if (EditorGUILayout.BeginFadeGroup(onHideRotateAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(rotateAnimation.isCustom?50f : 40f);
GUILayout.Label(EditorGUIUtility.IconContent("RotateTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(rotateAnimation.duration);
if (newDuration!=rotateAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Hide Animation Rotate Duration");
rotateAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(rotateAnimation.delay);
if (newDelay!=rotateAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Hide Animation Rotate Delay");
rotateAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(rotateAnimation.isCustom?"Fixed Rotation" : "Current Rotation", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Rotation"), !rotateAnimation.isCustom, () => { rotateAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Rotation"), rotateAnimation.isCustom, () => { rotateAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (rotateAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, rotateAnimation.startValue);
if (newStartValue!=rotateAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Hide Animation Rotate From");
rotateAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, rotateAnimation.endValue);
if (newEndValue!=rotateAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Hide Animation Rotate To");
rotateAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Rotate ModeGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Mode", GUILayout.Width(labelWidth));
varnewRotateMode= (RotateMode)EditorGUILayout.EnumPopup(rotateAnimation.rotateMode);
if (newRotateMode!=rotateAnimation.rotateMode)
                                                {
Undo.RecordObject(Target, "On Hide Animation Rotate Mode");
rotateAnimation.rotateMode=newRotateMode;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(rotateAnimation.ease);
if (newEase!=rotateAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Hide Animation Rotate Ease");
rotateAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//ScaleAnimationvarscaleAnimation=animation.scaleAnimation;
if (EditorGUILayout.BeginFadeGroup(onHideScaleAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(scaleAnimation.isCustom?40f : 30f);
GUILayout.Label(EditorGUIUtility.IconContent("ScaleTool"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(scaleAnimation.duration);
if (newDuration!=scaleAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Hide Animation Scale Duration");
scaleAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(scaleAnimation.delay);
if (newDelay!=scaleAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Hide Animation Scale Delay");
scaleAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(scaleAnimation.isCustom?"Fixed Scale" : "Current Scale", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Scale"), !scaleAnimation.isCustom, () => { scaleAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Scale"), scaleAnimation.isCustom, () => { scaleAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (scaleAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
Vector3newStartValue=EditorGUILayout.Vector3Field(GUIContent.none, scaleAnimation.startValue);
if (newStartValue!=scaleAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Hide Animation Scale From");
scaleAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
Vector3newEndValue=EditorGUILayout.Vector3Field(GUIContent.none, scaleAnimation.endValue);
if (newEndValue!=scaleAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Hide Animation Scale To");
scaleAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(scaleAnimation.ease);
if (newEase!=scaleAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Hide Animation Scale Ease");
scaleAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
//FadeAnimationvarfadeAnimation=animation.fadeAnimation;
if (EditorGUILayout.BeginFadeGroup(onHideFadeAnimBool.faded))
                                {
GUILayout.BeginHorizontal("Badge");
                                    {
GUILayout.BeginVertical();
                                        {
GUILayout.Space(fadeAnimation.isCustom?40f : 30f);
GUILayout.Label(EditorGUIUtility.IconContent("ViewToolOrbit"));
                                        }
GUILayout.EndVertical();
GUILayout.BeginVertical();
                                        {
//Duration、DelayGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Duration", GUILayout.Width(labelWidth));
varnewDuration=EditorGUILayout.FloatField(fadeAnimation.duration);
if (newDuration!=fadeAnimation.duration)
                                                {
Undo.RecordObject(Target, "On Hide Animation Fade Duration");
fadeAnimation.duration=newDuration;
EditorUtility.SetDirty(Target);
                                                }
GUILayout.Label("Delay", GUILayout.Width(labelWidth-20f));
varnewDelay=EditorGUILayout.FloatField(fadeAnimation.delay);
if (newDelay!=fadeAnimation.delay)
                                                {
Undo.RecordObject(Target, "On Hide Animation Fade Delay");
fadeAnimation.delay=newDelay;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//Is CustomGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("From", GUILayout.Width(labelWidth-2f));
if (GUILayout.Button(fadeAnimation.isCustom?"Fixed Alpha" : "Current Alpha", "DropDownButton"))
                                                {
GenericMenugm=newGenericMenu();
gm.AddItem(newGUIContent("Current Alpha"), !fadeAnimation.isCustom, () => { fadeAnimation.isCustom=false; EditorUtility.SetDirty(Target); });
gm.AddItem(newGUIContent("Fixed Alpha"), fadeAnimation.isCustom, () => { fadeAnimation.isCustom=true; EditorUtility.SetDirty(Target); });
gm.ShowAsContext();
                                                }
                                            }
GUILayout.EndHorizontal();
if (fadeAnimation.isCustom)
                                            {
//FromGUILayout.BeginHorizontal();
                                                {
GUILayout.Label(GUIContent.none, GUILayout.Width(labelWidth));
floatnewStartValue=EditorGUILayout.FloatField(GUIContent.none, fadeAnimation.startValue);
if (newStartValue!=fadeAnimation.startValue)
                                                    {
Undo.RecordObject(Target, "On Hide Animation Fade From");
fadeAnimation.startValue=newStartValue;
EditorUtility.SetDirty(Target);
                                                    }
                                                }
GUILayout.EndHorizontal();
                                            }
//ToGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("To", GUILayout.Width(labelWidth));
floatnewEndValue=EditorGUILayout.FloatField(GUIContent.none, fadeAnimation.endValue);
if (newEndValue!=fadeAnimation.endValue)
                                                {
Undo.RecordObject(Target, "On Hide Animation Fade To");
fadeAnimation.endValue=newEndValue;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
//EaseGUILayout.BeginHorizontal();
                                            {
GUILayout.Label("Ease", GUILayout.Width(labelWidth));
varnewEase= (Ease)EditorGUILayout.EnumPopup(fadeAnimation.ease);
if (newEase!=fadeAnimation.ease)
                                                {
Undo.RecordObject(Target, "On Hide Animation Fade Ease");
fadeAnimation.ease=newEase;
EditorUtility.SetDirty(Target);
                                                }
                                            }
GUILayout.EndHorizontal();
                                        }
GUILayout.EndVertical();
                                    }
GUILayout.EndHorizontal();
                                }
EditorGUILayout.EndFadeGroup();
break;
caseUIAnimationType.Animator:
varanimator=Target.GetComponent<Animator>();
if (animator!=null)
                                {
varanimatorController=animator.runtimeAnimatorControllerasAnimatorController;
varstateMachine=animatorController.layers[0].stateMachine;
if (stateMachine.states.Length==0)
                                    {
EditorGUILayout.HelpBox("no animator state was found.", MessageType.Info);
                                    }
else                                    {
string[] stateNames=newstring[stateMachine.states.Length];
for (inti=0; i<stateNames.Length; i++)
                                        {
stateNames[i] =stateMachine.states[i].state.name;
                                        }
varindex=Array.FindIndex(stateNames, m=>m==animation.stateName);
GUILayout.BeginHorizontal();
GUILayout.Label("State Name", GUILayout.Width(titleWidth));
varnewIndex=EditorGUILayout.Popup(index, stateNames);
if (newIndex!=index)
                                        {
Undo.RecordObject(Target, "Show Animation State Name");
animation.stateName=stateNames[newIndex];
EditorUtility.SetDirty(Target);
                                        }
GUILayout.EndHorizontal();
                                    }
                                }
else                                {
EditorGUILayout.HelpBox("no animator component on this view.", MessageType.Error);
                                }
break;
default:
break;
                        }
break;
caseMenu.UnityEvent:
//OnBeginEvent、OnEndEventEditorGUILayout.PropertyField(onHideBeginEvent);
EditorGUILayout.PropertyField(onHideEndEvent);
break;
default:
break;
                }
            }
serializedObject.ApplyModifiedProperties();
        }
    }
}

image.gif

image.gif

目录
相关文章
|
1月前
|
缓存 API 开发工具
有关Unity使用Rider编辑器无法弹出代码提示的有效解决方法
【11月更文挑战第13天】在 Unity 中使用 Rider 编辑器时,若遇到代码提示无法弹出的问题,可以通过检查 Rider 设置(如自动补全选项、Unity 插件安装、索引设置)、Unity 项目设置(如解决方案正确关联、脚本导入设置)以及环境和依赖关系(如 .NET SDK 版本兼容性、Unity 和 Rider 版本兼容性)等方面进行排查和解决。
|
3月前
|
前端开发 图形学 开发者
【独家揭秘】那些让你的游戏瞬间鲜活起来的Unity UI动画技巧:从零开始打造动态按钮,提升玩家交互体验的绝招大公开!
【9月更文挑战第1天】在游戏开发领域,Unity 是最受欢迎的游戏引擎之一,其强大的跨平台发布能力和丰富的功能集让开发者能够迅速打造出高质量的游戏。优秀的 UI 设计对于游戏至关重要,尤其是在手游市场,出色的 UI 能给玩家留下深刻的第一印象。Unity 的 UGUI 系统提供了一整套解决方案,包括 Canvas、Image 和 Button 等组件,支持添加各种动画效果。
173 3
|
4月前
|
图形学 开发者 存储
超越基础教程:深度拆解Unity地形编辑器的每一个隐藏角落,让你的游戏世界既浩瀚无垠又细节满满——从新手到高手的全面技巧升级秘籍
【8月更文挑战第31天】Unity地形编辑器是游戏开发中的重要工具,可快速创建复杂多变的游戏环境。本文通过比较不同地形编辑技术,详细介绍如何利用其功能构建广阔且精细的游戏世界,并提供具体示例代码,展示从基础地形绘制到植被与纹理添加的全过程。通过学习这些技巧,开发者能显著提升游戏画面质量和玩家体验。
193 3
|
4月前
|
开发者 图形学 开发工具
Unity编辑器神级扩展攻略:从批量操作到定制Inspector界面,手把手教你编写高效开发工具,解锁编辑器隐藏潜能
【8月更文挑战第31天】Unity是一款强大的游戏开发引擎,支持多平台发布与高度可定制的编辑器环境。通过自定义编辑器工具,开发者能显著提升工作效率。本文介绍如何使用C#脚本扩展Unity编辑器功能,包括批量调整游戏对象位置、创建自定义Inspector界面及项目统计窗口等实用工具,并提供具体示例代码。理解并应用这些技巧,可大幅优化开发流程,提高生产力。
440 1
|
4月前
|
开发者 图形学 Java
揭秘Unity物理引擎核心技术:从刚体动力学到关节连接,全方位教你如何在虚拟世界中重现真实物理现象——含实战代码示例与详细解析
【8月更文挑战第31天】Unity物理引擎对于游戏开发至关重要,它能够模拟真实的物理效果,如刚体运动、碰撞检测及关节连接等。通过Rigidbody和Collider组件,开发者可以轻松实现物体间的互动与碰撞。本文通过具体代码示例介绍了如何使用Unity物理引擎实现物体运动、施加力、使用关节连接以及模拟弹簧效果等功能,帮助开发者提升游戏的真实感与沉浸感。
121 1
|
3月前
|
图形学 C++ C#
Unity插件开发全攻略:从零起步教你用C++扩展游戏功能,解锁Unity新玩法的详细步骤与实战技巧大公开
【8月更文挑战第31天】Unity 是一款功能强大的游戏开发引擎,支持多平台发布并拥有丰富的插件生态系统。本文介绍 Unity 插件开发基础,帮助读者从零开始编写自定义插件以扩展其功能。插件通常用 C++ 编写,通过 Mono C# 运行时调用,需在不同平台上编译。文中详细讲解了开发环境搭建、简单插件编写及在 Unity 中调用的方法,包括创建 C# 封装脚本和处理跨平台问题,助力开发者提升游戏开发效率。
300 0
|
4月前
|
开发者 图形学 API
从零起步,深度揭秘:运用Unity引擎及网络编程技术,一步步搭建属于你的实时多人在线对战游戏平台——详尽指南与实战代码解析,带你轻松掌握网络化游戏开发的核心要领与最佳实践路径
【8月更文挑战第31天】构建实时多人对战平台是技术与创意的结合。本文使用成熟的Unity游戏开发引擎,从零开始指导读者搭建简单的实时对战平台。内容涵盖网络架构设计、Unity网络API应用及客户端与服务器通信。首先,创建新项目并选择适合多人游戏的模板,使用推荐的网络传输层。接着,定义基本玩法,如2D多人射击游戏,创建角色预制件并添加Rigidbody2D组件。然后,引入网络身份组件以同步对象状态。通过示例代码展示玩家控制逻辑,包括移动和发射子弹功能。最后,设置服务器端逻辑,处理客户端连接和断开。本文帮助读者掌握构建Unity多人对战平台的核心知识,为进一步开发打下基础。
156 0
|
4月前
|
开发者 图形学 C#
揭秘游戏沉浸感的秘密武器:深度解析Unity中的音频设计技巧,从背景音乐到动态音效,全面提升你的游戏氛围艺术——附实战代码示例与应用场景指导
【8月更文挑战第31天】音频设计在游戏开发中至关重要,不仅能增强沉浸感,还能传递信息,构建氛围。Unity作为跨平台游戏引擎,提供了丰富的音频处理功能,助力开发者轻松实现复杂音效。本文将探讨如何利用Unity的音频设计提升游戏氛围,并通过具体示例代码展示实现过程。例如,在恐怖游戏中,阴森的背景音乐和突然的脚步声能增加紧张感;在休闲游戏中,轻快的旋律则让玩家感到愉悦。
125 0
|
4月前
|
图形学 C#
超实用!深度解析Unity引擎,手把手教你从零开始构建精美的2D平面冒险游戏,涵盖资源导入、角色控制与动画、碰撞检测等核心技巧,打造沉浸式游戏体验完全指南
【8月更文挑战第31天】本文是 Unity 2D 游戏开发的全面指南,手把手教你从零开始构建精美的平面冒险游戏。首先,通过 Unity Hub 创建 2D 项目并导入游戏资源。接着,编写 `PlayerController` 脚本来实现角色移动,并添加动画以增强视觉效果。最后,通过 Collider 2D 组件实现碰撞检测等游戏机制。每一步均展示 Unity 在 2D 游戏开发中的强大功能。
224 6
|
4月前
|
图形学 缓存 算法
掌握这五大绝招,让您的Unity游戏瞬间加载完毕,从此告别漫长等待,大幅提升玩家首次体验的满意度与留存率!
【8月更文挑战第31天】游戏的加载时间是影响玩家初次体验的关键因素,特别是在移动设备上。本文介绍了几种常见的Unity游戏加载优化方法,包括资源的预加载与异步加载、使用AssetBundles管理动态资源、纹理和模型优化、合理利用缓存系统以及脚本优化。通过具体示例代码展示了如何实现异步加载场景,并提出了针对不同资源的优化策略。综合运用这些技术可以显著缩短加载时间,提升玩家满意度。
302 5