Skip to content

Commit 25cbe34

Browse files
committed
新增:CustomModule自定义模块。
1 parent 5e760a5 commit 25cbe34

21 files changed

+547
-22
lines changed

Editor/CustomModule.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using System.Reflection;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace HT.Framework
7+
{
8+
[CustomEditor(typeof(CustomModuleManager))]
9+
[GithubURL("https://github.com/SaiTingHu/HTFramework")]
10+
[CSDNBlogURL("https://wanderer.blog.csdn.net/article/details/103390089")]
11+
public sealed class CustomModuleManagerInspector : HTFEditor<CustomModuleManager>
12+
{
13+
private Dictionary<string, CustomModuleBase> _customModules;
14+
15+
protected override void OnRuntimeEnable()
16+
{
17+
base.OnRuntimeEnable();
18+
19+
_customModules = Target.GetType().GetField("_customModules", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Target) as Dictionary<string, CustomModuleBase>;
20+
}
21+
22+
protected override void OnInspectorDefaultGUI()
23+
{
24+
base.OnInspectorDefaultGUI();
25+
26+
GUILayout.BeginHorizontal();
27+
EditorGUILayout.HelpBox("Custom Module Manager, Manager of all custom modules!", MessageType.Info);
28+
GUILayout.EndHorizontal();
29+
}
30+
31+
protected override void OnInspectorRuntimeGUI()
32+
{
33+
base.OnInspectorRuntimeGUI();
34+
35+
GUILayout.BeginHorizontal();
36+
GUILayout.Label("CustomModules: " + _customModules.Count);
37+
GUILayout.EndHorizontal();
38+
39+
foreach (var item in _customModules)
40+
{
41+
GUILayout.BeginHorizontal();
42+
GUILayout.Space(20);
43+
GUILayout.Label(item.Key + "[" + item.Value.GetType().FullName + "]");
44+
GUILayout.EndHorizontal();
45+
}
46+
}
47+
}
48+
}

Editor/CustomModule/CustomModuleManagerInspector.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Utility/EditorGlobalTools.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,48 @@ private static void CreateEntityLogic()
643643
}
644644
}
645645

646+
/// <summary>
647+
/// 新建CustomModule类
648+
/// </summary>
649+
[@MenuItem("Assets/Create/HTFramework/C# CustomModule Script", false, 20)]
650+
private static void CreateCustomModule()
651+
{
652+
string directory = EditorPrefs.GetString(EditorPrefsTable.Script_CustomModule_Directory, Application.dataPath);
653+
string path = EditorUtility.SaveFilePanel("新建 CustomModule 类", directory, "NewCustomModule", "cs");
654+
if (path != "")
655+
{
656+
string className = path.Substring(path.LastIndexOf("/") + 1).Replace(".cs", "");
657+
if (!File.Exists(path))
658+
{
659+
TextAsset asset = AssetDatabase.LoadAssetAtPath("Assets/HTFramework/Editor/Utility/Template/CustomModuleTemplate.txt", typeof(TextAsset)) as TextAsset;
660+
if (asset)
661+
{
662+
string code = asset.text;
663+
code = code.Replace("#SCRIPTNAME#", className);
664+
code = code.Replace("#MODULENAME#", className);
665+
File.AppendAllText(path, code);
666+
asset = null;
667+
AssetDatabase.Refresh();
668+
669+
string assetPath = path.Substring(path.LastIndexOf("Assets"));
670+
TextAsset cs = AssetDatabase.LoadAssetAtPath(assetPath, typeof(TextAsset)) as TextAsset;
671+
EditorGUIUtility.PingObject(cs);
672+
Selection.activeObject = cs;
673+
AssetDatabase.OpenAsset(cs);
674+
EditorPrefs.SetString(EditorPrefsTable.Script_CustomModule_Directory, path.Substring(0, path.LastIndexOf("/")));
675+
}
676+
}
677+
else
678+
{
679+
GlobalTools.LogError("新建CustomModule失败,已存在类型 " + className);
680+
}
681+
}
682+
}
683+
646684
/// <summary>
647685
/// 新建HotfixProcedure类
648686
/// </summary>
649-
[@MenuItem("Assets/Create/HTFramework/[Hotfix] C# HotfixProcedure Script", false, 40)]
687+
[@MenuItem("Assets/Create/HTFramework/[Hotfix] C# HotfixProcedure Script", false, 60)]
650688
private static void CreateHotfixProcedure()
651689
{
652690
string directory = EditorPrefs.GetString(EditorPrefsTable.Script_HotfixProcedure_Directory, Application.dataPath);
@@ -683,7 +721,7 @@ private static void CreateHotfixProcedure()
683721
/// <summary>
684722
/// 新建HotfixObject类
685723
/// </summary>
686-
[@MenuItem("Assets/Create/HTFramework/[Hotfix] C# HotfixObject Script", false, 41)]
724+
[@MenuItem("Assets/Create/HTFramework/[Hotfix] C# HotfixObject Script", false, 61)]
687725
private static void CreateHotfixObject()
688726
{
689727
string directory = EditorPrefs.GetString(EditorPrefsTable.Script_HotfixObject_Directory, Application.dataPath);
@@ -720,7 +758,7 @@ private static void CreateHotfixObject()
720758
/// <summary>
721759
/// 新建WebGL插件
722760
/// </summary>
723-
[@MenuItem("Assets/Create/HTFramework/WebGL Plugin", false, 60)]
761+
[@MenuItem("Assets/Create/HTFramework/WebGL Plugin", false, 100)]
724762
private static void CreateWebGLPlugin()
725763
{
726764
string pluginsDirectory = Application.dataPath + "/Plugins";

Editor/Utility/EditorPrefsTable.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ public static string Script_EntityLogic_Directory
9999
}
100100
}
101101
/// <summary>
102+
/// 新建CustomModule脚本的文件夹
103+
/// </summary>
104+
public static string Script_CustomModule_Directory
105+
{
106+
get
107+
{
108+
return Application.productName + ".HT.Framework.Script.CustomModule";
109+
}
110+
}
111+
/// <summary>
102112
/// 新建HotfixProcedure脚本的文件夹
103113
/// </summary>
104114
public static string Script_HotfixProcedure_Directory
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using HT.Framework;
5+
using DG.Tweening;
6+
/// <summary>
7+
/// 新建自定义模块
8+
/// </summary>
9+
[CustomModule("#MODULENAME#", true)]
10+
public class #SCRIPTNAME# : CustomModuleBase
11+
{
12+
/// <summary>
13+
/// 初始化模块
14+
/// </summary>
15+
public override void OnInitialization()
16+
{
17+
base.OnInitialization();
18+
}
19+
20+
/// <summary>
21+
/// 模块准备工作
22+
/// </summary>
23+
public override void OnPreparatory()
24+
{
25+
base.OnPreparatory();
26+
}
27+
28+
/// <summary>
29+
/// 刷新模块
30+
/// </summary>
31+
public override void OnRefresh()
32+
{
33+
base.OnRefresh();
34+
}
35+
36+
/// <summary>
37+
/// 终结模块
38+
/// </summary>
39+
public override void OnTermination()
40+
{
41+
base.OnTermination();
42+
}
43+
44+
/// <summary>
45+
/// 暂停模块
46+
/// </summary>
47+
public override void OnPause()
48+
{
49+
base.OnPause();
50+
}
51+
52+
/// <summary>
53+
/// 恢复模块
54+
/// </summary>
55+
public override void OnUnPause()
56+
{
57+
base.OnUnPause();
58+
}
59+
}

Editor/Utility/Template/CustomModuleTemplate.txt.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)