UIAnchorsPanel.cs 2.6 KB

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