/// <summary> /// 刷新GamingMap ui /// </summary> /// <param name="map"></param> private void RefreshMapUI(GamingMap gamingMap) { if (gamingMap == null) { return; } m_ContentCache.Clear(); m_ContentCache.Add(new GUIContent("导出数据到json")); m_ContentCache.Add(new GUIContent("保存")); Scene scene = gamingMap.GetMapScene(); if (!scene.isLoaded) { gamingMap.OpenMapScene(); } Map map = null; GameObject[] rootObjs = scene.GetRootGameObjects(); if (rootObjs != null && rootObjs.Length > 0) { for (int iRoot = 0; iRoot < rootObjs.Length; iRoot++) { GameObject obj = rootObjs[iRoot]; map = obj.GetComponent <Map>(); if (map != null) { break; } } } if (map != null) { List <AreaSpawner> areaSpawnerList = map.GetAreaSpawnerList(); if (areaSpawnerList != null && areaSpawnerList.Count > 0) { for (int iArea = 0; iArea < areaSpawnerList.Count; iArea++) { AreaSpawner areaSpawner = areaSpawnerList[iArea]; GUIContent content = new GUIContent(string.Format("区域/GamingArea_{0}", areaSpawner.GetAreaId())); m_ContentCache.Add(content); } } } Vector2 mousePosition = Event.current.mousePosition; GameObject userData = Selection.activeGameObject; int selected = -1; EditorUtility.DisplayCustomMenu(new Rect(mousePosition.x, mousePosition.y, 0, 0), m_ContentCache.ToArray(), selected, delegate(object data, string[] opt, int select) { switch (select) { case 0: //BeginExportGamingMap(gamingMap,map); List <ulong> areaIds = new List <ulong>(); List <Leap> allLeaps = m_LeapOverview.m_LeapList; if (allLeaps != null && allLeaps.Count > 0) { for (int iLeap = 0; iLeap < allLeaps.Count; iLeap++) { if (allLeaps[iLeap].m_IsExportToJson) { areaIds.Add(allLeaps[iLeap].m_LeapId); } } } new ExportGamingMapData().BeginExport(map, gamingMap, areaIds); break; case 1: //保存 gamingMap.SaveScene(); break; default: gamingMap.OnClickArea(select, map); break; } }, userData); Event.current.Use(); }
protected override IEnumerator DoExport() { if (m_GamingMapPaths != null && m_GamingMapPaths.Count > 0) { for (int iMap = 0; iMap < m_GamingMapPaths.Count; iMap++) { string mapPath = m_GamingMapPaths[iMap]; Scene iterScene = EditorSceneManager.OpenScene(mapPath, OpenSceneMode.Single); GameObject[] rootGameObjects = iterScene.GetRootGameObjects(); for (int iRootGameObject = 0; iRootGameObject < rootGameObjects.Length; iRootGameObject++) { GameObject iterGameObject = rootGameObjects[iRootGameObject]; GamingMap iterMap = iterGameObject.GetComponent <GamingMap>(); if (iterMap) { Scene scene = iterMap.GetMapScene(); if (!scene.isLoaded) { iterMap.OpenMapScene(); scene = iterMap.GetMapScene(); } while (!scene.isLoaded) { yield return(null); } Map map = null; GameObject[] rootObjs = scene.GetRootGameObjects(); if (rootObjs != null && rootObjs.Length > 0) { for (int iRoot = 0; iRoot < rootObjs.Length; iRoot++) { GameObject obj = rootObjs[iRoot]; map = obj.GetComponent <Map>(); if (map != null) { break; } } } while (map == null) { yield return(null); } LeapOverview leapOverView = iterMap.GetComponentInChildren <LeapOverview>(); List <ulong> areaIds = null; if (leapOverView != null) { areaIds = new List <ulong>(); List <Leap> allLeaps = leapOverView.m_LeapList; if (allLeaps != null && allLeaps.Count > 0) { for (int iLeap = 0; iLeap < allLeaps.Count; iLeap++) { if (allLeaps[iLeap].m_IsExportToJson) { areaIds.Add(allLeaps[iLeap].m_LeapId); } } } } ExporterHandle handle = new ExportGamingMapData().BeginExport(map, iterMap, areaIds); //ExporterHandle handle = iterMap.BeginExportGamingMap(iterMap, map); while (!handle.IsDone) { yield return(null); } } } } } }