/// <summary> /// 初始化 /// </summary> /// <param name="gamingMapuid"></param> /// <param name="mapId"></param> /// <param name="mapName"></param> /// <param name="mapType"></param> /// <param name="areaSpawners"></param> public void Init(uint gamingMapuid, uint mapId, string mapName, GamingMapType mapType, List <AreaSpawner> areaSpawners) { m_Uid = gamingMapuid; m_MapId = mapId; m_MapName = mapName; m_Type = mapType; string areaTemplete = ""; GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting(); if (gamingSetting != null) { areaTemplete = gamingSetting.m_GamingAreaTemplete; } GameObject areaTempleteAsset = AssetDatabase.LoadAssetAtPath <GameObject>(areaTemplete); if (areaTempleteAsset == null) { Debug.LogError("GamingMap Area 模板未设置"); return; } if (areaSpawners != null && areaSpawners.Count > 0) { m_GamingAreaList = new List <GamingMapArea>(); for (int iArea = 0; iArea < areaSpawners.Count; iArea++) { AreaSpawner areaSpawner = areaSpawners[iArea]; CreateGamingArea(areaSpawner); } } SaveScene(); }
/// <summary> /// 是否显示落地 /// </summary> /// <returns></returns> public bool IsShowLand() { if (m_Root == null) { return(false); } GamingMapType mapType = m_Root.GetGamingMapType(); return(mapType == GamingMapType.mapMainCity); }
public IEnumerator OnUpdate(GamingMapArea mapArea) { m_GamingMapArea = mapArea; GamingMapType mapType = m_GamingMapArea.GetGamingMapType(); if (mapType != m_lastGamingMapType) { ResetModelPath(); } m_lastGamingMapType = mapType; if (m_CreateTeleportEnumerator != null) { while (m_CreateTeleportEnumerator.MoveNext()) { yield return(null); } m_CreateTeleportEnumerator = null; m_EditorLocation = null; } yield return(null); m_LocationCache = gameObject.GetComponentsInChildren <Location>(); CalcuateMaxLocationId(); if (m_LocationCache != null && m_LocationCache.Length > 0) { for (int iLocation = 0; m_LocationCache != null && iLocation < m_LocationCache.Length; iLocation++) { IEnumerator locationEnumerator = m_LocationCache[iLocation].OnUpdate(this, m_ShowModel); if (locationEnumerator != null) { while (m_LocationCache != null && m_LocationCache[iLocation] != null && locationEnumerator.MoveNext()) { yield return(null); } } } } yield return(null); }
private void OnGUI() { GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField("关联地图Scene:", m_RelationScene); if (m_HasSelect) { if (GUILayout.Button("收起", GUILayout.Width(100))) { m_HasSelect = false; } GUILayout.EndHorizontal(); m_VerticalPos = GUILayout.BeginScrollView(m_VerticalPos); GUILayout.BeginVertical("box"); if (m_RelationSceneList != null && m_RelationSceneList.Count > 0) { for (int iRelation = 0; iRelation < m_RelationSceneList.Count; iRelation++) { string[] splitPath = m_RelationSceneList[iRelation].Split('/'); if (splitPath != null && splitPath.Length > 0) { string showPath = splitPath[splitPath.Length - 1]; if (!string.IsNullOrEmpty(showPath)) { showPath = showPath.Replace(".unity", ""); if (GUILayout.Button(showPath)) { m_RelationScene = m_RelationSceneList[iRelation]; m_HasSelect = false; } } } } } else { GUILayout.Label("未找到关联的Scene"); } GUILayout.EndVertical(); GUILayout.EndScrollView(); } else { if (GUILayout.Button("选择", GUILayout.Width(100))) { m_HasSelect = true; } GUILayout.EndHorizontal(); } GUILayout.BeginVertical("box"); m_GamingMapId = EditorGUILayout.TextField("GamingMap Id:", m_GamingMapId); m_GamingMapName = EditorGUILayout.TextField("名称:", m_GamingMapName); //m_GamingMapType = (GamingMapType)EditorGUILayout.EnumPopup("类型:", m_GamingMapType); m_SelectTypeIndex = EditorGUILayout.Popup(new GUIContent("类型:"), m_SelectTypeIndex, EditorGamingMapData.GAMINGMAPTYPE_NAME); m_GamingMapType = (GamingMapType)m_SelectTypeIndex; if (GUILayout.Button("创建")) { if (m_RelationScene == null) { EditorUtility.DisplayDialog("提示", "请选择关联地图Scene", "确定"); return; } uint mapId; if (!uint.TryParse(m_GamingMapId, out mapId)) { EditorUtility.DisplayDialog("提示", "GamingMap id格式错误", "确定"); return; } if (string.IsNullOrEmpty(m_GamingMapName)) { EditorUtility.DisplayDialog("提示", "名称不能为空", "确定"); return; } string mapPath = ""; GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting(); if (gamingSetting != null) { mapPath = string.Format("{0}/GamingMap_{1}.unity", MapEditorUtility.GetFullPath(gamingSetting.m_GamingMapPath), mapId); } if (File.Exists(mapPath)) { EditorUtility.DisplayDialog("提示", "该GamingMap已存在", "确定"); return; } List <Scene> openScenes = new List <Scene>(); for (int iScene = 0; iScene < EditorSceneManager.sceneCount; iScene++) { Scene sceneTmp = EditorSceneManager.GetSceneAt(iScene); openScenes.Add(sceneTmp); } SaveOpenScene(); //打开对应的map 找到mapid 创建Gamingmap 初始化GamingMap和Area Scene scene = EditorSceneManager.OpenScene(m_RelationScene, OpenSceneMode.Additive); Map map = null; GameObject[] objs = scene.GetRootGameObjects(); if (objs != null && objs.Length > 0) { for (int iObj = 0; iObj < objs.Length; iObj++) { map = objs[iObj].GetComponent <Map>(); if (map != null) { break; } } } //string gamingPath = PlayerPrefsUtility.GetString(Constants.GAMINGMAP_TEMPLETE_PATH); string gamingPath = ""; if (gamingSetting != null) { gamingPath = MapEditorUtility.GetFullPath(gamingSetting.m_GamingMapTemplete); gamingPath += "/"; } FileUtil.CopyFileOrDirectory(gamingPath, mapPath); AssetDatabase.ImportAsset(mapPath); Scene exportScene = EditorSceneManager.OpenScene(mapPath, OpenSceneMode.Additive); GameObject[] exportObjs = exportScene.GetRootGameObjects(); if (exportObjs != null && exportObjs.Length > 0) { for (int iExport = 0; iExport < exportObjs.Length; iExport++) { GamingMap gamingMap = exportObjs[iExport].GetComponent <GamingMap>(); if (gamingMap != null) { gamingMap.Init(mapId, map.Uid, m_GamingMapName, m_GamingMapType, map.GetAreaSpawnerList()); break; } } } SceneManager.SetActiveScene(exportScene); EditorSceneManager.SaveScene(exportScene); EditorSceneManager.CloseScene(scene, true); if (openScenes != null && openScenes.Count > 0) { for (int iOpen = 0; iOpen < openScenes.Count; iOpen++) { Scene openScene = openScenes[iOpen]; EditorSceneManager.SaveScene(openScene); EditorSceneManager.CloseScene(openScene, true); } } } GUILayout.EndVertical(); }