12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class ButtonUtil
- {
- public static void TabSelected(GameObject btn, Transform container)
- {
- int count = container.childCount;
- for(int i=0; i<count; i++)
- {
- GameObject child = container.GetChild (i).gameObject;
- if (child == btn) {
- Selected (child);
- } else {
- Unselect (child);
- }
- }
- }
- public static void TabSelected(SelectItemRenderer item, Transform container)
- {
- int count = container.childCount;
- for(int i=0; i<count; i++)
- {
- SelectItemRenderer renderer = container.GetChild (i).GetComponent<SelectItemRenderer>();
- renderer.selected = (renderer == item);
- }
- }
- public static void TabSelected(int index, Transform container)
- {
- int count = container.childCount;
- for(int i=0; i<count; i++)
- {
- GameObject child = container.GetChild (i).gameObject;
- if (i == index) {
- Selected (child);
- } else {
- Unselect (child);
- }
- }
- }
- public static void Selected(GameObject btn)
- {
- Color color = Color.white;
- Image img = btn.GetComponent<Image> ();
- if(img != null)
- {
- color = img.color;
- color.a = 1f;
- img.color = color;
- }
- Text[] txtArr = btn.GetComponentsInChildren<Text> ();
- for(int i=0; i<txtArr.Length; i++)
- {
- Text txt = txtArr [i];
- color = txt.color;
- color.a = 1f;
- txt.color = color;
- }
- }
- public static void Unselect(GameObject btn)
- {
- float alpha = 96f / 255f;
- Color color = Color.white;
- Image img = btn.GetComponent<Image> ();
- if(img != null)
- {
- color = img.color;
- color.a = alpha;
- img.color = color;
- }
- Image[] imgArr = btn.GetComponentsInChildren<Image> ();
- for(int i=0; i<imgArr.Length; i++)
- {
- color = img.color;
- color.a = alpha;
- img.color = color;
- }
- Text[] txtArr = btn.GetComponentsInChildren<Text> ();
- for(int i=0; i<txtArr.Length; i++)
- {
- Text txt = txtArr [i];
- color = txt.color;
- color.a = alpha;
- txt.color = color;
- }
- }
- }
|