123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Newtonsoft.Json;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 模拟刀片机数据生成
- /// </summary>
- public class Servermanager : MonoSingleton<Servermanager>
- {
- public List<ServerData> listDataItem;
- private void Start()
- {
- listDataItem = new List<ServerData>();
- ServerData item1 = new ServerData();
- item1.ID = 31;
- item1.offsetPos = new Vector3(-0.4f,0, -0.3f);
- item1.eulerAxle = 3;
- ServerData item2 = new ServerData();
- item2.ID = 61;
- item2.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- item2.eulerAxle = 3;
- ServerData item3 = new ServerData();
- item3.ID = 64;
- item3.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- item3.eulerAxle = 3;
- ServerData item4 = new ServerData();
- item4.ID = 43;
- item4.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- item4.eulerAxle = 3;
- ServerData item5 = new ServerData();
- item5.ID = 3143;
- item5.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- item5.eulerAxle = 3;
- ServerData item6 = new ServerData();
- item6.ID = 3161;
- item6.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- item6.eulerAxle = 3;
- listDataItem.Add(item1);
- listDataItem.Add(item2);
- listDataItem.Add(item3);
- listDataItem.Add(item4);
- listDataItem.Add(item5);
- listDataItem.Add(item6);
- if(PlayerPrefs.HasKey("ServerData"))
- {
- Debug.Log(" 读取 ServerData "+ PlayerPrefs.GetString("ServerData"));
- listDataItem = JsonConvert.DeserializeObject<List<ServerData>>(PlayerPrefs.GetString("ServerData"));
- }
- Init("");
- }
- public void Init( string msg)
- {
- // 根据后台的消息创建对应的机柜UI
- GameObject rDataItem = Resources.Load<GameObject>("DataItem");
- for (int i = 0; i < listDataItem.Count; i++)
- {
- GameObject item = GameObject.Instantiate(rDataItem);
- DataItem dataItem = item.GetComponent<DataItem>();
- // dataItem.Init(listDataItem[i].ID, listDataItem[i].offsetPos, listDataItem[i].eulerAxle,listDataItem[i],1000,1000);
-
- }
- }
- public void Save()
- {
- Debug.Log(" 保存 ServerData " + JsonConvert.SerializeObject(listDataItem));
- PlayerPrefs.SetString("ServerData", JsonConvert.SerializeObject(listDataItem));
- }
- }
|