Files
plugin-library/Assets/10.StoryEditor/Editor/Graph/GraphExportWindow.cs
mzh f5a79aabf8 【m】10. StoryEditor [1.1.0] - 2026-01-08
### Added
- 新增剧本设置窗口,在窗口中打开和导出剧本
### Fixed
- 修改Graph创建时的默认位置,防止热更分包导致脚本丢失报错
- 修改Graph导出时对加载器的加载逻辑,解决跨包无法加载的问题
2026-01-08 17:31:26 +08:00

112 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using XNodeEditor;
namespace Stary.Evo.StoryEditor.Editor
{
public class GraphExportWindow : EditorWindow
{
private string[] _options = Array.Empty<string>();
private Dictionary<string, string> _paths = new();
private int _selectedIndex;
private int _selectedStoryIndex;
private ScriptGraph _selectedStory;
private int _selectedAssemblyIndex;
private int _selectedLoaderIndex;
[MenuItem("Evo/剧本编辑器/打开剧本")]
private static void Open()
{
// 打开一个浮动窗口
GetWindow<GraphExportWindow>( "剧本配置" ) ;
}
private void OnEnable()
{
minSize = maxSize = new Vector2(300, 400);
// 记录Package地址并返回选项
var packages = GraphEditorTools.GetPackages();
_paths.Clear();
packages.ForEach(path => _paths.Add(Path.GetFileName(path), path));
_options = _paths.Keys.ToArray();
}
private void OnGUI()
{
GUILayout.Space(15);
EditorGUILayout.BeginHorizontal();
GUILayout.Space(10);
EditorGUILayout.BeginVertical();
// Package选项
_selectedIndex = GraphEditorTools.Popup("请选择剧本所在的Package", _selectedIndex, _options);
GUILayout.Space(15);
// 显示已有剧本
try
{
string[] storys;
var packageID = _options[_selectedIndex];
var graphDir = Path.Combine(Application.dataPath, "StoryEditor", "Graphs",
$"{(string.IsNullOrEmpty(packageID) ? "default" : packageID)}");
if (!Directory.Exists(graphDir))
{
storys = Array.Empty<string>();
}
else
{
// 选择剧本
var guids = AssetDatabase.FindAssets($"t:{nameof(ScriptGraph)}");
var allAssets = guids.Select(AssetDatabase.GUIDToAssetPath)
.Select(AssetDatabase.LoadAssetAtPath<ScriptGraph>)
.ToArray();
storys = allAssets.Select(asset => asset.name).ToArray();
_selectedStoryIndex = GraphEditorTools.Popup("请选择剧本:", _selectedStoryIndex, storys);
_selectedStory = allAssets[_selectedStoryIndex];
GUILayout.Space(15);
// 打开剧本按钮
if (GUILayout.Button("打开剧本"))
{
var win = GetWindow<NodeEditorWindow> (false, _selectedStory.name);
win.graph = _selectedStory;
}
GUILayout.Space(15);
// 选择程序集
var assemblyNames = GraphEditorTools.GetAllAssemblyNames().ToArray();
_selectedAssemblyIndex = GraphEditorTools.Popup("请选择加载器所在的程序集:", _selectedAssemblyIndex, assemblyNames);
_selectedStory.assembly = assemblyNames.Length > 0 ? assemblyNames[_selectedAssemblyIndex] : null;
GUILayout.Space(15);
// 选择加载器
var loaders = GraphEditorTools.IResourceTypes(_selectedStory.assembly).ToArray();
_selectedLoaderIndex = GraphEditorTools.Popup("请选择加载器:", _selectedLoaderIndex, loaders);
_selectedStory.loaderType = loaders.Length > 0 ? loaders[_selectedLoaderIndex] : null;
GUILayout.Space(15);
// 导出剧本按钮
if (GUILayout.Button("导出剧本"))
{
_selectedStory.Export();
}
}
}
catch (Exception e)
{
Debug.LogException(e);
}
EditorGUILayout.EndVertical();
GUILayout.Space(10);
EditorGUILayout.EndHorizontal();
}
}
}