| //-------------------------------------------------------- | 
| //    [Author]:           玩个游戏 | 
| //    [  Date ]:           Tuesday, October 31, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using UnityEngine.EventSystems; | 
|   | 
| using System; | 
|   | 
|   | 
| //关联按钮,其中一个亮起,其他按下,文字颜色对应变更 | 
| //数据更新通过SelectBtn更新 或者 GroupButtonExManager.SelectButton | 
| //使用步骤 1.序列化GroupButtonEx类型的按钮,2:初始需设置SelectBtn()选中哪个按钮,其他和按钮使用方法一致 | 
| public class GroupButtonEx : ButtonEx | 
| { | 
|     [SerializeField] GroupButtonExManager m_Manager; // 按钮组管理器引用 | 
|     public GroupButtonExManager manager | 
|     { | 
|         get { return m_Manager; } | 
|         set | 
|         { | 
|             if (m_Manager != value) | 
|             { | 
|                 // 从旧管理器移除并添加到新管理器 | 
|                 if (m_Manager != null) | 
|                 { | 
|                     m_Manager.RemoveButton(this); | 
|                 } | 
|   | 
|                 m_Manager = value; | 
|   | 
|                 if (m_Manager != null) | 
|                 { | 
|                     m_Manager.AddButton(this); | 
|                 } | 
|             } | 
|         } | 
|     } | 
|   | 
|     [NonSerialized] TitleBtnState m_State = TitleBtnState.Normal; | 
|     public TitleBtnState state | 
|     { | 
|         get { return m_State; } | 
|         set | 
|         { | 
|             if (m_State != value) | 
|             { | 
|                 m_State = value; | 
|             } | 
|         } | 
|     } | 
|   | 
|     [SerializeField] ImageEx m_SelectIcon; | 
|     public ImageEx selectIcon | 
|     { | 
|         get { return this.m_SelectIcon; } | 
|         set { this.m_SelectIcon = value; } | 
|     } | 
|   | 
|     [SerializeField] ImageEx m_UnSelectIcon; | 
|     public ImageEx unSelectIcon | 
|     { | 
|         get { return this.m_UnSelectIcon; } | 
|         set { this.m_UnSelectIcon = value; } | 
|     } | 
|   | 
|     [SerializeField] TextEx m_Title; | 
|     public TextEx title | 
|     { | 
|         get { return this.m_Title; } | 
|         set { this.m_Title = value; } | 
|     } | 
|   | 
|     [SerializeField] UIEffectPlayer m_SelectEffect;  //选中特效 | 
|     public UIEffectPlayer selectEffect | 
|     { | 
|         get { return m_SelectEffect; } | 
|         set { m_SelectEffect = value; } | 
|     } | 
|   | 
|     public bool isLock = false; | 
|   | 
|     protected override void Awake() | 
|     { | 
|         base.Awake(); | 
|         // 确保已添加到管理器 | 
|         if (m_Manager != null) | 
|         { | 
|             m_Manager.AddButton(this); | 
|         } | 
|     } | 
|   | 
|     protected override void OnDestroy() | 
|     { | 
|         if (m_Manager != null) | 
|         { | 
|             m_Manager.RemoveButton(this); | 
|         } | 
|         base.OnDestroy(); | 
|     } | 
|   | 
|     public override void OnPointerClick(PointerEventData eventData) | 
|     { | 
|         if (isLock) | 
|             return; | 
|         base.OnPointerClick(eventData); | 
|         SelectBtn(); | 
|     } | 
|   | 
|     // 选中当前按钮,只处理刷新显示 | 
|     public void SelectBtn(bool forceRefresh = false) | 
|     { | 
|         if (m_State == TitleBtnState.Click && !forceRefresh) | 
|             return; | 
|   | 
|         // 通过管理器处理选中逻辑 | 
|         if (m_Manager != null) | 
|         { | 
|             m_Manager.SelectButton(this); | 
|         } | 
|   | 
|     } | 
|   | 
|     // 更新按钮状态 | 
|     public void UpdateButtonState() | 
|     { | 
|         // 更新图标显示 | 
|         if (m_SelectIcon != null) | 
|             m_SelectIcon.SetActive(m_State == TitleBtnState.Click); | 
|   | 
|         if (m_UnSelectIcon != null) | 
|             m_UnSelectIcon.SetActive(m_State != TitleBtnState.Click); | 
|   | 
|         // 更新文字颜色 | 
|         if (m_Title != null && m_Manager != null) | 
|         { | 
|             m_Title.color = m_Manager.GetTextColorForState(m_State); | 
|         } | 
|   | 
|         if (m_SelectEffect != null) | 
|         { | 
|             if (m_State == TitleBtnState.Click) | 
|             { | 
|                 //选中,显示特效 | 
|                 m_SelectEffect.Play(); | 
|             } | 
|             else | 
|             { | 
|                 m_SelectEffect.Stop(); | 
|             } | 
|         } | 
|     } | 
| } |