183 lines
6.0 KiB
C#
183 lines
6.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using cfg.FightCfg;
|
|
using Framework;
|
|
using Gameplay.Fight.FightStory.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 void OnGUI()
|
|
{
|
|
_InitData();
|
|
|
|
_ShowTitle();
|
|
|
|
_scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1);
|
|
GUILayout.BeginVertical();
|
|
_ShowNPCInfos();
|
|
_ShowPreStory();
|
|
|
|
GUILayout.EndVertical();
|
|
EditorGUILayout.EndScrollView();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_storyData = null;
|
|
}
|
|
|
|
private void _ShowPreStory()
|
|
{
|
|
_storyData.hasBeforeFightStage = EditorGUILayout.ToggleLeft("是否有战前剧情", _storyData.hasBeforeFightStage);
|
|
if (_storyData.hasBeforeFightStage)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
GUILayout.BeginHorizontal();
|
|
|
|
GUILayout.Label("队长ID:", GUILayout.Width(60));
|
|
_storyData.playerTeamData.leaderId = EditorGUILayout.IntField(_storyData.playerTeamData.leaderId);
|
|
GUILayout.EndHorizontal();
|
|
|
|
var npcConfig = EditorTableManager.instance.tables.FightNPCConfig.GetOrDefault(_storyData.playerTeamData.leaderId);
|
|
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].npcConfigId = _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.npcConfigId = EditorGUILayout.IntField(npcData.npcConfigId);
|
|
npcData.unitLocalId = EditorGUILayout.IntField(npcData.unitLocalId);
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
_NpcErrorCheck(npcData);
|
|
}
|
|
|
|
private void _NpcErrorCheck(FightStoryNpcData npcData)
|
|
{
|
|
if (npcData.npcConfigId != 0)
|
|
{
|
|
var npcConfig = EditorTableManager.instance.tables.FightNPCConfig.GetOrDefault(npcData.npcConfigId);
|
|
if (npcConfig == null)
|
|
{
|
|
EditorGUILayout.HelpBox("没有找到对应的NPC配置:" + npcData.npcConfigId, MessageType.Error);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
GUILayout.Label("NPC名字: " + npcConfig.NameRead + " 职业:" + (int)npcConfig.Job);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GUILayout.Label("玩家自由配置");
|
|
}
|
|
}
|
|
|
|
private void _InitData()
|
|
{
|
|
if (_storyData != null) return;
|
|
// 先判断有没有json数据
|
|
// 获取当前场景的名字
|
|
var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
|
var jsonPath = PathEx.GetFightStoryJsonPath(sceneName);
|
|
_jsonPath = jsonPath;
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|