UIAnchorsPanel.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /****************************
  2. summary:
  3. ****************************/
  4. using Blue;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. public class UIAnchorsPanel : UIPanelBase
  12. {
  13. private Transform m_Content;
  14. private GameObject m_AnchorPrefab;
  15. private Toggle m_AnchorBtn;
  16. private Dictionary<Anchor, MeshRenderer> m_dicAnchors;
  17. protected override void OnAwake()
  18. {
  19. base.OnAwake();
  20. m_Content = CacheTransform.Find("UIAnchors/Scroll View/Viewport/UIAnchorlContent");
  21. m_AnchorPrefab = CacheTransform.Find("UIAnchors/AnchorBtn").gameObject;
  22. m_AnchorBtn = m_AnchorPrefab.GetComponent<Toggle>();
  23. }
  24. protected override void OnShow(object param)
  25. {
  26. base.OnShow(param);
  27. }
  28. public override void Hide()
  29. {
  30. base.Hide();
  31. }
  32. public void SetAnchor(Dictionary<Anchor,MeshRenderer> dicAnchors)
  33. {
  34. GameObject btnItem;
  35. m_dicAnchors = dicAnchors;
  36. foreach (var item in dicAnchors)
  37. {
  38. btnItem = Instantiate(m_AnchorBtn, m_Content).gameObject;
  39. btnItem.transform.localScale = new Vector3(1, 1, 1);
  40. btnItem.transform.localRotation = Quaternion.identity;
  41. btnItem.gameObject.SetActive(true);
  42. btnItem.GetComponent<AnchorBtnItem>().SetData(item.Value.gameObject,item.Key);
  43. }
  44. }
  45. public void SaveAnchors( string name )
  46. {
  47. Anchor anchor = null;
  48. GameObject anchorObj = null;
  49. foreach (var item in m_dicAnchors)
  50. {
  51. if (item.Value.name == name)
  52. {
  53. anchor = item.Key;
  54. anchorObj = item.Value.gameObject;
  55. }
  56. }
  57. if (anchor == null)
  58. return;
  59. SendSaveAnchor data = new SendSaveAnchor();
  60. data.id = anchor.id;
  61. data.objectTransform = anchor.objectTransform;
  62. string sendData = JsonConvert.SerializeObject(data);
  63. Debug.Log("更新景点数据: " + sendData);
  64. HttpTool.Instance.PostTest("/picture/update", sendData, SaveCallBack);
  65. }
  66. private void SaveCallBack(string message)
  67. {
  68. if(message == "UnityWebRequest Error")
  69. {
  70. InstantiateCommand Command = new InstantiateCommand(
  71. InstantiateSystem.Instance.BlueObject.WarningPopUp,
  72. InstantiateSystem.Instance.BlueObject.NetErrorText);
  73. CommandSystem.Instance.Send(Command);
  74. return;
  75. }
  76. Debug.Log("SaveCallBack: " + message);
  77. JObject jObject = JObject.Parse(message);
  78. string str = jObject["message"].ToString();
  79. if(str!="更新成功")
  80. {
  81. InstantiateCommand Command =new InstantiateCommand(
  82. InstantiateSystem.Instance.BlueObject.WarningPopUp,
  83. InstantiateSystem.Instance.BlueObject.NetErrorText);
  84. CommandSystem.Instance.Send(Command);
  85. return;
  86. }
  87. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd);
  88. ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
  89. }
  90. }