// 清空场景 public void ClearScene() { MS.Clear(); (ShowTopUI("GuideUI", true) as GuideUI).HideAllHints(); (ShowTopUI("InBattleUI", true) as InBattleUI).HideAllChildren(); Tips.Clear(); }
public void OnGUI() { GUILayout.BeginVertical(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); worldType = (WorldType)EditorGUILayout.EnumPopup(worldType, GUILayout.Width(100)); if (GUILayout.Button("创建新的地图块", GUILayout.Width(100), GUILayout.Height(30))) { currMapScene = new GameObject("Map" + (mapSceneList.Count + 1)).AddComponent <MapScene>(); currMapScene.offsetX = offsetX; currMapScene.offsetY = offsetY; currMapScene.mapSizeX = mapSizeX; currMapScene.mapSizeY = mapSizeY; currMapScene.worldType = worldType; mapSceneList.Add(currMapScene); FreshResource(); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图宽度:", GUILayout.Width(60)); mapSizeX = EditorGUILayout.IntField(mapSizeX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图高度:", GUILayout.Width(60)); mapSizeY = EditorGUILayout.IntField(mapSizeY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移X:", GUILayout.Width(60)); offsetX = EditorGUILayout.IntField(offsetX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移Y:", GUILayout.Width(60)); offsetY = EditorGUILayout.IntField(offsetY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); GUILayout.Label("当前选中的地图块: " + (currMapScene == null ? "无" : currMapScene.name), GUILayout.Width(200)); if (currMapScene != null) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("地图宽度:" + currMapScene.mapSizeX, GUILayout.Width(100)); GUILayout.Label("地图高度:" + currMapScene.mapSizeY, GUILayout.Width(100)); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移X:", GUILayout.Width(60)); currMapScene.offsetX = EditorGUILayout.IntField(currMapScene.offsetX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移Y:", GUILayout.Width(60)); currMapScene.offsetY = EditorGUILayout.IntField(currMapScene.offsetY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.BeginHorizontal(); if (GUILayout.Button("更新物理碰撞", GUILayout.Width(90), GUILayout.Height(30))) { for (int i = 0; i < mapSceneList.Count; i++) { mapSceneList[i].UpdateCollider(); } } if (GUILayout.Button("清除当前地图块", GUILayout.Width(90), GUILayout.Height(30))) { if (currMapScene != null) { currMapScene.Clear(); } mapSceneList.Remove(currMapScene); currMapScene = null; if (mapSceneList.Count > 0) { currMapScene = mapSceneList[0]; } } if (GUILayout.Button("保存世界地图", GUILayout.Width(90), GUILayout.Height(30))) { EditorApplication.SaveScene(EditorApplication.currentScene); SaveSceneAsset(); } if (GUILayout.Button("加载世界地图", GUILayout.Width(90), GUILayout.Height(30))) { LoadSceneAsset(); } GUILayout.EndHorizontal(); toolSelected = (MapTool)GUILayout.Toolbar((int)toolSelected, toolIcons, GUILayout.Width(160), GUILayout.Height(30)); if (currMapScene != null && mapResouceList != null) { GUILayout.BeginVertical(); int count = 0; for (int i = 0; i < mapResouceList.Count; i++) { if (mapResouceList[i].worldType != WorldType.None && mapResouceList[i].worldType != currMapScene.worldType) { continue; } if (count % 7 == 0) { GUILayout.BeginHorizontal(); } Sprite sprite = (mapResouceList[i].isPrefab ? (mapResouceList[i].GetComponentInChildren <SpriteRenderer>().sprite) : ((mapResouceList[i].isNine ? mapResouceList[i].center[0] : mapResouceList[i].normalList[0]).sprite)); var croppedTexture = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height); var pixels = sprite.texture.GetPixels((int)sprite.textureRect.x, (int)sprite.textureRect.y, (int)sprite.textureRect.width, (int)sprite.textureRect.height); croppedTexture.SetPixels(pixels); croppedTexture.Apply(); if (GUILayout.Button(croppedTexture, GUILayout.Width(60), GUILayout.Height(60))) { selectedTile = mapResouceList[i]; if (toolSelected == MapTool.Clear) { toolSelected = MapTool.Draw; } } if ((count + 1) % 7 == 0) { GUILayout.EndHorizontal(); } count++; } GUILayout.EndVertical(); } GUILayout.EndVertical(); }