【m】10. StoryEditor [1.1.0] - 2026-01-08
### Added - 新增剧本设置窗口,在窗口中打开和导出剧本 ### Fixed - 修改Graph创建时的默认位置,防止热更分包导致脚本丢失报错 - 修改Graph导出时对加载器的加载逻辑,解决跨包无法加载的问题
This commit is contained in:
92
Assets/10.StoryEditor/Editor/Graph/GraphEditorTools.cs
Normal file
92
Assets/10.StoryEditor/Editor/Graph/GraphEditorTools.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.StoryEditor.Editor
|
||||
{
|
||||
public static class GraphEditorTools
|
||||
{
|
||||
public static int Popup(string content, int currentIndex, string[] options)
|
||||
{
|
||||
EditorGUILayout.LabelField( "请选择剧本所在的Package:" , EditorStyles.boldLabel ) ;
|
||||
return EditorGUILayout.Popup( currentIndex , options ) ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有Module Package
|
||||
/// </summary>
|
||||
public static List<string> GetPackages()
|
||||
{
|
||||
// 查找Modules目录
|
||||
List<string> modules = new();
|
||||
GetDirectoryPaths(Application.dataPath, modules, "Modules");
|
||||
if (modules.Count == 0)
|
||||
{
|
||||
Debug.LogError("未找到任何Modules目录");
|
||||
return new();
|
||||
}
|
||||
|
||||
// 查找package
|
||||
List<string> packages = new();
|
||||
GetDirectoryPaths(modules[0], packages, "com.");
|
||||
if (packages.Count == 0)
|
||||
{
|
||||
Debug.LogError("未找到任何Package");
|
||||
return new();
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取符合条件的目录
|
||||
/// </summary>
|
||||
/// <param name="root">查找起始目录</param>
|
||||
/// <param name="result">查找结果</param>
|
||||
/// <param name="title">筛选条件(title)</param>
|
||||
/// <param name="tail">筛选条件(tail)</param>
|
||||
private static void GetDirectoryPaths(string root, List<string> result, string title = null, string tail = null)
|
||||
{
|
||||
foreach (var dir in Directory.GetDirectories(root))
|
||||
{
|
||||
// ReSharper disable once ReplaceWithSingleAssignment.True
|
||||
var check = true;
|
||||
|
||||
// 匹配文件头
|
||||
if (!string.IsNullOrEmpty(title) && !Path.GetFileName(dir).StartsWith(title))
|
||||
{
|
||||
check = false;
|
||||
}
|
||||
// 匹配文件尾
|
||||
if (!string.IsNullOrEmpty(tail) && !Path.GetFileName(dir).EndsWith(tail))
|
||||
{
|
||||
check = false;
|
||||
}
|
||||
|
||||
if(check)
|
||||
result.Add(dir.Replace('\\', '/'));
|
||||
|
||||
// 继续往下找
|
||||
GetDirectoryPaths(dir, result, title);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetAllAssemblyNames() =>
|
||||
AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).OrderBy(n => n);
|
||||
|
||||
/// <summary>
|
||||
/// 获取继承 IResource 的所有类
|
||||
/// </summary>
|
||||
public static HashSet<string> IResourceTypes(string assembly)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assembly))
|
||||
return new();
|
||||
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == assembly);
|
||||
return asm == null ? new() : asm.GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Any(i => i.Name == nameof(IResource))).Select(t => t.Name).ToHashSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user