123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SelectButtonCtrl : MonoBehaviour
- {
- public void Awake()
- {
- if (this.Panel == null)
- {
- this.Panel = base.transform.parent.gameObject.GetComponent<UIPanel>();
- }
- }
- public void CreateSelectButtons(List<KeyValuePair<string, KeyValuePair<string, bool>>> listSelectBtn, Action<string, string> onClickCallBack, UnityEngine.Object selectBtnPrefab)
- {
- this.m_OnClickCallBack = null;
- this.m_OnClickCallEvent = null;
- this.ClearExistSelectButton();
- this.m_OnClickCallBack = onClickCallBack;
- this.m_listSelectBtn = new List<KeyValuePair<string, SelectButtonCtrl.SelectButton>>();
- int num = 0;
- foreach (KeyValuePair<string, KeyValuePair<string, bool>> keyValuePair in listSelectBtn)
- {
- GameObject gameObject = UnityEngine.Object.Instantiate(selectBtnPrefab) as GameObject;
- UIButton component = gameObject.GetComponent<UIButton>();
- EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.ClickSelectButton));
- gameObject.name = "selectButton_" + num;
- gameObject.transform.parent = base.transform;
- gameObject.transform.localScale = Vector3.one;
- gameObject.transform.localPosition = Vector3.zero;
- gameObject.transform.rotation = Quaternion.identity;
- EventDelegate.Set(gameObject.GetComponent<TweenAlpha>().onFinished, new EventDelegate.Callback(this.OnFinished));
- UILabel component2 = UTY.GetChildObject(gameObject, "Option", false).GetComponent<UILabel>();
- component2.text = keyValuePair.Key;
- SelectButtonCtrl.SelectButton selectButton = new SelectButtonCtrl.SelectButton();
- selectButton.m_btnName = gameObject.name;
- selectButton.m_goSelectBtn = gameObject;
- selectButton.m_msg = keyValuePair.Key;
- selectButton.m_tag = keyValuePair.Value.Key;
- component.isEnabled = keyValuePair.Value.Value;
- this.m_listSelectBtn.Add(new KeyValuePair<string, SelectButtonCtrl.SelectButton>(selectButton.m_btnName, selectButton));
- num++;
- }
- base.GetComponent<UIGrid>().Reposition();
- this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
- }
- public void SetPanelAlpha(float value)
- {
- this.Awake();
- this.Panel.alpha = value;
- }
- public bool IsPlayingEffect()
- {
- return this.m_EffectStat != SelectButtonCtrl.EffectStat.Null;
- }
- public void ClearExistSelectButton()
- {
- IEnumerator enumerator = base.transform.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- Transform transform = (Transform)obj;
- UnityEngine.Object.Destroy(transform.gameObject);
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- }
- public void ClickSelectButton()
- {
- string b = string.Empty;
- b = UIButton.current.name;
- foreach (KeyValuePair<string, SelectButtonCtrl.SelectButton> keyValuePair in this.m_listSelectBtn)
- {
- GameObject goSelectBtn = keyValuePair.Value.m_goSelectBtn;
- if (keyValuePair.Key == b)
- {
- if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
- {
- TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
- }
- else
- {
- TweenAlpha.Begin(keyValuePair.Value.m_goSelectBtn, 1f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
- }
- if (this.m_OnClickCallBack != null)
- {
- string text = keyValuePair.Value.m_msg;
- string tag = keyValuePair.Value.m_tag;
- Action<string, string> tmp = this.m_OnClickCallBack;
- this.m_OnClickCallEvent = delegate
- {
- tmp(text, tag);
- };
- this.m_OnClickCallBack = null;
- }
- }
- else
- {
- goSelectBtn.GetComponent<TweenAlpha>().onFinished = null;
- if (GameMain.Instance.ScriptMgr.adv_kag.skip_mode)
- {
- TweenAlpha.Begin(goSelectBtn, 0.01f, 0f);
- }
- else
- {
- TweenAlpha.Begin(goSelectBtn, 0.3f * GameMain.Instance.CMSystem.FadeSpeedRate, 0f);
- }
- }
- goSelectBtn.GetComponent<BoxCollider>().enabled = false;
- }
- this.m_EffectStat = SelectButtonCtrl.EffectStat.EndOut;
- }
- private void OnFinished()
- {
- if (this.dragMat == null)
- {
- this.dragMat = base.transform.parent.parent.Find("DragMat").gameObject;
- }
- this.dragMat.SetActive(false);
- this.ClearExistSelectButton();
- base.transform.parent.GetComponent<UIScrollView>().ResetPosition();
- this.m_EffectStat = SelectButtonCtrl.EffectStat.Null;
- if (this.m_OnClickCallEvent != null)
- {
- this.m_OnClickCallEvent();
- }
- this.m_OnClickCallEvent = null;
- }
- [SerializeField]
- private GameObject dragMat;
- private UIPanel Panel;
- private List<KeyValuePair<string, SelectButtonCtrl.SelectButton>> m_listSelectBtn;
- private Action<string, string> m_OnClickCallBack;
- private Action m_OnClickCallEvent;
- private SelectButtonCtrl.EffectStat m_EffectStat;
- private enum EffectStat
- {
- Null,
- StartIn,
- EndOut
- }
- private class SelectButton
- {
- public string m_btnName { get; set; }
- public string m_msg { get; set; }
- public string m_tag { get; set; }
- public GameObject m_goSelectBtn { get; set; }
- public override string ToString()
- {
- return string.Format("SelectButton=[m_btnName={0}, m_msg={1}, m_tag={2}, m_goSelectBtn={3}]", new object[]
- {
- this.m_btnName,
- this.m_msg,
- this.m_tag,
- this.m_goSelectBtn
- });
- }
- }
- }
|