123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Blue;
- using LitJson;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using UnityEngine;
- using UnityEngine.Assertions.Must;
- using UnityEngine.UI;
- public class UIEditorPanel : AbstractController, EventObserver
- {
- public event Action<GameObject> 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;
- /// <summary>
- /// 当前物体移动旋转缩放的操作步骤
- /// </summary>
- private List<objectData> listAlter;
- /// <summary>
- /// 当前景点信息
- /// </summary>
- private SpoitValue listSpoits;
- public static UIEditorPanel Instance;
- private void Awake()
- {
- Instance = this;
- InitEvent();
- MaterialObj = null;
- listAlter = new List<objectData>();
- listSpoits = new SpoitValue();
- EventManager.Instance.Register(this, EventID.EVENT_1);
- }
- 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)
- {
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- "保存失败\n服务器异常,请稍后重试");
- CommandSystem.Instance.Send(Command);
- //this.GetService<ISendLogService>().SendLog("Blue","请选择素材");
- return;
- }
- GameManager.Instance.SaveSpoitObjs();
- */
- // TODO 需要再保存一次
- GameManager.Instance.GetPosRotScale();
- StartCoroutine(SetSpoitInfo());
- });
- }
- public IEnumerator SetSpoitInfo()
- {
- countSplit =0;saveData.Clear();
- int count = GameManager.Instance.ObjsParent.childCount;
- for (int i = 1; i <= count-1;i++) // 第一个LocalNULLShowObj是无用的
- {
- var spoit = GameManager.Instance.SpoitValues[i-1]; // 某个景点
- 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;
- if(GameManager.Instance.allobjs.ContainsKey(spoit.id.ToString()))
- {
- if (GameManager.Instance.allobjs[spoit.id.ToString()].ContainsKey(spoit.material[j].id.ToString()))
- {
- if (GameManager.Instance.allobjs[spoit.id.ToString()][spoit.material[j].id.ToString()].ContainsKey(spoit.material[j].materialList[k].id.ToString()))
- {
- spoit.material[j].materialList[k].ObjectTransform.nowPos = GameManager.Instance.allobjs[spoit.id.ToString()][spoit.material[j].id.ToString()][spoit.material[j].materialList[k].id.ToString()].transform.localPosition;// spoit.material[j].materialList[k].obj.transform.localPosition;// GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localPosition;
- spoit.material[j].materialList[k].ObjectTransform.nowRot = GameManager.Instance.allobjs[spoit.id.ToString()][spoit.material[j].id.ToString()][spoit.material[j].materialList[k].id.ToString()].transform.localEulerAngles;//spoit.material[j].materialList[k].obj.transform.localEulerAngles;// GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localEulerAngles;
- spoit.material[j].materialList[k].ObjectTransform.nowScale = GameManager.Instance.allobjs[spoit.id.ToString()][spoit.material[j].id.ToString()][spoit.material[j].materialList[k].id.ToString()].transform.localScale;//spoit.material[j].materialList[k].obj.transform.localScale;// GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localScale;
- }
- }
- }
- // Debug.Log("HJJSSSSSSSSSSSSSSSS保存 ===》"+ spoit.id.ToString()+"_"+ spoit.material[j].id.ToString() + "_"+ spoit.material[j].materialList[k].id.ToString());
- }
- }
- SplitSpoitData(spoit,count-1); //// 第一个LocalNULLShowObj是无用的 ,so -1
- yield return null;
- }
- }
- private List<SendSaveData> saveData = new List<SendSaveData>();
- private void SplitSpoitData(SpoitValue spoit,int spoitCount)
- {
- countSplit++;
- // GameManager.Instance.UpdateSpoitValue();
- SendSaveData data = new SendSaveData();
- data.id = GameManager.Instance.SpoitsValueDetail[spoit.id].id;
- data.name = GameManager.Instance.SpoitsValueDetail[spoit.id].name;
- data.projectId = DataManager.Instance.ProjectID;
- data.material = spoit.material;
- data.spoittf = GameManager.Instance.SpoitsValueDetail[spoit.id].spoitTf;
- data.position = GameManager.Instance.SpoitsValueDetail[spoit.id].position;
- data.spoittf.nowPos = GameManager.Instance.spoitposObjDic[spoit.id].transform.localPosition - GameManager.Instance.spoitposDic[spoit.id];
- Debug.Log("最新保存====》保存的POS" + data.spoittf.nowPos);
- Debug.Log("最新保存====》物體的POS" + GameManager.Instance.spoitposObjDic[spoit.id].transform.localPosition);
- Debug.Log("最新保存====》原始的POS" + GameManager.Instance.spoitposDic[spoit.id]);
- data.spoittf.nowRot = GameManager.Instance.spoitposObjDic[spoit.id].transform.localEulerAngles;
- data.spoittf.nowScale = GameManager.Instance.spoitposObjDic[spoit.id].transform.localScale;
- data.triggerImageId = GameManager.Instance.SpoitsValueDetail[spoit.id].triggerImageId;
- data.triggerRange = GameManager.Instance.SpoitsValueDetail[spoit.id].triggerRange;
- saveData.Add(data);
- if (countSplit==spoitCount)
- {
- string sendData = JsonConvert.SerializeObject(saveData);
- JsonData jsdata = JsonMapper.ToObject(sendData);
- for (int i = 0; i < jsdata.Count; i++)
- {
- if(jsdata[i].Keys.Contains("material")&&jsdata[i]["material"].IsArray)
- {
- for (int j = 0; j < jsdata[i]["material"].Count; j++)
- {
- if (jsdata[i]["material"][j].Keys.Contains("materialList") && jsdata[i]["material"][j]["materialList"].IsArray)
- {
- for (int k = 0; k < jsdata[i]["material"][j]["materialList"].Count; k++)
- {
- jsdata[i]["material"][j]["materialList"][k]["textBJ"] = jsdata[i]["material"][j]["materialList"][k]["TextBJ"];
- jsdata[i]["material"][j]["materialList"][k]["downloadPath"] = jsdata[i]["material"][j]["materialList"][k]["DownloadPath"];
- jsdata[i]["material"][j]["materialList"][k]["objectTransform"] = jsdata[i]["material"][j]["materialList"][k]["ObjectTransform"];
- }
- }
-
- }
- }
- }
- Debug.LogError(countSplit + "==" + spoitCount);
- Debug.LogError("sendDatasendDatasendData====>" + jsdata.ToJson());
- HttpTool.Instance.PostTest("/viewpoint/update", jsdata.ToJson(), SaveCallBack);
- }
- }
- private int countSplit =0;
- private void SaveCallBack(string message)
- {
- try
- {
- JsonData jd = JsonMapper.ToObject(message);
- if (jd.Keys.Contains("message"))
- {
- if (jd["message"].ToString() == "success")
- {
- Debug.Log("更新成功");
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd);
- ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = "更新成功";
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存成功";
- GameManager.Instance.saveOldData();
- return;
- }
- else
- {
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存失败";
- //this.GetService<ISendLogService>().SendLog("Blue","UnityWebRequest Error");
- return;
- }
- }
- else
- {
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存失败";
- //this.GetService<ISendLogService>().SendLog("Blue","UnityWebRequest Error");
- return;
- }
- }
- catch
- {
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存失败";
- //this.GetService<ISendLogService>().SendLog("Blue","UnityWebRequest Error");
- return;
- }
-
- }
- /// <summary>
- /// 选择素材
- /// </summary>
- /// <param name="MaterialObj"></param>
- public void SelectMaterial(Transform MaterialObj)
- {
- Debug.LogError("MaterialObjName:"+MaterialObj.name);
- this.MaterialObj = MaterialObj;
- listAlter.Clear();
- listAlter = new List<objectData>();
- }
- /// <summary>
- /// 初始化素材
- /// 只初始化当前素材
- /// </summary>
- private void InitMaterialObj()
- {
- if (MaterialObj == null)
- return;
- string name = MaterialObj.name;
- listAlter.Clear();
- listAlter = new List<objectData>();
- 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);
- }
- }
|