/// <summary> /// 点击退出设置按钮 /// </summary> public void ExitSetting_Click() { if (nowUIFocus) { nowUIFocus.LostForcus(); } bigMapOperateState = EnumBigMapOperateState.OperateMap; //根据当前的设置更新状态 UIFocusDropdown thisFocus = uiFocusPath.NewUIFocusArray.Where(temp => string.Equals(temp.Tag, "SceneDropDown")).FirstOrDefault() as UIFocusDropdown; if (thisFocus != null) { int index = thisFocus.dropdown.value; if (index >= 0) { SceneData sceneData = DataCenter.Instance.GetMetaData <SceneData>(); SceneDataInfo[] sceneDataInfos = sceneData.GetAllSceneData(); List <string> sceneNameList = sceneDataInfos.Where(temp => temp.SceneAction == EnumSceneAction.Game).Select(temp => temp.SceneName).ToList(); string selectSceneName = sceneNameList[index]; if (!string.Equals(nowSceneName, selectSceneName))//当前地图显示的和选择的场景不一致则重新载入 { MapData mapData = DataCenter.Instance.GetMetaData <MapData>(); MapDataInfo mapDataInfo = mapData[selectSceneName]; if (mapDataInfo != null) { mapDataInfo.Load(); PlayerState playerState = DataCenter.Instance.GetEntity <PlayerState>(); Sprite mapMaskSprite = playerState.GetSceneMapMaskSprite(selectSceneName, mapDataInfo.MapSprite); ResetMap(mapDataInfo.MapSprite, mapMaskSprite, mapDataInfo.SceneRect, selectSceneName); } } } } }
private void OnGUI() { EditorGUILayout.BeginHorizontal(); //左侧具体的场景 EditorGUILayout.BeginVertical(GUILayout.Width(135)); if (GUILayout.Button("保存")) { string valueText = SerializeNow(sceneToMapDataDic); File.WriteAllText(dataDirectoryPath + "/Map.txt", valueText, Encoding.UTF8); EditorUtility.DisplayDialog("保存数据", "保存成功!", "确认"); } EditorGUILayout.LabelField("场景名"); tempSceneName = EditorGUILayout.TextField(tempSceneName); if (!string.IsNullOrEmpty(tempSceneName)) { if (!sceneToMapDataDic.ContainsKey(tempSceneName)) { if (GUILayout.Button("添加")) { if (EditorUtility.DisplayDialog("提示!", "是否添加该场景的数据", "确认添加", "取消添加")) { sceneToMapDataDic.Add(tempSceneName, new MapDataInfo()); } } } } EditorGUILayout.Space(); leftScroll = EditorGUILayout.BeginScrollView(leftScroll); KeyValuePair <string, MapDataInfo>[] values = new KeyValuePair <string, MapDataInfo> [0]; if (string.IsNullOrEmpty(tempSceneName)) { values = sceneToMapDataDic.OfType <KeyValuePair <string, MapDataInfo> >().ToArray(); } else { values = sceneToMapDataDic.Where(temp => temp.Key.Contains(tempSceneName)).ToArray(); } foreach (KeyValuePair <string, MapDataInfo> value in values) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("×", GUILayout.Width(20))) { if (EditorUtility.DisplayDialog("警告!", "是否删除该场景名的数据", "确认删除", "取消删除")) { sceneToMapDataDic.Remove(value.Key); } } string newKey = EditorGUILayout.TextField(value.Key, GUILayout.Width(80)); if (!string.Equals(value.Key, newKey) && !string.IsNullOrEmpty(newKey)) { if (sceneToMapDataDic.ContainsKey(value.Key) && !sceneToMapDataDic.ContainsKey(newKey)) { sceneToMapDataDic.Remove(value.Key); sceneToMapDataDic.Add(newKey, value.Value); } } bool isCheck = object.Equals(tempMapDataInfo, value.Value); isCheck = EditorGUILayout.Toggle(isCheck, GUILayout.Width(25)); if (isCheck) { tempMapDataInfo = value.Value; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); //游戏详细的设置 EditorGUILayout.BeginVertical(); if (tempMapDataInfo != null && sceneToMapDataDic.ContainsValue(tempMapDataInfo)) { string thisSceneName = sceneToMapDataDic.Where(temp => object.Equals(temp.Value, tempMapDataInfo)).Select(temp => temp.Key).FirstOrDefault(); if (!string.IsNullOrEmpty(thisSceneName)) { if (GUILayout.Button("刷新精灵库") && EditorUtility.DisplayDialog("请再次确认", "是否刷新?", "是", "否")) { SpriteManager.Load(); } ReflectUnit <MapDataInfo> mapDataInfoUnit = Entry.On(tempMapDataInfo); //设置场景名 if (!string.Equals(tempMapDataInfo.SceneName, thisSceneName)) { mapDataInfoUnit.Field("sceneName", thisSceneName).End(); } EditorGUILayout.LabelField("场景名:" + tempMapDataInfo.SceneName); //设置边界 Rect sceneRect = EditorGUILayout.RectField("场景边界:", tempMapDataInfo.SceneRect); if (!Rect.Equals(sceneRect, tempMapDataInfo.SceneRect)) { mapDataInfoUnit.Set("SceneRect", sceneRect).End(); } //设置地图图片 tempMapDataInfo.Load(); Sprite mapSprite = (Sprite)EditorGUILayout.ObjectField("场景的地图:", tempMapDataInfo.MapSprite, typeof(Sprite), true); if (!Sprite.Equals(mapSprite, tempMapDataInfo.MapSprite) && mapSprite != null) { string mapSpriteID = SpriteManager.GetName(mapSprite); mapDataInfoUnit.Field("mapSpriteID", mapSpriteID).End(); tempMapDataInfo.Load(true); } } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
/// <summary> /// 更改场景 /// </summary> /// <param name="sceneName">场景名</param> /// <param name="playerLocation">玩家的位置</param> /// <param name="LoadResultAction">加载结果回调</param> public void ChangedScene(string sceneName, Vector3 playerLocation, Action <bool> LoadResultAction = null) { GameRunType = EnumGameRunType.Start;//切换场景时当前的状态为开始状态 //如果要切换的场景不是当前场景则加载场景 if (SceneName != sceneName) { //保存原来地形的遮罩图 if (!string.IsNullOrEmpty(SceneName)) { playerState.SaveGetSceneMapMaskData(SceneName); } //开始加载 UIChangeScene.Instance.LoadScene(sceneName, result => { //自身调用初始化数据 Debug.Log("需要调用自身的函数实现数据的初始化,如地图显示,npc位置等一系列的数据"); //加载地图的图片以及遮罩资源 IMapState iMapState = GetEntity <IMapState>(); MapData mapData = DataCenter.Instance.GetMetaData <MapData>(); MapDataInfo mapDataInfo = mapData[sceneName]; if (mapDataInfo != null) { mapDataInfo.Load(); iMapState.MapBackSprite = mapDataInfo.MapSprite; Sprite mapMaskSprite = playerState.GetSceneMapMaskSprite(sceneName, mapDataInfo.MapSprite); iMapState.MaskMapSprite = mapMaskSprite; iMapState.MapRectAtScene = mapDataInfo.SceneRect; } //初始化npc与npc的位置 NPCData npcData = DataCenter.Instance.GetMetaData <NPCData>(); NPCDataInfo[] npcDataInfos = npcData.GetNPCDataInfos(sceneName); foreach (NPCDataInfo npcDataInfo in npcDataInfos) { npcDataInfo.Load();//切换场景时有时候会导致游戏对象被删除,需要重新Load } //初始化采集点与采集点的位置 StuffData stuffData = DataCenter.Instance.GetMetaData <StuffData>(); StuffDataInfo[] stuffDataInfos = stuffData.GetStuffDataInfos(sceneName); foreach (StuffDataInfo stuffDataInfo in stuffDataInfos) { stuffDataInfo.Load();//切换场景时有时候会导致游戏对象被删除,需要重新Load } //初始化功能交互对象 ActionInteractiveData actionInteractiveData = DataCenter.Instance.GetMetaData <ActionInteractiveData>(); ActionInteractiveDataInfo[] actionInteractiveDataInfos = actionInteractiveData.GetActionInteractiveDataInfos(sceneName); foreach (ActionInteractiveDataInfo actionInteractiveDataInfo in actionInteractiveDataInfos) { actionInteractiveDataInfo.Load();//切换场景时有时候会导致游戏对象被删除,需要重新Load } //创建UI GameObject mainCanvasPrefab = Resources.Load <GameObject>("UI/MainCanvas"); GameObject.Instantiate(mainCanvasPrefab); //创建玩家操纵的游戏对象 GameObject playerPrefab = Resources.Load <GameObject>("Prefabs/Player"); GameObject.Instantiate(playerPrefab); //更改过后修改玩家位置 PlayerObj.transform.position = playerLocation; //回调 if (LoadResultAction != null) { LoadResultAction(result); } SceneName = sceneName; GameRunType = EnumGameRunType.Safe; //场景变换回调 Call <IGameState, Action <string, Vector3, Action <bool> > >(temp => temp.ChangedScene); }); } else//如果不需要切换场景则直接更改玩家位置即可 { UIChangeScene.Instance.MovePlayer(3, result => { GameRunType = EnumGameRunType.Safe; //场景变换回调 Call <IGameState, Action <string, Vector3, Action <bool> > >(temp => temp.ChangedScene); }); //更改过后修改玩家位置 PlayerObj.transform.position = playerLocation; //关闭当前按显示的UI IInteractiveState iInteractiveState = GameState.Instance.GetEntity <IInteractiveState>(); iInteractiveState.ActionObj.SetActive(false); } }