112 lines
4.4 KiB
C#
112 lines
4.4 KiB
C#
|
|
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();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|