123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
- using System.Linq;
- using Newtonsoft.Json;
- using SC.XR.Unity.Module_InputSystem;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.XR;
- using Ximmerse.XR.Tag;
- using Newtonsoft.Json.Linq;
- /// <summary>
- /// 大场景生成和Tag管理
- /// </summary>
- public class MachineRoomManager : MonoSingleton<MachineRoomManager>
- {
- public MachineRoomData data;
- public GameObject cabinetObj;
- public GameObject bladeServer;
- public bool isInit = false;
- public MachineRoomTagData tagData;
- public List<EditorTag> listEditorTag;
- GameObject tagObjPoint;
- private List<BladeServerItem> listBSItem;
- public TagTracking foundTracking;
- public GameObject cubeY;
- public Transform leftLine;
- public Transform rightLine;
- bool isSelect = false;
- private Transform selectTrigger;
- private Vector3 selectTOldPos;
- private Vector3 selectTOldRot;
- public bool isDataInit = false;
- public Transform startShowDevice;
- /// <summary>
- /// 临时创建 的tagid
- /// </summary>
- private List<int> listTagid;
- /// <summary>
- /// 临时创建 刀片机信息
- /// </summary>
- private DeviceParameters dp1;
- private DeviceParameters dp2;
- /// <summary>
- /// 机房列表
- /// </summary>
- public List<string> listRoomName;
- public void Init()
- {
- tagObjPoint = new GameObject();
- listBSItem = new List<BladeServerItem>();
- listRoomName = new List<string>();
- listRoomName.Add("4A-23");
- listRoomName.Add("4A-24");
- listRoomName.Add("4A-25");
- listRoomName.Add("4A-26");
- listRoomName.Add("4A-27");
- listTagid = new List<int>();
- listTagid.Add(6);
- listTagid.Add(15);
- listTagid.Add(26);
- listTagid.Add(27);
- listTagid.Add(28);
- listTagid.Add(30);
- listTagid.Add(31);
- listTagid.Add(32);
- listTagid.Add(35);
- listTagid.Add(36);
- listTagid.Add(38);
- listTagid.Add(41);
- //listTagid.Add(42);
- //listTagid.Add(43);
- //listTagid.Add(44);
- //listTagid.Add(50);
- //listTagid.Add(53);
- //listTagid.Add(55);
- //listTagid.Add(58);
- //listTagid.Add(61);
- //listTagid.Add(62);
- //listTagid.Add(64);
- //listTagid.Add(31);
- //listTagid.Add(61);
- //listTagid.Add(64);
- //listTagid.Add(43);
- //listTagid.Add(3161);
- //listTagid.Add(3164);
- //listTagid.Add(4361);
- //listTagid.Add(4364);
- #region 原初始化
- // //PlayerPrefs.DeleteAll();
- // if (PlayerPrefs.HasKey("MachineRoomData"))
- // {
- // string msg = PlayerPrefs.GetString("MachineRoomData");
- // UILogManager.Instance.text1.text = msg;
- // Debug.Log("MachineRoomData " + msg);
- // data = JsonConvert.DeserializeObject<MachineRoomData>(msg);
- // // Debug.Log("PlayerPrefs.HasKey(MachineRoomData) ");
- // //data = new MachineRoomData();
- // //data.line = 4;
- // //data.list = 3;
- // //data.intervalW = 1;
- // //data.intervalL = 2;
- // //data.cabinetW = 1.2f;
- // //data.cabinetH = 2f;
- // //data.bladeSeverNumber = 4;
- // //data.bIntervalH = 0.2f;
- // //data.firstBladeSeverH = 0.4f;
- // //data.TagOffestPosY = 0;
- // //data.CameraFar = 3;
- // //data.roomName = "4A-23";
- // //data.totalCapacity = 8520;
- // //data.usedCapacity = 4420;
- // //data.totalPower = 1278;
- // //data.usedPower = 846.24f;
- // //data.totalLoadBearing = 85.2f;
- // //data.usedBearing = 46.83f;
- // }
- // else
- // {
- // data = new MachineRoomData();
- // data.line = 4;
- // data.list = 3;
- // data.intervalW = 0.1f;
- // data.intervalL = 1f;
- // data.cabinetW = 0.6f;
- // data.cabinetH = 2f;
- // data.bladeSeverNumber = 4;
- // data.bIntervalH = 0.2f;
- // data.firstBladeSeverH = 0.4f;
- // data.tagOffestPosY = 1f;
- // data.cameraFar = 10;
- // data.roomName = "4A-23";
- // data.totalCapacity = 8520;
- // data.usedCapacity = 4420;
- // data.totalPower = 1278;
- // data.usedPower = 846.24f;
- // data.totalLoadBearing = 85.2f;
- // data.usedBearing = 46.83f;
- // }
- // // data.listCabinetData = null;
- // data.listEquipmentData = null;
- // data.listTagData = null;
- //// PlayerPrefs.DeleteAll();
- // if (PlayerPrefs.HasKey("MachineRoomTagData"))
- // {
- // string msg = PlayerPrefs.GetString("MachineRoomTagData");
- // Debug.Log("MachineRoomTagData " + msg);
- // data.listTagData = JsonConvert.DeserializeObject<List<MachineRoomTagData>>(msg);
- // }
- // else
- // {
- // data.listTagData = new List<MachineRoomTagData>();
- // MachineRoomTagData data1 = new MachineRoomTagData();
- // data1.id = 65;
- // //data1.pos = new Vector3(4.5f, 0, 0);
- // data1.pos = Vector3.zero;
- // data1.rot = new Vector3(0, 180, 0);
- // data1.offestPos = Vector3.zero;
- // data1.offestrot = Vector3.zero;
- // MachineRoomTagData data4 = new MachineRoomTagData();
- // data4.id = 141;
- // // data4.pos = new Vector3(4.5f, 2.5f, 3.7f);
- // data4.pos = Vector3.zero;
- // data4.rot = new Vector3(0, 180, 0);
- // data4.offestPos = Vector3.zero;
- // data4.offestrot = Vector3.zero;
- // MachineRoomTagData data5 = new MachineRoomTagData();
- // data5.id = 142;
- // // data5.pos = new Vector3(4.5f, 2.5f, 3.7f);
- // data5.pos = Vector3.zero;
- // data5.rot = new Vector3(0, 180, 0);
- // data5.offestPos = Vector3.zero;
- // data5.offestrot = Vector3.zero;
- // data.listTagData.Add(data1);
- // data.listTagData.Add(data4);
- // data.listTagData.Add(data5);
- // }
- // if (PlayerPrefs.HasKey("MachineRoomCabinetData"))
- // {
- // string msg = PlayerPrefs.GetString("MachineRoomCabinetData");
- // // data.listCabinetData = JsonConvert.DeserializeObject<List<MachineRoomCabinetData>>(msg);
- // data.listEquipmentData = JsonConvert.DeserializeObject<List<MachineParameters>>(msg);
- // }
- #endregion
- }
- private void Start()
- {
- Init();
-
- //Init();
-
- // Init();
- #if UNITY_EDITOR
- // Init();
- #endif
- }
- public void SceneInitCallBack(string msg)
- {
- Debug.Log(msg);
- JObject json = JObject.Parse(msg);
- UILogManager.Instance.text1.text = msg;
- if (json["code"].ToString() == "200")
- {
- string data = json["data"]["room"].ToString();
- this.data = JsonConvert.DeserializeObject<MachineRoomData>(data);
- UICallManager.Instance.MachineRoomInit();
- }
- else
- {
- Debug.LogError(" 请求场景参数出错 !!! " + HttpActionLang.sceneInit);
- }
- }
- public void SceneInit()
- {
- SettingMachineRoomData.Instance.Init(data);
- OpenXRCamera.Instance.head.GetComponent<Camera>().farClipPlane = data.cameraFar;
- MachineInit();
- // ServerInit();
- UICallManager.Instance.ShowDeviceTransform(startShowDevice);
- isDataInit = true;
- }
- private void Update()
- {
- if (state && tagData != null)
- {
- for (int i = 0; i < listEditorTag.Count; i++)
- {
- listEditorTag[i].gameObject.SetActive(!state);
- if (listEditorTag[i].id == tagData.id)
- listEditorTag[i].gameObject.SetActive(true);
- }
- }
- if (tagData != null && foundTracking != null && DragManager.Instance.triggerState == TriggerState.No && !state)
- {
- tagObjPoint.transform.SetParent(foundTracking.transform);
- tagObjPoint.transform.localEulerAngles = new Vector3(0, tagData.offestrot == Vector3.zero ? tagData.rot.y : tagData.offestrot.y, 0);
- tagObjPoint.transform.localPosition = tagData.offestPos == Vector3.zero ? tagData.pos : tagData.offestPos;
- // Debug.Log(" MachineRoom T " + tagData.offestPos);
- transform.eulerAngles = new Vector3(0, tagObjPoint.transform.eulerAngles.y, 0);
- transform.position = new Vector3(tagObjPoint.transform.position.x, foundTracking.transform.position.y + data.tagOffestPosY, tagObjPoint.transform.position.z);
- }
- if (Input.GetKeyDown(KeyCode.L))
- {
- OnTrackingFound(foundTracking);
- }
-
- }
- public List<MachineObj> listObjes = new List<MachineObj>();
- public void MachineInit()
- {
- //listObjes.Clear();
- //listObjes = new List<MachineObj>();
- //// 重新生成机柜组
- //if(data.listEquipmentData == null||data.listEquipmentData.Count!=(data.line*data.list))
- //{
- // data.listEquipmentData = new List<MachineParameters>();
- // for (int i = 0; i < data.line; i++)
- // {
- // for (int j = 0; j < data.list; j++)
- // {
- // MachineParameters mp1 = new MachineParameters();
- // mp1.deviceId = (i * data.list + j + 1).ToString();
- // mp1.tagID = -1000;
- // // mp1.offsetPos = new Vector3(-0.4f, 0, -0.3f);
- // mp1.offsetPos = Vector3.zero;
- // mp1.eulerAxle = 3;
- // mp1.deviceName = "设备" + (i * data.list + j + 1).ToString();
- // mp1.carryingSystem = "承载系统1";
- // mp1.deviceLocation = "4A-23机房";
- // mp1.equipmentType = "机柜";
- // mp1.equipmentModel = null;
- // mp1.factory = null;
- // mp1.specification = null;
- // mp1.listDevicesParameters = new List<DeviceParameters>();
- // if (int.Parse( mp1.deviceId) % 2 == 0)
- // mp1.listDevicesParameters.Add(dp1);
- // else
- // mp1.listDevicesParameters.Add(dp2);
- // data.listEquipmentData.Add(mp1);
- // }
- // }
- // for (int i = 0; i < listTagid.Count; i++)
- // {
- // if ((i + 1) < data.listEquipmentData.Count)
- // {
- // data.listEquipmentData[i].tagID = listTagid[i];
- // }
- // else
- // break;
- // }
- //}
- GameObject rDataItem = Resources.Load<GameObject>("DataItem");
- for (int i = 0; i < data.listEquipmentData.Count; i++)
- {
- GameObject obj = GameObject.Instantiate(cabinetObj, transform);
- obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
- Debug.Log(data.cabinetH + " " + data.cabinetW);
- obj.name =i.ToString();
- // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
- obj.transform.localPosition = new Vector3((i%data.list)*(data.cabinetW + data.intervalW), 0, (i/data.list) * data.intervalL);
- obj.GetComponent<MachineObj>().Setting((i / data.list) % 2 == 0);
- listObjes.Add(obj.GetComponent<MachineObj>());
- listObjes[i].deviceParameters = data.listEquipmentData[i];
-
- if(data.listEquipmentData[i]!=null)
- {
- GameObject item = GameObject.Instantiate(rDataItem);
- DataItem dataItem = item.GetComponent<DataItem>();
- dataItem.Init(data.listEquipmentData[i]);
- // item.SetActive(true);
- for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count; j++)
- {
- dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
- }
- listObjes[i].dataItem = dataItem;
- dataItem.transform.SetParent(listObjes[i].transform);
- dataItem.transform.localPosition = listObjes[i].xTag.localPosition;
- dataItem.transform.localEulerAngles = new Vector3(0, listObjes[i].isSingle ? 180 : 0, 0);
- }
- }
- //Debug.Log(data.line);
- Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
- Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list + data.cabinetW + data.intervalW), 0, 0);
- WayFindingManager.Instance.SetLine(leftPos, rightPos);
- SaveAllData();
- isInit = true;
-
- }
- public IEnumerator RandomRange()
- {
- yield return 2f;
- int randomNum = UnityEngine.Random.Range(0, listObjes.Count-1);
- // WayFindingManager.Instance.SetServerItem(listObjes[randomNum].transform);
- List<MachineObj> listMachineObj = new List<MachineObj>();
- for (int i = 0; i < 3; i++)
- {
- if(i<listObjes.Count-1)
- {
- listMachineObj.Add(listObjes[i]);
- }
- }
- WayFindingManager.Instance.NavigatorServer(listMachineObj);
- }
- public void ServerInit()
- {
- // if (data.listCabinetData == null)
- // return;
- //// GameObject rDataItem = Resources.Load<GameObject>("DataItem");
- // for (int i = 0; i < data.listCabinetData.Count; i++)
- // {
- // if (data.listCabinetData[i].listBladeServerData == null)
- // continue;
- // for (int j = 0; j < data.listCabinetData[i].listBladeServerData.Count; j++)
- // {
- // GameObject item = GameObject.Instantiate(rDataItem);
- // DataItem dataItem = item.GetComponent<DataItem>();
- // dataItem.Init(data.listCabinetData[i].listBladeServerData[j].tagID, data.listCabinetData[i].listBladeServerData[j].pos, data.listCabinetData[i].listBladeServerData[j].eulerAxle , data.listCabinetData[i].listBladeServerData[j], data.listCabinetData[i].listBladeServerData[j].width, data.listCabinetData[i].listBladeServerData[j].heigth);
- // }
- // }
- if (data.listEquipmentData == null)
- return;
- GameObject rDataItem = Resources.Load<GameObject>("DataItem");
- for (int i = 0; i < data.listEquipmentData.Count; i++)
- {
- GameObject item = GameObject.Instantiate(rDataItem);
- DataItem dataItem = item.GetComponent<DataItem>();
- dataItem.Init(data.listEquipmentData[i]);
- // item.SetActive(true);
- for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count;j++)
- {
- dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
- }
- }
- }
- public void SettingMachine( )
- {
- if (listObjes != null)
- {
- for (int i = 0; i < listObjes.Count; i++)
- {
- listObjes[i].gameObject.SetActive(false);
- }
- listObjes.Clear();
- listObjes = new List<MachineObj>();
- }
- if(BladeServerManager.Instance.listTagTracking!=null)
- {
- for (int i = 0; i < BladeServerManager.Instance.listTagTracking.Count; i++)
- {
- BladeServerManager.Instance.listTagTracking[i].gameObject.SetActive(false);
- }
- BladeServerManager.Instance.listTagTracking.Clear();
- }
-
- //data.listEquipmentData = new List<MachineParameters>();
- //for (int i = 0; i < data.line; i++)
- //{
- // for (int j = 0; j < data.list; j++)
- // {
-
- // MachineParameters mp1 = new MachineParameters();
- // mp1.deviceId = (i * data.list + j + 1).ToString();
- // mp1.tagID = -1000;
- // mp1.offsetPos = new Vector3(0f, 0, 0f);
- // mp1.eulerAxle = 3;
- // mp1.deviceName = "设备" + (i * data.list + j + 1).ToString();
- // mp1.carryingSystem = "承载系统1";
- // mp1.deviceLocation = "4A-23机房";
- // mp1.equipmentType = "机柜";
- // mp1.equipmentModel = null;
- // mp1.factory = null;
- // mp1.specification = null;
- // mp1.listDevicesParameters = new List<DeviceParameters>();
-
- // if (int.Parse( mp1.deviceId) % 2 == 0)
- // mp1.listDevicesParameters.Add(dp1);
- // else
- // mp1.listDevicesParameters.Add(dp2);
- // data.listEquipmentData.Add(mp1);
- // }
- //}
- //Debug.Log(data.line);
- //for (int i = 0; i < listTagid.Count; i++)
- //{
- // if (data.listEquipmentData.Count < (i + 1))
- // {
- // Debug.Log("a "+listTagid);
- // Debug.Log(data.listEquipmentData[i].tagID);
- // data.listEquipmentData[i].tagID = listTagid[i];
- // }
- //}
- //for (int i = 0; i < data.listEquipmentData.Count; i++)
- //{
- // GameObject obj = GameObject.Instantiate(cabinetObj, transform);
- // obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
- // Debug.Log(data.cabinetH + " " + data.cabinetW);
- // obj.name = data.listEquipmentData[i].deviceName;
- // // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
- // obj.transform.localPosition = new Vector3((i % data.line) * (data.cabinetW + data.intervalW), 0, i * data.intervalL);
- // obj.GetComponent<MachineObj>().Setting((i % data.line) % 2 == 0);
- // listObjes.Add(obj.GetComponent<MachineObj>());
- // listObjes[i].deviceParameters = data.listEquipmentData[i];
- //}
- //Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
- //Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list), 0, 0);
- //WayFindingManager.Instance.SetLine(leftPos, rightPos);
- GameObject rDataItem = Resources.Load<GameObject>("DataItem");
- for (int i = 0; i < data.listEquipmentData.Count; i++)
- {
- GameObject obj = GameObject.Instantiate(cabinetObj, transform);
- obj.transform.localScale = new Vector3(data.cabinetW, data.cabinetH, obj.transform.localScale.z);
- Debug.Log(data.cabinetH + " " + data.cabinetW);
- obj.name = data.listEquipmentData[i].deviceName;
- // Debug.Log(obj.name + " " + new Vector3(j * (data.cabinetW + data.intervalW), 0, i * data.intervalL));
- obj.transform.localPosition = new Vector3((i % data.line) * (data.cabinetW + data.intervalW), 0, (i / data.line) * data.intervalL);
- obj.GetComponent<MachineObj>().Setting((i / data.line) % 2 == 0);
- listObjes.Add(obj.GetComponent<MachineObj>());
- listObjes[i].deviceParameters = data.listEquipmentData[i];
- GameObject item = GameObject.Instantiate(rDataItem);
- DataItem dataItem = item.GetComponent<DataItem>();
- dataItem.Init(data.listEquipmentData[i]);
- // item.SetActive(true);
- for (int j = 0; j < data.listEquipmentData[i].listDevicesParameters.Count; j++)
- {
- dataItem.SetDeviceParametersData(data.listEquipmentData[i].listDevicesParameters);
- }
- listObjes[i].dataItem = dataItem;
- dataItem.transform.SetParent(listObjes[i].transform);
- dataItem.transform.localPosition = listObjes[i].xTag.localPosition;
- dataItem.transform.localEulerAngles = new Vector3(0, listObjes[i].isSingle ? 180 : 0, 0);
- }
- //Debug.Log(data.line);
- Vector3 leftPos = new Vector3(-1 * (data.cabinetW + data.intervalW), 0, 0);
- Vector3 rightPos = new Vector3((data.cabinetW * data.list + data.intervalW * data.list + data.cabinetW + data.intervalW), 0, 0);
- WayFindingManager.Instance.SetLine(leftPos, rightPos);
- SaveAllData();
- isInit = true;
- }
- public void SettingCameraFar()
- {
- OpenXRCamera.Instance.head.GetComponent<Camera>().farClipPlane = data.cameraFar;
- }
- public void OnTrackingFirst(TagTracking tracking)
- {
- if(isDataInit)
- QueryTagData(tracking);
- }
-
- public void OnTrackingStay(TagTracking tracking)
- {
-
- }
- public void OnTrackingFound(TagTracking tracking)
- {
- // UILogManager.Instance.SendLogText(2, tracking.TrackId.ToString());
- if (isDataInit)
- QueryTagData(tracking);
- }
- public void OnTrackingLost(TagTracking tracking)
- {
- if (isDataInit)
- {
- if (foundTracking == tracking)
- foundTracking = null;
- }
- }
- private void QueryTagData( TagTracking tracking)
- {
- if (isDataInit)
- {
- foundTracking = tracking;
- tagData = null;
- Debug.Log("DGJ ===> QueryTagData" + data.listTagData.Count);
- for (int i = 0; i < data.listTagData.Count; i++)
- {
- if (data.listTagData[i].id == tracking.TrackId)
- {
- tagData = data.listTagData[i];
- SynPlayerTransform.Instance.transform.SetParent(tracking.transform);
- break;
- }
- }
- }
-
- //if (state)
- //{
- // for (int i = 0; i < listEditorTag.Count; i++)
- // {
- // listEditorTag[i].gameObject.SetActive(!state);
- // if (listEditorTag[i].id == tracking.TrackId)
- // listEditorTag[i].gameObject.SetActive(true);
- // }
- //}
- }
- bool state = false;
- public void EditorTag(Text text)
- {
- text.text = state ? "打开" : "关闭";
- text.text += "场景编辑";
-
- state = !state;
- DragManager.Instance.state = state;
- cubeY.SetActive(state);
- for (int i = 0; i < listObjes.Count; i++)
- {
- listObjes[i].MeshState(state);
- }
- if (!state && foundTracking!=null)
- {
- for (int i = 0; i < listEditorTag.Count; i++)
- {
- listEditorTag[i].gameObject.SetActive(state);
- }
- for (int i = 0; i < data.listTagData.Count; i++)
- {
- //data.listTagData[i].offestPos = data.listTagData[i].tagModel.localPosition;
- //data.listTagData[i].offestrot = data.listTagData[i].tagModel.localEulerAngles;
- for (int j = 0; j < listEditorTag.Count; j++)
- {
- if (listEditorTag[j].id == data.listTagData[i].id)
- {
- //data.listTagData[i].offestPos+= listEditorTag[j].transform.localPosition;
- //data.listTagData[i].offestrot+= listEditorTag[j].transform.localEulerAngles;
- transform.SetParent(listEditorTag[j].transform.parent);
- data.listTagData[i].offestPos = transform.localPosition;
- data.listTagData[i].offestrot = transform.localEulerAngles;
- transform.parent = null;
-
- Debug.Log("DGJ ===> 保存 Tag " + listEditorTag[j].id);
- }
- }
-
- }
-
-
- UpdataTagData tagData = new UpdataTagData();
- tagData.listTagData = data.listTagData;
- string jsonDate = JsonConvert.SerializeObject(tagData);
- Debug.Log(jsonDate);
- HttpTool.Instance.Post(HttpActionLang.updateTag, jsonDate, UpdateTagCallBack);
- selectTOldPos = Vector3.zero;
- selectTOldRot = Vector3.zero;
- DragManager.Instance.triggerState = TriggerState.No;
- selectTrigger = null;
- }
-
- if(!state)
- {
- SaveAllData();
- }
- }
-
- private void UpdateTagCallBack(string msg)
- {
- Debug.Log(msg);
- JObject json = JObject.Parse(msg);
- if (json["code"].ToString() == "200")
- {
- Debug.Log(" 更新场景Tag参数成功 ");
- }
- else
- {
- Debug.LogError(" 更新场景Tag参数出错 !!! " + HttpActionLang.updateCabinet);
- }
- }
- public void SaveAllData()
- {
- PlayerPrefs.SetString("MachineRoomTagData", JsonConvert.SerializeObject(data.listTagData));
- PlayerPrefs.SetString("MachineRoomCabinetData", JsonConvert.SerializeObject(data.listEquipmentData));
- PlayerPrefs.SetString("MachineRoomData", JsonConvert.SerializeObject(data));
- Debug.Log(" 保存成功 " + JsonConvert.SerializeObject(data));
- }
- private void SaveData()
- {
- if(data!=null)
- {
- string _str = JsonConvert.SerializeObject(data);
- System.IO.Directory.CreateDirectory(Application.persistentDataPath+"/Data");
- string NowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_").Replace("/", "_").Replace(":", "_");
- Debug.Log(Application.persistentDataPath + "/Data");
- using (System.IO.StreamWriter writer = System.IO.File.CreateText(Application.persistentDataPath + "/Data" + "/"+ NowTime + "_data.txt"))
- {
- writer.Write(_str);
- //writer.
- }
-
-
- //UnityEditor.AssetDatabase.Refresh();
- }
- }
- private void OnDisable()
- {
- //PlayerPrefs.SetString("MachineRoomTagData", JsonConvert.SerializeObject(data.listTagData));
- //PlayerPrefs.SetString("MachineRoomCabinetData", JsonConvert.SerializeObject(data.listEquipmentData));
- //PlayerPrefs.SetString("MachineRoomData", JsonConvert.SerializeObject(data));
- // SaveData();
- }
- }
- public class UpdataTagData
- {
- public UpdataTagData()
- {
- listTagData = new List<MachineRoomTagData>();
- }
- public List<MachineRoomTagData> listTagData { get; set; }
- }
|