using Blue; using LitJson; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SC.XR.Unity; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class DataManager : SingletonMono { /// /// 当前账号下所有场景信息 /// private List m_SceneData; /// /// 当前场景数据 /// private SceneValue m_CurrentSceen; /// /// 当前场景ID /// private int m_ProjectID; /// /// 当前场景的所有景点 /// private List m_Spoits; /// /// 场景所对应的物体 /// private Dictionary m_SpoitObjs; /// /// Web端素材库 /// private Dictionary> m_AllMaterials; public bool IsSavedData { get; set; } public List SceneData { get { return m_SceneData; } set { m_SceneData = value; } } public SceneValue CurrentScene { get { return m_CurrentSceen; } set { m_CurrentSceen = value; } } public int ProjectID { get { return m_ProjectID; } set { m_ProjectID = value; } } public List Spoits { get { return m_Spoits; } set { m_Spoits = value; } } public Dictionary> AllMaterials { get { return m_AllMaterials; } set { m_AllMaterials = value; } } public void Awake() { IsSavedData = false; m_SpoitObjs = new Dictionary(); m_SceneData = new List(); m_Spoits = new List(); m_AllMaterials = new Dictionary>(); } /// /// 获取景点属性 /// /// 景点名称 public SpoitValue GetSpoitValue(string spoitName) { SpoitValue spoit = null; for (int i = 0; i < m_Spoits.Count; i++) { if (m_Spoits[i].name == spoitName) { spoit = m_Spoits[i]; break; } } return spoit; } /// /// 改变当前场景中的景点信息 /// /// 景点数据 public void ChangeSpoitValue(SpoitValue value) { for (int i = 0; i < m_Spoits.Count; i++) { if (value.name == m_Spoits[i].name) { m_Spoits[i] = value; } } } /// /// 获取当前景点所对应的物体 /// /// 景点名称 /// public ObjectValue GetSpoitObj(string spoitName) { return m_SpoitObjs[spoitName]; } public void SaveSpoits() { UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitData); Spoits = GameManager.Instance.SpoitValues; List saveData = new List(); for (int i = 0; i < Spoits.Count; i++) { var spoit = Spoits[i]; SendSaveData data = new SendSaveData(); data.id = spoit.id; data.name = spoit.name; data.projectId = ProjectID; data.material = spoit.material; data.spoittf = spoit.spoitTf; data.triggerRange = spoit.SpoitTransform[0]; saveData.Add(data); } string sendData = JsonConvert.SerializeObject(saveData); Debug.Log("更新景点数据: " + sendData); HttpTool.Instance.PostTest("/viewpoint/update", sendData, SaveCallBack); //string str = JsonMapper.ToJson(Spoits); FileManager.WriteFile(sendData, Application.persistentDataPath + "/a.json"); //Debug.Log(str); } private void SaveCallBack(string message) { if (message == "UnityWebRequest Error") { InstantiateCommand Command= new InstantiateCommand( InstantiateSystem.Instance.BlueObject.WarningPopUp, InstantiateSystem.Instance.BlueObject.NetErrorText); CommandSystem.Instance.Send(Command); return; } Debug.Log("SaveCallBack: " + message); JObject jObject = JObject.Parse(message); string str = jObject["message"].ToString(); if(str!="更新成功") { InstantiateCommand Command =new InstantiateCommand( InstantiateSystem.Instance.BlueObject.WarningPopUp, InstantiateSystem.Instance.BlueObject.NetErrorText); CommandSystem.Instance.Send(Command); return; } UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd); ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str; } private void OnApplicationQuit() { //if (!IsSavedData) //{ // SaveSpoits(); //} } } public class SendSaveAnchor { public int id { get; set; } public ObjectTransform objectTransform { get; set; } } public class sspos { public float x; public float y; public float z; } public class SendSaveDataNew { public List position; /// /// 景点ID /// public int id; /// /// 景点名称 /// public string name { get; set; } /// /// 场景id /// public int projectId; /// /// 素材 /// public List material { get; set; } /// /// 坐标 旋转 尺寸 如果没有数据的话默认为NULL /// public ObjectTransform spoittf { get; set; } /// /// 触发范围 /// public SpoitPos triggerRange { get; set; } public int triggerImageId; } public class SendSaveData { public List position { get; set; } public int triggerImageId { get; set; } /// /// 景点ID /// public int id; /// /// 景点名称 /// public string name { get; set; } /// /// 场景id /// public int projectId; /// /// 素材 /// public List material { get; set; } /// /// 坐标 旋转 尺寸 如果没有数据的话默认为NULL /// public ObjectTransform spoittf { get; set; } /// /// 触发范围 /// public SpoitPos triggerRange { get; set; } }