Servermanager.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Newtonsoft.Json;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// 模拟刀片机数据生成
  7. /// </summary>
  8. public class Servermanager : MonoSingleton<Servermanager>
  9. {
  10. public List<ServerData> listDataItem;
  11. private void Start()
  12. {
  13. listDataItem = new List<ServerData>();
  14. ServerData item1 = new ServerData();
  15. item1.ID = 31;
  16. item1.offsetPos = new Vector3(-0.4f,0, -0.3f);
  17. item1.eulerAxle = 3;
  18. ServerData item2 = new ServerData();
  19. item2.ID = 61;
  20. item2.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  21. item2.eulerAxle = 3;
  22. ServerData item3 = new ServerData();
  23. item3.ID = 64;
  24. item3.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  25. item3.eulerAxle = 3;
  26. ServerData item4 = new ServerData();
  27. item4.ID = 43;
  28. item4.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  29. item4.eulerAxle = 3;
  30. ServerData item5 = new ServerData();
  31. item5.ID = 3143;
  32. item5.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  33. item5.eulerAxle = 3;
  34. ServerData item6 = new ServerData();
  35. item6.ID = 3161;
  36. item6.offsetPos = new Vector3(-0.4f, 0, -0.3f);
  37. item6.eulerAxle = 3;
  38. listDataItem.Add(item1);
  39. listDataItem.Add(item2);
  40. listDataItem.Add(item3);
  41. listDataItem.Add(item4);
  42. listDataItem.Add(item5);
  43. listDataItem.Add(item6);
  44. if(PlayerPrefs.HasKey("ServerData"))
  45. {
  46. Debug.Log(" 读取 ServerData "+ PlayerPrefs.GetString("ServerData"));
  47. listDataItem = JsonConvert.DeserializeObject<List<ServerData>>(PlayerPrefs.GetString("ServerData"));
  48. }
  49. Init("");
  50. }
  51. public void Init( string msg)
  52. {
  53. // 根据后台的消息创建对应的机柜UI
  54. GameObject rDataItem = Resources.Load<GameObject>("DataItem");
  55. for (int i = 0; i < listDataItem.Count; i++)
  56. {
  57. GameObject item = GameObject.Instantiate(rDataItem);
  58. DataItem dataItem = item.GetComponent<DataItem>();
  59. // dataItem.Init(listDataItem[i].ID, listDataItem[i].offsetPos, listDataItem[i].eulerAxle,listDataItem[i],1000,1000);
  60. }
  61. }
  62. public void Save()
  63. {
  64. Debug.Log(" 保存 ServerData " + JsonConvert.SerializeObject(listDataItem));
  65. PlayerPrefs.SetString("ServerData", JsonConvert.SerializeObject(listDataItem));
  66. }
  67. }