CeShi1.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using LitJson;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class CeShi1 : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. public Data_PlayerAttributes dataPA;
  10. private int myrandom;
  11. private List<string> playerID = new List<string>();
  12. private int indexlist;
  13. private List<Data_PlayerAttributes> dataPlayerAttributesList = new List<Data_PlayerAttributes>();
  14. void Start()
  15. {
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. XXX();
  21. }
  22. public void XXX()
  23. {
  24. myrandom = UnityEngine.Random.Range(0, 2); //随机下标
  25. if (myrandom == 0)
  26. {
  27. dataPA = JsonMapper.ToObject<Data_PlayerAttributes>(JsonRead("cel_Label"));
  28. }
  29. else
  30. {
  31. dataPA = JsonMapper.ToObject<Data_PlayerAttributes>(JsonRead("cel_Label 1"));
  32. }
  33. if (!playerID.Contains(dataPA.data.message.data2.id))
  34. {
  35. playerID.Add(dataPA.data.message.data2.id);//得到了两个数字 88888 213123213
  36. dataPlayerAttributesList.Add(dataPA);
  37. }
  38. for (int i = 0; i < dataPlayerAttributesList.Count; i++)
  39. {
  40. if (dataPlayerAttributesList[i].data.message.data2.id.Contains(dataPA.data.message.data2.id))
  41. {
  42. dataPlayerAttributesList[i] = dataPA;
  43. }
  44. Debug.Log(dataPlayerAttributesList[i].data.message.data2.id + " " + i);
  45. }
  46. // Debug.Log(dataPlayerAttributesList.Count);
  47. //for (int i = 0; i < playerID.Count; i++)
  48. //{
  49. // if (playerID[i] == dataPA.data.message.data2.id) //1==data || 2==data
  50. // {
  51. // indexlist = i;
  52. // // dataPlayerAttributesList[indexlist] = dataPA;
  53. // //Debug.Log(playerID[i]+" "+i);
  54. // }
  55. //}
  56. }
  57. public string JsonRead(string name)
  58. {
  59. string json = "";
  60. TextAsset text = Resources.Load<TextAsset>("Jsons/" + name);
  61. json = text.text;
  62. if (string.IsNullOrEmpty(json)) return null;
  63. return json;
  64. }
  65. }