123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class UIWFSwitchPanel : MonoBehaviour
- {
- public void Start()
- {
- if (this.onclick_event_ != null)
- {
- return;
- }
- this.SetNumberOfSelected(this.NumberOfSelected);
- this.UpdateChildren();
- }
- public void SetNumberOfSelected(int num)
- {
- this.NumberOfSelected = num;
- this.select_button_list_ = new UIWFSelectButton[num];
- }
- public void UpdateChildren()
- {
- if (!base.enabled)
- {
- return;
- }
- if (this.select_button_list_ == null)
- {
- this.SetNumberOfSelected(this.NumberOfSelected);
- }
- if (this.onclick_event_ == null)
- {
- this.onclick_event_ = new EventDelegate(this, "OnClick");
- }
- for (int i = 0; i < this.select_button_list_.Length; i++)
- {
- this.select_button_list_[i] = null;
- }
- this.button_list_.Clear();
- Transform transform = base.transform;
- for (int j = 0; j < transform.childCount; j++)
- {
- UIWFSelectButton componentInChildren = transform.GetChild(j).GetComponentInChildren<UIWFSelectButton>();
- if (componentInChildren != null)
- {
- this.button_list_.Add(componentInChildren);
- if (!this.event_add_object_hash_list_.Contains(componentInChildren.GetHashCode()))
- {
- componentInChildren.onClick.Add(this.onclick_event_);
- this.event_add_object_hash_list_.Add(componentInChildren.GetHashCode());
- }
- }
- }
- }
- public void SelectAll()
- {
- Transform transform = base.transform;
- for (int i = 0; i < transform.childCount; i++)
- {
- UIWFSelectButton componentInChildren = transform.GetChild(i).GetComponentInChildren<UIWFSelectButton>();
- if (componentInChildren != null && !componentInChildren.isSelected)
- {
- this.Select(componentInChildren);
- }
- }
- }
- public void SelectAllRelease()
- {
- Transform transform = base.transform;
- for (int i = 0; i < transform.childCount; i++)
- {
- UIWFSelectButton componentInChildren = transform.GetChild(i).GetComponentInChildren<UIWFSelectButton>();
- if (componentInChildren != null && componentInChildren.isSelected)
- {
- this.Select(componentInChildren);
- }
- }
- }
- public void Select(UIWFSelectButton button)
- {
- if (!base.enabled)
- {
- return;
- }
- UIWFSelectButton.current = button;
- UIButton.current = button;
- EventDelegate.Execute(button.onClick);
- UIWFSelectButton.current = null;
- UIButton.current = null;
- }
- public UIWFSelectButton[] select_button_list
- {
- get
- {
- return this.select_button_list_;
- }
- }
- public void OnClick()
- {
- if (!base.enabled)
- {
- return;
- }
- if (UIWFSelectButton.current.isSelected)
- {
- for (int i = 0; i < this.select_button_list_.Length; i++)
- {
- if (this.select_button_list_[i] == UIWFSelectButton.current)
- {
- this.select_button_list_[i] = null;
- UIWFSelectButton.current.SetSelect(false);
- break;
- }
- }
- }
- else
- {
- for (int j = 0; j < this.select_button_list_.Length; j++)
- {
- if (this.select_button_list_[j] == null)
- {
- this.select_button_list_[j] = UIWFSelectButton.current;
- UIWFSelectButton.current.SetSelect(true);
- break;
- }
- }
- }
- bool flag = true;
- for (int k = 0; k < this.select_button_list_.Length; k++)
- {
- if (this.select_button_list_[k] == null)
- {
- flag = false;
- break;
- }
- }
- if (flag)
- {
- for (int l = 0; l < this.button_list_.Count; l++)
- {
- if (!this.button_list_[l].isSelected)
- {
- this.button_list_[l].isEnabled = false;
- }
- }
- }
- else
- {
- for (int m = 0; m < this.button_list_.Count; m++)
- {
- if (!this.button_list_[m].isSelected && !this.button_list_[m].isEnabled)
- {
- this.button_list_[m].isEnabled = true;
- }
- }
- }
- }
- public int NumberOfSelected = 1;
- private List<UIWFSelectButton> button_list_ = new List<UIWFSelectButton>();
- private EventDelegate onclick_event_;
- private HashSet<int> event_add_object_hash_list_ = new HashSet<int>();
- private UIWFSelectButton[] select_button_list_;
- }
|