using System; using System.Collections; using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.UI; public class UIEditorPanel : MonoBehaviour, EventObserver { public event Action OnClickRemoveBtn; [SerializeField] private Button UCBtn; [SerializeField] private Button TicBtn; [SerializeField] private Button RemoveBtn; [SerializeField] private Image UCElenemt; [SerializeField] private Button AddSize; [SerializeField] private Button SubSize; [SerializeField] private Button SubY; [SerializeField] private Button AddY; [SerializeField] private Button SubX; [SerializeField] private Button AddX; [SerializeField] private SCButton SubRot; [SerializeField] private SCButton AddRot; [SerializeField] private Image TicElenemt; [SerializeField] private Button ADDXBtn; [SerializeField] private Button SubXBtn; [SerializeField] private Button ADDYBtn; [SerializeField] private Button SubYBtn; [SerializeField] private Button AddZBtn; [SerializeField] private Button SubZBtn; [SerializeField] private Button InitiativeBtn; [SerializeField] private Button RevocationBtn; [SerializeField] private Button SaveBtn; private Transform MaterialObj; /// /// 当前物体移动旋转缩放的操作步骤 /// private List listAlter; /// /// 当前景点信息 /// private SpoitValue listSpoits; private void Awake() { InitEvent(); MaterialObj = null; listAlter = new List(); listSpoits = new SpoitValue(); EventManager.Instance.Register(this, EventID.EVENT_1); initCount = GameManager.Instance.ObjsParent.childCount; } public void Init() { } private void InitEvent() { UCBtn.onClick.AddListener(() => { if (UCElenemt.gameObject.activeSelf) return; UCElenemt.gameObject.SetActive(true); TicElenemt.gameObject.SetActive(false); }); TicBtn.onClick.AddListener(() => { if (TicElenemt.gameObject.activeSelf) return; UCElenemt.gameObject.SetActive(false); TicElenemt.gameObject.SetActive(true); }); RemoveBtn.onClick.AddListener(() => { if (MaterialObj == null) return; if (MaterialObj.tag == "TriggerBox") return; if (OnClickRemoveBtn != null) { OnClickRemoveBtn(MaterialObj.gameObject); } }); //RemoveBtn.gameObject.SetActive(false); AddSize.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localScale += new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f); }); SubSize.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localScale -= new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f); }); AddRot.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localEulerAngles += new Vector3(0, 10, 0); }); SubRot.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localEulerAngles -= new Vector3(0, 10, 0); }); AddX.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubX.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0.1f, 0, 0); }); AddY.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0.1f, 0); }); SubY.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0.1f, 0); }); ADDXBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubXBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0.1f, 0, 0); }); ADDYBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0.1f, 0); }); SubYBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0.1f, 0); }); AddZBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0, 0.1f); }); SubZBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0, 0.1f); }); InitiativeBtn.onClick.AddListener(() => { if (MaterialObj == null) return; InitMaterialObj(); }); RevocationBtn.onClick.AddListener(() => { GameManager.Instance.SetPosRotScale(); if (MaterialObj == null) return; if (listAlter.Count >= 1) { MaterialObj.localPosition = listAlter[listAlter.Count - 1].pos; MaterialObj.localEulerAngles = listAlter[listAlter.Count - 1].rot; MaterialObj.localScale = listAlter[listAlter.Count - 1].scale; listAlter.RemoveAt(listAlter.Count - 1); } }); SaveBtn.onClick.AddListener(() => { /* if (MaterialObj == null) return; GameManager.Instance.SaveSpoitObjs(); */ // TODO 需要再保存一次 GameManager.Instance.GetPosRotScale(); StartCoroutine(SetSpoitInfo()); }); } private int initCount; // 本身存在多少个景点 public IEnumerator SetSpoitInfo() { countSplit =0;saveData.Clear(); int count = GameManager.Instance.ObjsParent.childCount; for (int i = initCount; i <= count-1;i++) // 第一个LocalNULLShowObj是无用的 { for (int temp = 0; temp < GameManager.Instance.ColliderObjectValues.Count;temp++) { // 判断景点是否是场景景点名字 if(GameManager.Instance.ColliderObjectValues[temp].matName==GameManager.Instance.ObjsParent.GetChild(i).name) { Debug.LogError(GameManager.Instance.ObjsParent.GetChild(i).name); var spoit = GameManager.Instance.SpoitValues[i-initCount]; // 某个景点 for (int j = 0; j < spoit.material.Count; j++) // 更新 ObjectTransform { for (int k = 0;k< spoit.material[j].materialList.Count; k++) { spoit.material[j].select = true; spoit.material[j].materialList[k].ObjectTransform.nowPos = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localPosition; spoit.material[j].materialList[k].ObjectTransform.nowRot = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localEulerAngles; spoit.material[j].materialList[k].ObjectTransform.nowScale = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localScale; } } SplitSpoitData(spoit,count-initCount); //// 第一个LocalNULLShowObj是无用的 ,so -1 yield return null; } } } } private List saveData = new List(); private void SplitSpoitData(SpoitValue spoit,int spoitCount) { countSplit++; SendSaveData data = new SendSaveData(); data.id = spoit.id; data.name = spoit.name; data.projectId = DataManager.Instance.ProjectID; data.material = spoit.material; data.spoittf = spoit.spoitTf; saveData.Add(data); string sendData = JsonConvert.SerializeObject(saveData); //Debug.LogError(countSplit+"=="+spoitCount); if(countSplit==spoitCount) HttpTool.Instance.PostTest("/viewpoint/update", sendData, SaveCallBack); } private int countSplit =0; private void SaveCallBack(string message) { if (message == "UnityWebRequest Error") { InstantiateCommand ErrorCommand = new InstantiateCommand( InstantiateSystem.Instance.BlueObject.WarningPopUp, InstantiateSystem.Instance.BlueObject.NetErrorText); CommandExtensionSystem.Instance.Send(ErrorCommand); //this.GetService().SendLog("Blue","UnityWebRequest Error"); return; } //Debug.LogError("SaveCallBack: " + message); JObject jObject = JObject.Parse(message); string str = jObject["message"].ToString(); if (str != "更新成功") { InstantiateCommand ErrorCommand = new InstantiateCommand( InstantiateSystem.Instance.BlueObject.WarningPopUp, InstantiateSystem.Instance.BlueObject.NetErrorText); CommandExtensionSystem.Instance.Send(ErrorCommand); Debug.LogError("执行协程数:" + countSplit); //this.GetService().SendLog("Blue","更新成功出现问题"); return; } Debug.Log("更新成功"); UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd); ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str; InstantiateCommand Command = new InstantiateCommand( InstantiateSystem.Instance.BlueObject.WarningPopUp, "保存成功"); CommandExtensionSystem.Instance.Send(Command); } /// /// 选择素材 /// /// public void SelectMaterial(Transform MaterialObj) { this.MaterialObj = MaterialObj; listAlter.Clear(); listAlter = new List(); } /// /// 初始化素材 /// 只初始化当前素材 /// private void InitMaterialObj() { if (MaterialObj == null) return; string name = MaterialObj.name; listAlter.Clear(); listAlter = new List(); GameManager.Instance.InitSpoitObjs(); } private void SaveAlter() { objectData data = new objectData(); data.pos = MaterialObj.localPosition; data.rot = MaterialObj.localEulerAngles; data.scale = MaterialObj.localScale; listAlter.Add(data); } public void HandleEvent(EventData data) { switch (data.ID) { case EventID.EVENT_1: EventData1 data1 = (EventData1)data; if (data1.SelectObj != null) { SelectMaterial(data1.SelectObj.transform); } else { MaterialObj = null; listAlter.Clear(); } break; case EventID.EVENT_2: break; default: break; } } private void OnDestroy() { //EventManager.Instance.Remove(this); } }