380 lines
14 KiB
C#
380 lines
14 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using CEditor.FightStory.Handle;
|
||
using cfg.FightCfg;
|
||
using cfg.LevelCfg;
|
||
using Framework;
|
||
using Gameplay.Fight.FightStory.Data;
|
||
using Gameplay.Fight.FightStory.WrapData;
|
||
using Gameplay.Level.Data;
|
||
using Gameplay.Utils;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
namespace CEditor.FightStory
|
||
{
|
||
public class FightStoryWindow : EditorWindow
|
||
{
|
||
|
||
private FightStoryData _storyData;
|
||
|
||
private string _jsonPath;
|
||
private Vector2 _scrollPos1;
|
||
|
||
private Dictionary<string, bool> _foldState = new Dictionary<string, bool>();
|
||
|
||
public static void ShowWindow(string jsonName)
|
||
{
|
||
var window = EditorWindow.GetWindow<FightStoryWindow>();
|
||
window._jsonPath = PathEx.GetFightStoryJsonPath(jsonName);
|
||
window.titleContent = new GUIContent("剧情编辑器");
|
||
window.Show();
|
||
}
|
||
|
||
private void OnGUI()
|
||
{
|
||
_InitData();
|
||
|
||
_ShowTitle();
|
||
|
||
_scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1);
|
||
GUILayout.BeginVertical();
|
||
_ShowNPCInfos();
|
||
_ShowPreStory();
|
||
_ShowDuringStory();
|
||
_ShowEndSuccessStory();
|
||
_ShowEndFailedStory();
|
||
|
||
GUILayout.Space(40);
|
||
GUILayout.EndVertical();
|
||
EditorGUILayout.EndScrollView();
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
_storyData = null;
|
||
}
|
||
|
||
private bool _GetFoldState(string key)
|
||
{
|
||
return _foldState.GetValueOrDefault(key, false);
|
||
}
|
||
|
||
private void _SetFoldState(string key, bool value)
|
||
{
|
||
_foldState[key] = value;
|
||
}
|
||
|
||
private void _ShowDuringStory()
|
||
{
|
||
GUILayout.Label("战斗中剧情");
|
||
|
||
for (int i = 0; i < _storyData.duringFightStageList.Count; i++)
|
||
{
|
||
var stageData = _storyData.duringFightStageList[i];
|
||
GUILayout.BeginHorizontal();
|
||
var foldKey = "duringFightStageList" + i;
|
||
var foldState = _GetFoldState(foldKey);
|
||
foldState = EditorGUILayout.Foldout(foldState, "第" + i + "个剧情");
|
||
_SetFoldState(foldKey, foldState);
|
||
if (GUILayout.Button("删除"))
|
||
{
|
||
_storyData.duringFightStageList.RemoveAt(i);
|
||
i--;
|
||
}
|
||
GUILayout.EndHorizontal();
|
||
|
||
if (foldState)
|
||
{
|
||
_ShowFightStoryStageData(stageData);
|
||
GUILayout.Space(10);
|
||
}
|
||
}
|
||
|
||
if (GUILayout.Button("添加战斗中剧情", GUILayout.Height(40)))
|
||
{
|
||
_storyData.duringFightStageList.Add(new FightStoryStageData());
|
||
}
|
||
}
|
||
|
||
private void _ShowFightStoryStageData(FightStoryStageData stageData)
|
||
{
|
||
GUILayout.Label("触发条件:");
|
||
TriggerDataHandle.HandleTriggerData(stageData);
|
||
|
||
GUILayout.Space(10);
|
||
GUILayout.Label("剧情内容:");
|
||
_ShowStoryActions(stageData.actionList);
|
||
}
|
||
|
||
private void _ShowEndFailedStory()
|
||
{
|
||
_storyData.hasAfterFailStage = EditorGUILayout.ToggleLeft("是否有战后失败剧情", _storyData.hasAfterFailStage);
|
||
if (_storyData.hasAfterFailStage)
|
||
{
|
||
if (_storyData.afterFailStageData == null)
|
||
{
|
||
_storyData.afterFailStageData = new FightStoryStageData();
|
||
}
|
||
|
||
var foldKey = "hasAfterFailStage";
|
||
var foldState = _GetFoldState(foldKey);
|
||
foldState = EditorGUILayout.Foldout(foldState, "战后剧情");
|
||
_SetFoldState(foldKey, foldState);
|
||
if (foldState)
|
||
{
|
||
_ShowStoryActions(_storyData.afterFailStageData.actionList);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void _ShowEndSuccessStory()
|
||
{
|
||
_storyData.hasAfterSuccessStage = EditorGUILayout.ToggleLeft("是否有战后胜利剧情", _storyData.hasAfterSuccessStage);
|
||
if (_storyData.hasAfterSuccessStage)
|
||
{
|
||
if (_storyData.afterSuccessStageData == null)
|
||
{
|
||
_storyData.afterSuccessStageData = new FightStoryStageData();
|
||
}
|
||
|
||
var foldKey = "hasAfterSuccessStage";
|
||
var foldState = _GetFoldState(foldKey);
|
||
foldState = EditorGUILayout.Foldout(foldState, "战后剧情");
|
||
_SetFoldState(foldKey, foldState);
|
||
if (foldState)
|
||
{
|
||
_ShowStoryActions(_storyData.afterSuccessStageData.actionList);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void _ShowPreStory()
|
||
{
|
||
_storyData.hasBeforeFightStage = EditorGUILayout.ToggleLeft("是否有战前剧情", _storyData.hasBeforeFightStage);
|
||
if (_storyData.hasBeforeFightStage)
|
||
{
|
||
if (_storyData.beforeFightStageData == null)
|
||
{
|
||
_storyData.beforeFightStageData = new FightStoryStageData();
|
||
}
|
||
|
||
var foldKey = "beforeFightStageData";
|
||
var foldState = _GetFoldState(foldKey);
|
||
foldState = EditorGUILayout.Foldout(foldState, "战前剧情");
|
||
_SetFoldState(foldKey, foldState);
|
||
if (foldState)
|
||
{
|
||
_ShowStoryActions(_storyData.beforeFightStageData.actionList);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
private void _ShowStoryActions(List<FightStoryActionData> actionDataList)
|
||
{
|
||
|
||
for (int i = 0; i < actionDataList.Count; i++)
|
||
{
|
||
var actionData = actionDataList[i];
|
||
GUILayout.BeginHorizontal();
|
||
GUILayout.BeginVertical();
|
||
ActionDataHandle.HandleActionData(actionData);
|
||
GUILayout.EndVertical();
|
||
if (GUILayout.Button("删除"))
|
||
{
|
||
actionDataList.RemoveAt(i);
|
||
i--;
|
||
}
|
||
GUILayout.EndHorizontal();
|
||
GUILayout.Space(10);
|
||
}
|
||
|
||
if (GUILayout.Button("添加action", GUILayout.Height(40)))
|
||
{
|
||
actionDataList.Add(new FightStoryActionData());
|
||
}
|
||
}
|
||
|
||
private void _ShowTitle()
|
||
{
|
||
GUILayout.BeginHorizontal();
|
||
GUILayout.Label("文件:" + _jsonPath);
|
||
if (GUILayout.Button("保存"))
|
||
{
|
||
var jsonStr = JsonUtility.ToJson(_storyData, true);
|
||
var realPath = PathEx.GetRealPath(_jsonPath);
|
||
File.WriteAllText(realPath, jsonStr);
|
||
|
||
// 弹出提示
|
||
if (EditorUtility.DisplayDialog("保存成功", "保存成功", "确定"))
|
||
{
|
||
AssetDatabase.Refresh();
|
||
}
|
||
}
|
||
GUILayout.EndHorizontal();
|
||
}
|
||
|
||
private void _ShowNPCInfos()
|
||
{
|
||
GUILayout.Label("准备NPC信息");
|
||
|
||
_storyData.forceUserTeam = EditorGUILayout.ToggleLeft("是否强制指定玩家队伍", _storyData.forceUserTeam);
|
||
|
||
if (_storyData.forceUserTeam)
|
||
{
|
||
if (_storyData.playerTeamData == null)
|
||
{
|
||
_storyData.playerTeamData = new FightStoryTeamData();
|
||
}
|
||
|
||
var foldKey = "playerTeamData";
|
||
var foldState = _GetFoldState(foldKey);
|
||
foldState = EditorGUILayout.Foldout(foldState, "玩家队伍信息");
|
||
_SetFoldState(foldKey, foldState);
|
||
if (foldState)
|
||
{
|
||
GUILayout.BeginHorizontal();
|
||
|
||
GUILayout.Label("队长ID:", GUILayout.Width(60));
|
||
_storyData.playerTeamData.leaderId = EditorGUILayout.IntField(_storyData.playerTeamData.leaderId);
|
||
GUILayout.EndHorizontal();
|
||
|
||
var monsterConfig = EditorTableManager.instance.tables.Monster.GetOrDefault(_storyData.playerTeamData.leaderId);
|
||
if (monsterConfig == null)
|
||
{
|
||
EditorGUILayout.HelpBox("没有找到对应的怪物配置:" + _storyData.playerTeamData.leaderId, MessageType.Error);
|
||
}
|
||
else if (monsterConfig.NpcType != EMonsterType.SelfCharacter)
|
||
{
|
||
EditorGUILayout.HelpBox("队长的NpcType类型必须是(ENpcType.SELF_NPC)2", MessageType.Error);
|
||
}
|
||
else
|
||
{
|
||
var npcConfig = EditorTableManager.instance.tables.FightNPCConfig.GetOrDefault(monsterConfig.MonsterClassID);
|
||
if (npcConfig == null)
|
||
{
|
||
EditorGUILayout.HelpBox("没有找到对应的NPC配置:" + _storyData.playerTeamData.leaderId, MessageType.Error);
|
||
}
|
||
else
|
||
{
|
||
_ShowDetailTeamInfo(npcConfig);
|
||
}
|
||
}
|
||
|
||
GUILayout.Space(10);
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
private void _ShowDetailTeamInfo(DataFightNPC npcConfig)
|
||
{
|
||
var provideJobs = npcConfig.ProvideJob;
|
||
if (_storyData.playerTeamData.memberList.Count != provideJobs.Length + 1)
|
||
{
|
||
_storyData.playerTeamData.memberList.Clear();
|
||
for (int i = 0; i < provideJobs.Length + 1; i++)
|
||
{
|
||
_storyData.playerTeamData.memberList.Add(new FightStoryNpcData());
|
||
}
|
||
}
|
||
GUILayout.Space(10);
|
||
|
||
_storyData.playerTeamData.memberList[0].monsterId = _storyData.playerTeamData.leaderId;
|
||
_ShowNpcInfo(_storyData.playerTeamData.memberList[0], "队长位:");
|
||
for (int i = 1; i < _storyData.playerTeamData.memberList.Count; i++)
|
||
{
|
||
var job = provideJobs[i - 1];
|
||
var npcInfo = _storyData.playerTeamData.memberList[i];
|
||
GUILayout.Space(10);
|
||
_ShowNpcInfo(npcInfo, "位置:" + i + " 职业:" + (int)job);
|
||
}
|
||
}
|
||
|
||
private void _ShowNpcInfo(FightStoryNpcData npcData,
|
||
string titleName)
|
||
{
|
||
GUILayout.BeginHorizontal();
|
||
|
||
GUILayout.Label(titleName);
|
||
npcData.monsterId = EditorGUILayout.IntField(npcData.monsterId);
|
||
npcData.unitLocalId = EditorGUILayout.IntField(npcData.unitLocalId);
|
||
|
||
GUILayout.EndHorizontal();
|
||
|
||
_NpcErrorCheck(npcData);
|
||
}
|
||
|
||
private void _NpcErrorCheck(FightStoryNpcData npcData)
|
||
{
|
||
if (npcData.monsterId != 0)
|
||
{
|
||
var monsterConfig = EditorTableManager.instance.tables.Monster.GetOrDefault(npcData.monsterId);
|
||
if (monsterConfig == null)
|
||
{
|
||
EditorGUILayout.HelpBox("没有找到对应的怪物配置:" + npcData.monsterId, MessageType.Error);
|
||
return;
|
||
}
|
||
|
||
switch (monsterConfig.NpcType)
|
||
{
|
||
case EMonsterType.SelfCharacter:
|
||
var npcConfig = EditorTableManager.instance.tables.FightNPCConfig.GetOrDefault(monsterConfig.MonsterClassID);
|
||
if (npcConfig == null)
|
||
{
|
||
EditorGUILayout.HelpBox("没有找到对应的NPC配置:" + npcData.monsterId, MessageType.Error);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
GUILayout.Label("NPC名字: " + npcConfig.NameRead + " 职业:" + (int)npcConfig.Job);
|
||
}
|
||
break;
|
||
case EMonsterType.Vehicle:
|
||
var vehicleConfig = EditorTableManager.instance.tables.VehicleConfig.GetOrDefault(monsterConfig.MonsterClassID);
|
||
if (vehicleConfig == null)
|
||
{
|
||
EditorGUILayout.HelpBox("没有找到对应的载具配置:" + npcData.monsterId, MessageType.Error);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
GUILayout.Label("载具名字: " + vehicleConfig.Name);
|
||
}
|
||
break;
|
||
|
||
default:
|
||
EditorGUILayout.HelpBox("NPC类型错误:" + monsterConfig.NpcType, MessageType.Error);
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GUILayout.Label("玩家自由配置");
|
||
}
|
||
}
|
||
|
||
private void _InitData()
|
||
{
|
||
if (_storyData != null) return;
|
||
// 先判断有没有json数据
|
||
// 获取当前场景的名字
|
||
var realPath = PathEx.GetRealPath(_jsonPath);
|
||
if (File.Exists(realPath))
|
||
{
|
||
var loadJsonStr = File.ReadAllText(realPath);
|
||
_storyData = JsonUtility.FromJson<FightStoryData>(loadJsonStr);
|
||
}
|
||
|
||
if (_storyData == null)
|
||
{
|
||
Debug.Log("没有找到剧情数据, 创建新的剧情数据");
|
||
_storyData = new FightStoryData();
|
||
}
|
||
}
|
||
}
|
||
}
|