InitTapList.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using static GameManager;
  6. using System.Reflection;
  7. using System;
  8. public class InitTapList : MonoBehaviour
  9. {
  10. public bool isPose=true;
  11. public GameObjectType type;
  12. public GameObject go;
  13. public List<TapName> taplist;
  14. List<GameObject> golist=new List<GameObject>();
  15. private void Awake() {
  16. StartCoroutine(Finder());
  17. }
  18. IEnumerator Finder()
  19. {
  20. yield return null;
  21. go.SetActive(false);
  22. for (int i = 0;i<taplist.Count;i++)
  23. {
  24. GameObject fz =GameObject.Instantiate(go,go.transform.parent);
  25. fz.SetActive(true);
  26. yield return null;
  27. if(i==0)
  28. {
  29. fz.GetComponent<Toggle>().isOn=true;
  30. }
  31. fz.GetComponentInChildren<Text>().text=GetChineseDescription(taplist[i]);
  32. fz.GetComponent<CameraToPose>().init(type,taplist[i]);
  33. yield return FinderObj(taplist[i],fz);
  34. }
  35. yield return null;
  36. golist[0].GetComponent<Toggle>().isOn=true;
  37. }
  38. IEnumerator FinderObj(TapName tn,GameObject fz)
  39. {
  40. GameObject findgo=null;
  41. if(isPose)
  42. {
  43. while(!findgo)
  44. {
  45. findgo =GameObject.Find(GetChineseDescription(type)+"_"+GetChineseDescription(tn));
  46. yield return null;
  47. }
  48. }
  49. fz.GetComponent<CameraToPose>().go =findgo;
  50. fz.name = GetChineseDescription(type)+"_"+GetChineseDescription(tn);
  51. golist.Add(fz) ;
  52. yield return null;
  53. }
  54. public static string GetChineseDescription(Enum value)
  55. {
  56. FieldInfo field = value.GetType().GetField(value.ToString());
  57. ChineseDescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(ChineseDescriptionAttribute)) as ChineseDescriptionAttribute;
  58. return attribute == null ? value.ToString() : attribute.Description;
  59. }
  60. private void OnEnable() {
  61. }
  62. [AttributeUsage(AttributeTargets.Field)]
  63. public class ChineseDescriptionAttribute : Attribute
  64. {
  65. public string Description { get; private set; }
  66. public ChineseDescriptionAttribute(string description)
  67. {
  68. Description = description;
  69. }
  70. }
  71. }