fix&&feature
This commit is contained in:
parent
ded05d1a23
commit
db5faf5f7d
@ -30,9 +30,13 @@ public class UXButtonEditor : Editor
|
|||||||
private Dictionary<int, bool> m_ChildTransitionFoldouts = new Dictionary<int, bool>();
|
private Dictionary<int, bool> m_ChildTransitionFoldouts = new Dictionary<int, bool>();
|
||||||
private UXGroup group;
|
private UXGroup group;
|
||||||
private int m_ButtonMode;
|
private int m_ButtonMode;
|
||||||
|
private SerializedProperty m_SelectionState;
|
||||||
|
private UXButton mTarget;
|
||||||
|
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
|
mTarget = target as UXButton;
|
||||||
m_Interactable = serializedObject.FindProperty("m_Interactable");
|
m_Interactable = serializedObject.FindProperty("m_Interactable");
|
||||||
m_UXGroup = serializedObject.FindProperty("m_UXGroup");
|
m_UXGroup = serializedObject.FindProperty("m_UXGroup");
|
||||||
m_Mode = serializedObject.FindProperty("m_Mode");
|
m_Mode = serializedObject.FindProperty("m_Mode");
|
||||||
@ -41,6 +45,7 @@ public class UXButtonEditor : Editor
|
|||||||
m_TransitionData = serializedObject.FindProperty("m_TransitionData");
|
m_TransitionData = serializedObject.FindProperty("m_TransitionData");
|
||||||
m_ChildTransitions = serializedObject.FindProperty("m_ChildTransitions");
|
m_ChildTransitions = serializedObject.FindProperty("m_ChildTransitions");
|
||||||
m_ButtonUISounds = serializedObject.FindProperty("m_ButtonUISounds");
|
m_ButtonUISounds = serializedObject.FindProperty("m_ButtonUISounds");
|
||||||
|
m_SelectionState = serializedObject.FindProperty("m_SelectionState");
|
||||||
m_ChildTransitionFoldouts.Clear();
|
m_ChildTransitionFoldouts.Clear();
|
||||||
group = (UXGroup)m_UXGroup.objectReferenceValue;
|
group = (UXGroup)m_UXGroup.objectReferenceValue;
|
||||||
m_ButtonMode = m_Mode.enumValueIndex;
|
m_ButtonMode = m_Mode.enumValueIndex;
|
||||||
@ -53,6 +58,7 @@ public class UXButtonEditor : Editor
|
|||||||
calls.arraySize = 0;
|
calls.arraySize = 0;
|
||||||
property.serializedObject.ApplyModifiedProperties();
|
property.serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
@ -194,7 +200,7 @@ public class UXButtonEditor : Editor
|
|||||||
SerializedProperty transition = transitionData.FindPropertyRelative("transition");
|
SerializedProperty transition = transitionData.FindPropertyRelative("transition");
|
||||||
SerializedProperty colorBlock = transitionData.FindPropertyRelative("colors");
|
SerializedProperty colorBlock = transitionData.FindPropertyRelative("colors");
|
||||||
SerializedProperty spriteState = transitionData.FindPropertyRelative("spriteState");
|
SerializedProperty spriteState = transitionData.FindPropertyRelative("spriteState");
|
||||||
|
SerializedProperty animationTriggers = transitionData.FindPropertyRelative("animationTriggers");
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
|
|
||||||
// 绘制目标图形
|
// 绘制目标图形
|
||||||
@ -206,8 +212,12 @@ public class UXButtonEditor : Editor
|
|||||||
// 绘制transition类型
|
// 绘制transition类型
|
||||||
EditorGUILayout.PropertyField(transition);
|
EditorGUILayout.PropertyField(transition);
|
||||||
|
|
||||||
|
|
||||||
// 显示警告信息
|
// 显示警告信息
|
||||||
var graphic = targetGraphic.objectReferenceValue as Graphic;
|
var graphic = targetGraphic.objectReferenceValue as Graphic;
|
||||||
|
var animation = graphic.GetComponent<Animation>();
|
||||||
|
|
||||||
|
|
||||||
switch (currentTransition)
|
switch (currentTransition)
|
||||||
{
|
{
|
||||||
case Selectable.Transition.ColorTint:
|
case Selectable.Transition.ColorTint:
|
||||||
@ -219,6 +229,10 @@ public class UXButtonEditor : Editor
|
|||||||
if (!(graphic is Image))
|
if (!(graphic is Image))
|
||||||
EditorGUILayout.HelpBox("需要Image组件来使用精灵切换", MessageType.Warning);
|
EditorGUILayout.HelpBox("需要Image组件来使用精灵切换", MessageType.Warning);
|
||||||
break;
|
break;
|
||||||
|
case Selectable.Transition.Animation:
|
||||||
|
if (animation == null)
|
||||||
|
EditorGUILayout.HelpBox("需要Animation || Animator组件来使用动画切换", MessageType.Warning);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制对应类型的属性
|
// 绘制对应类型的属性
|
||||||
@ -232,6 +246,15 @@ public class UXButtonEditor : Editor
|
|||||||
case Selectable.Transition.SpriteSwap:
|
case Selectable.Transition.SpriteSwap:
|
||||||
EditorGUILayout.PropertyField(spriteState);
|
EditorGUILayout.PropertyField(spriteState);
|
||||||
break;
|
break;
|
||||||
|
case Selectable.Transition.Animation:
|
||||||
|
EditorGUILayout.PropertyField(animationTriggers);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((int)currentTransition != transition.enumValueIndex)
|
||||||
|
{
|
||||||
|
graphic.canvasRenderer.SetColor(graphic.color);
|
||||||
|
graphic.color = graphic.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
@ -279,6 +302,11 @@ public class UXButtonEditor : Editor
|
|||||||
Color color = colorBlock.FindPropertyRelative("m_NormalColor").colorValue;
|
Color color = colorBlock.FindPropertyRelative("m_NormalColor").colorValue;
|
||||||
graphic.canvasRenderer.SetColor(color);
|
graphic.canvasRenderer.SetColor(color);
|
||||||
}
|
}
|
||||||
|
else if (m_SelectionState.enumValueIndex == 0)
|
||||||
|
{
|
||||||
|
Color color = colorBlock.FindPropertyRelative("m_NormalColor").colorValue;
|
||||||
|
graphic.canvasRenderer.SetColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public class TransitionData
|
|||||||
public Selectable.Transition transition = Selectable.Transition.ColorTint;
|
public Selectable.Transition transition = Selectable.Transition.ColorTint;
|
||||||
public ColorBlock colors;
|
public ColorBlock colors;
|
||||||
public SpriteState spriteState;
|
public SpriteState spriteState;
|
||||||
|
public AnimationTriggers animationTriggers = new AnimationTriggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -82,12 +83,21 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
[SerializeField] private UXGroup m_UXGroup;
|
[SerializeField] private UXGroup m_UXGroup;
|
||||||
|
|
||||||
[SerializeField] private List<ButtonSoundCell> m_ButtonUISounds = new List<ButtonSoundCell>();
|
[SerializeField] private List<ButtonSoundCell> m_ButtonUISounds = new List<ButtonSoundCell>();
|
||||||
|
[SerializeField] private SelectionState m_SelectionState = SelectionState.Normal;
|
||||||
private SelectionState m_SelectionState = SelectionState.Normal;
|
|
||||||
private bool m_DownAndExistUI;
|
private bool m_DownAndExistUI;
|
||||||
private bool m_IsDown;
|
private bool m_IsDown;
|
||||||
private bool m_IsTogSelected;
|
private bool m_IsTogSelected;
|
||||||
|
|
||||||
|
private Animator _animator;
|
||||||
|
|
||||||
|
internal Animator animator
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_animator = _animator ?? GetComponent<Animator>();
|
||||||
|
return _animator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsSelected
|
public bool IsSelected
|
||||||
{
|
{
|
||||||
@ -122,7 +132,8 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
{
|
{
|
||||||
onValueChanged?.Invoke(IsSelected);
|
onValueChanged?.Invoke(IsSelected);
|
||||||
}
|
}
|
||||||
UpdateVisualState(m_SelectionState,true);
|
|
||||||
|
UpdateVisualState(m_SelectionState, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -239,31 +250,38 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
|
|
||||||
Color tintColor;
|
Color tintColor;
|
||||||
Sprite transitionSprite;
|
Sprite transitionSprite;
|
||||||
|
string triggerName;
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case SelectionState.Normal:
|
case SelectionState.Normal:
|
||||||
tintColor = transition.colors.normalColor;
|
tintColor = transition.colors.normalColor;
|
||||||
transitionSprite = null;
|
transitionSprite = null;
|
||||||
|
triggerName = transition.animationTriggers.normalTrigger;
|
||||||
break;
|
break;
|
||||||
case SelectionState.Highlighted:
|
case SelectionState.Highlighted:
|
||||||
tintColor = transition.colors.highlightedColor;
|
tintColor = transition.colors.highlightedColor;
|
||||||
transitionSprite = transition.spriteState.highlightedSprite;
|
transitionSprite = transition.spriteState.highlightedSprite;
|
||||||
|
triggerName = transition.animationTriggers.highlightedTrigger;
|
||||||
break;
|
break;
|
||||||
case SelectionState.Pressed:
|
case SelectionState.Pressed:
|
||||||
tintColor = transition.colors.pressedColor;
|
tintColor = transition.colors.pressedColor;
|
||||||
transitionSprite = transition.spriteState.pressedSprite;
|
transitionSprite = transition.spriteState.pressedSprite;
|
||||||
|
triggerName = transition.animationTriggers.pressedTrigger;
|
||||||
break;
|
break;
|
||||||
case SelectionState.Selected:
|
case SelectionState.Selected:
|
||||||
tintColor = transition.colors.selectedColor;
|
tintColor = transition.colors.selectedColor;
|
||||||
transitionSprite = transition.spriteState.selectedSprite;
|
transitionSprite = transition.spriteState.selectedSprite;
|
||||||
|
triggerName = transition.animationTriggers.selectedTrigger;
|
||||||
break;
|
break;
|
||||||
case SelectionState.Disabled:
|
case SelectionState.Disabled:
|
||||||
tintColor = transition.colors.disabledColor;
|
tintColor = transition.colors.disabledColor;
|
||||||
transitionSprite = transition.spriteState.disabledSprite;
|
transitionSprite = transition.spriteState.disabledSprite;
|
||||||
|
triggerName = transition.animationTriggers.disabledTrigger;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
tintColor = Color.black;
|
tintColor = Color.black;
|
||||||
transitionSprite = null;
|
transitionSprite = null;
|
||||||
|
triggerName = string.Empty;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +293,9 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
case Selectable.Transition.SpriteSwap:
|
case Selectable.Transition.SpriteSwap:
|
||||||
DoSpriteSwap(transition, transitionSprite);
|
DoSpriteSwap(transition, transitionSprite);
|
||||||
break;
|
break;
|
||||||
|
case Selectable.Transition.Animation:
|
||||||
|
TriggerAnimation(transition.animationTriggers, triggerName);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,6 +323,20 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TriggerAnimation(AnimationTriggers animationTriggers, string triggername)
|
||||||
|
{
|
||||||
|
if (animator == null || !animator.isActiveAndEnabled || !animator.hasBoundPlayables || string.IsNullOrEmpty(triggername))
|
||||||
|
return;
|
||||||
|
|
||||||
|
animator.ResetTrigger(animationTriggers.normalTrigger);
|
||||||
|
animator.ResetTrigger(animationTriggers.highlightedTrigger);
|
||||||
|
animator.ResetTrigger(animationTriggers.pressedTrigger);
|
||||||
|
animator.ResetTrigger(animationTriggers.selectedTrigger);
|
||||||
|
animator.ResetTrigger(animationTriggers.disabledTrigger);
|
||||||
|
|
||||||
|
animator.SetTrigger(triggername);
|
||||||
|
}
|
||||||
|
|
||||||
protected void PlayButtonSound(ButtonSoundType buttonSoundType)
|
protected void PlayButtonSound(ButtonSoundType buttonSoundType)
|
||||||
{
|
{
|
||||||
ButtonSoundCell buttonSound = GetButtonSound(buttonSoundType);
|
ButtonSoundCell buttonSound = GetButtonSound(buttonSoundType);
|
||||||
|
Loading…
Reference in New Issue
Block a user