TenExtract.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LitJson;
  5. using System.IO;
  6. using UnityEngine.UI;
  7. using static UnityEditor.Progress;
  8. public class TenExtract : MonoBehaviour
  9. {
  10. private List<TalentsItem> talentsItemList = new List<TalentsItem>();
  11. private List<TalentsItem> currentItemList = new List<TalentsItem>();
  12. public List<Toggle> toggleList = new List<Toggle>();
  13. public List<Text> labelList = new List<Text>();
  14. public Button selectBtn;
  15. public GameObject Adjust_Panel;
  16. void Start()
  17. {
  18. string filePath = "Assets/Data/myTalent.json";
  19. if (File.Exists(filePath))
  20. {
  21. string dataAsJson = File.ReadAllText(filePath);
  22. TalentsData talentsData = JsonMapper.ToObject<TalentsData>(dataAsJson);
  23. foreach (var item in talentsData.talents)
  24. {
  25. talentsItemList.Add(item);
  26. }
  27. }
  28. for (int i = 0; i < 10; i++)
  29. {
  30. int index = Random.Range(0, talentsItemList.Count);
  31. currentItemList.Add(talentsItemList[index]);
  32. talentsItemList.Remove(talentsItemList[index]);
  33. }
  34. foreach (var item in toggleList)
  35. {
  36. labelList.Add(item.transform.GetChild(1).GetComponent<Text>());
  37. }
  38. for (int i = 0; i < labelList.Count; i++)
  39. {
  40. labelList[i].text = currentItemList[i].name + "(" + currentItemList[i].description + ")";
  41. }
  42. selectBtn.onClick.AddListener(() =>
  43. {
  44. PlayerData.intance.currentItemTalentList.Clear();
  45. int m = 0;
  46. for (int i = 0; i < toggleList.Count; i++)
  47. {
  48. if (toggleList[i].isOn == true) m++;
  49. }
  50. if (m != 3)
  51. {
  52. Debug.Log("ÇëÑ¡ÔñÈý¸öÌ츳£¡");
  53. return;
  54. }
  55. for (int i = 0;i<toggleList.Count;i++)
  56. {
  57. if (toggleList[i].isOn == true)
  58. {
  59. PlayerData.intance.currentItemTalentList.Add(currentItemList[i]);
  60. }
  61. }
  62. Adjust_Panel.SetActive(true);
  63. });
  64. }
  65. void Update()
  66. {
  67. }
  68. }