UIAnchorsPanel.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. private string sendData;
  46. public void SaveAnchors( string name )
  47. {
  48. Anchor anchor = null;
  49. GameObject anchorObj = null;
  50. foreach (var item in m_dicAnchors)
  51. {
  52. if (item.Value.name == name)
  53. {
  54. anchor = item.Key;
  55. anchorObj = item.Value.gameObject;
  56. }
  57. }
  58. if (anchor == null)
  59. return;
  60. SendSaveAnchor data = new SendSaveAnchor();
  61. data.id = anchor.id;
  62. data.objectTransform = anchor.objectTransform;
  63. sendData = JsonConvert.SerializeObject(data);
  64. Debug.Log("更新景点数据: " + sendData);
  65. HttpTool.Instance.PostTest("/picture/update", sendData, SaveCallBack);
  66. }
  67. private void SaveCallBack(string message)
  68. {
  69. if(message == "UnityWebRequest Error")
  70. {
  71. InstantiateCommand Command = new InstantiateCommand(
  72. InstantiateSystem.Instance.BlueObject.WarningPopUp,
  73. InstantiateSystem.Instance.BlueObject.NetErrorText);
  74. CommandExtensionSystem.Instance.Send(Command);
  75. return;
  76. }
  77. Debug.Log("SaveCallBack: " + message);
  78. JObject jObject = JObject.Parse(message);
  79. string str = jObject["message"].ToString();
  80. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd);
  81. ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
  82. }
  83. }