/// <summary> /// 读取json数据 /// </summary> /// <param name="mapArea"></param> private void ReadJsonData(GamingMapArea mapArea) { if (mapArea == null) { return; } EditorGamingMap gamingMap = EditorGamingMapData.LoadGamingMapFromJson(mapArea.GetGamingMapId()); if (gamingMap != null) { EditorArea[] areas = gamingMap.areaList; if (areas != null && areas.Length > 0) { for (int iArea = 0; iArea < areas.Length; iArea++) { EditorArea area = areas[iArea]; if (area.areaId == mapArea.m_AreaId) { mapArea.Init(area, this); } } } } }
/// <summary> /// 创建区域 /// </summary> /// <param name="area"></param> private GamingMapArea CreateArea(EditorArea area) { GameObject areaObj = new GameObject(); areaObj.transform.SetParent(transform); GamingMapArea mapArea = areaObj.AddComponent <GamingMapArea>(); mapArea.Init(area, this); return(mapArea); }
/// <summary> /// 创建GameArea /// </summary> /// <param name="areaSpawner"></param> private void CreateGamingArea(AreaSpawner areaSpawner) { string areaTemplete = ""; GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting(); if (gamingSetting != null) { areaTemplete = gamingSetting.m_GamingAreaTemplete; } GameObject areaTempleteAsset = AssetDatabase.LoadAssetAtPath <GameObject>(areaTemplete); GameObject obj = Instantiate(areaTempleteAsset); obj.name = string.Format("Area_{0}", areaSpawner.GetAreaId()); obj.transform.SetParent(transform); GamingMapArea area = obj.GetComponent <GamingMapArea>(); if (area == null) { area = obj.AddComponent <GamingMapArea>(); } area.Init(areaSpawner, this); m_GamingAreaList.Add(area); }
public void LoadGamingMapArea(AreaSpawner areaSpawner, bool closeOtherArea = true) { if (areaSpawner == null) { return; } string m_AreaScenePath = string.Format("{0}/GamingMapArea_{1}_{2}.unity", GetOwnerAreaPath(), m_Uid, areaSpawner.GetAreaId()); if (string.IsNullOrEmpty(m_AreaScenePath)) { Debug.LogError("m_AreaScenePath == null"); return; } GamingMapArea[] areaArray = UnityEngine.Object.FindObjectsOfType <GamingMapArea>(); if (areaArray != null && areaArray.Length > 0) { for (int iArea = 0; iArea < areaArray.Length; iArea++) { GamingMapArea area = areaArray[iArea]; if (area != null && area.m_AreaId == areaSpawner.GetAreaId()) { //Debug.LogError(string.Format("{0}Area已导入", area.m_AreaId)); return; } } } if (closeOtherArea) { SaveOtherGamingArea(); } string areaScenePath = m_AreaScenePath.Replace("Assets", Application.dataPath); Scene areaScene; if (!File.Exists(areaScenePath)) { string gamingAreaPath = ""; GamingMapEditorSetting gamingSetting = GamingMapEditorUtility.GetGamingMapEditorSetting(); if (gamingSetting != null) { gamingAreaPath = gamingSetting.m_GamingAreaTemplete; } areaScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive); GameObject areaTempleteAsset = AssetDatabase.LoadAssetAtPath <GameObject>(gamingAreaPath); GameObject gamingArea = GameObject.Instantiate(areaTempleteAsset); GamingMapArea mapArea = gamingArea.GetComponent <GamingMapArea>(); mapArea.Init(areaSpawner, this); EditorSceneManager.MoveGameObjectToScene(gamingArea, areaScene); EditorSceneManager.SaveScene(areaScene, m_AreaScenePath); EditorSceneManager.CloseScene(areaScene, true); AssetDatabase.Refresh(); } areaScene = EditorSceneManager.OpenScene(m_AreaScenePath, OpenSceneMode.Additive); if (areaScene != null) { GamingMapArea mapArea = null; GameObject[] rootObjs = areaScene.GetRootGameObjects(); if (rootObjs != null && rootObjs.Length > 0) { for (int rIndex = 0; rIndex < rootObjs.Length; rIndex++) { mapArea = rootObjs[rIndex].GetComponent <GamingMapArea>(); if (mapArea != null) { break; } } } if (mapArea != null) { EditorSceneManager.MoveGameObjectToScene(mapArea.gameObject, GetOwnerScene()); mapArea.transform.SetParent(transform); } EditorSceneManager.CloseScene(areaScene, true); } }