12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using static GameManager;
- using System.Reflection;
- using System;
- public class InitTapList : MonoBehaviour
- {
- public bool isPose=true;
- public GameObjectType type;
- public GameObject go;
- public List<TapName> taplist;
-
- List<GameObject> golist=new List<GameObject>();
- private void Awake() {
- StartCoroutine(Finder());
- }
- IEnumerator Finder()
- {
- yield return null;
- go.SetActive(false);
- for (int i = 0;i<taplist.Count;i++)
- {
- GameObject fz =GameObject.Instantiate(go,go.transform.parent);
-
- fz.SetActive(true);
- yield return null;
- if(i==0)
- {
- fz.GetComponent<Toggle>().isOn=true;
- }
- fz.GetComponentInChildren<Text>().text=GetChineseDescription(taplist[i]);
- fz.GetComponent<CameraToPose>().init(type,taplist[i]);
- yield return FinderObj(taplist[i],fz);
- }
- yield return null;
- golist[0].GetComponent<Toggle>().isOn=true;
- }
- IEnumerator FinderObj(TapName tn,GameObject fz)
- {
- GameObject findgo=null;
- if(isPose)
- {
- while(!findgo)
- {
- findgo =GameObject.Find(GetChineseDescription(type)+"_"+GetChineseDescription(tn));
- yield return null;
- }
- }
- fz.GetComponent<CameraToPose>().go =findgo;
- fz.name = GetChineseDescription(type)+"_"+GetChineseDescription(tn);
- golist.Add(fz) ;
- yield return null;
-
- }
-
- public static string GetChineseDescription(Enum value)
- {
- FieldInfo field = value.GetType().GetField(value.ToString());
- ChineseDescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(ChineseDescriptionAttribute)) as ChineseDescriptionAttribute;
- return attribute == null ? value.ToString() : attribute.Description;
- }
- private void OnEnable() {
- }
-
- [AttributeUsage(AttributeTargets.Field)]
- public class ChineseDescriptionAttribute : Attribute
- {
- public string Description { get; private set; }
-
- public ChineseDescriptionAttribute(string description)
- {
- Description = description;
- }
- }
- }
|