Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Xml;
- using System.Collections;
- using UnityEngine.Networking;
- namespace g144.debug
- {
- [ExecuteInEditMode]
- public class gameMapping_topMenu : MonoBehaviour
- {
- private string titlePar = "markersHouse";
- private static gameMapping_topMenu cache;
- private void OnEnable()
- {
- cache = this;
- }
- [MenuItem("mapping/Update house markers")]
- public static void updateHouseMarkers()
- {
- cache.reqUpdateMarkers();
- }
- private void reqUpdateMarkers()
- {
- StartCoroutine(getMarkersInfo());
- }
- private IEnumerator getMarkersInfo()
- {
- Debug.LogWarning("send request. please wait...");
- string url = "http://127.0.0.1/house.php";
- WWWForm form = new WWWForm();
- form.AddField("action", "getMarkers"); // response snapshot https://imgur.com/a/IzchLvB
- UnityWebRequest req = UnityWebRequest.Post(url, form);
- yield return req.SendWebRequest();
- webResponse resp = GlobalEnv.parseWebReq(req); // method snapshot https://imgur.com/a/EaTgZY1
- Transform markerPar = GameObject.Find(titlePar).transform;
- if (markerPar)
- {
- int countOldMarkers = markerPar.childCount;
- for (int i = 0; i < countOldMarkers; i++)
- DestroyImmediate(markerPar.GetChild(0).gameObject);
- }
- else
- markerPar = new GameObject(titlePar).transform;
- if (resp.isSuccess)
- {
- XmlNodeList nodes = resp.node.ChildNodes;
- for(int i = 0; i < nodes.Count; i++)
- {
- string[] cord = nodes[i]["cord"].InnerText.Split(',');
- Transform marker = new GameObject(string.Format("marker_{0}", i)).transform;
- marker.parent = markerPar;
- marker.position = new Vector3(float.Parse(cord[0]), float.Parse(cord[1]), float.Parse(cord[2]));
- }
- }
- else
- Debug.LogWarning("No find markers");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement