This commit is contained in:
陈思海 2025-03-07 17:58:52 +08:00
parent 159c0273c9
commit 37056cca35
18 changed files with 189 additions and 362 deletions

View File

@ -1,36 +0,0 @@
using System.IO;
using AlicizaX.Runtime;
using UnityEditor;
using UnityEngine;
namespace AlicizaX.Editor
{
static class FrameworkAssetInitlized
{
[InitializeOnLoadMethod]
static void Initlize()
{
string FloderPath = "Assets/Resources/";
if (!Directory.Exists(FloderPath))
{
Directory.CreateDirectory(FloderPath);
}
string publisherPath = Path.Combine(FloderPath, "FrameworkPublishSettings.asset");
string hotPath = Path.Combine(FloderPath, "FrameworkHotUpdateSettings.asset");
if (!File.Exists(publisherPath))
{
var publisherObject = ScriptableObject.CreateInstance<FrameworkPublishSettings>();
AssetDatabase.CreateAsset(publisherObject, publisherPath);
}
if (!File.Exists(hotPath))
{
var hotObject = ScriptableObject.CreateInstance<FrameworkHotUpdateSettings>();
AssetDatabase.CreateAsset(hotObject, hotPath);
}
AssetDatabase.Refresh();
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 9e6620d843d745fba3213017d052d5e1
timeCreated: 1739170824

View File

@ -1,97 +1,97 @@
using UnityEditor;
using UnityEngine;
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using AlicizaX.Runtime;
using Sirenix.OdinInspector.Editor;
namespace AlicizaX.Editor
{
public class GameFrameworkPreferenceWindow : OdinMenuEditorWindow
{
private List<Type> m_TabTypes;
private readonly Dictionary<Type, GameFrameworkTabBase> _tabBases = new();
[MenuItem("Tools/AlicizaX/Preference Window")]
public static void ShowWindow()
{
GetWindow<GameFrameworkPreferenceWindow>(true, "Preference Window");
}
protected override void OnEnable()
{
base.OnEnable();
this.position = new Rect(this.position.x, this.position.y, 800, 600);
var assemblies = Utility.Assembly.GetAssemblies();
m_TabTypes = new List<Type>();
foreach (var assembly in assemblies)
{
var types = assembly.GetTypes();
foreach (var type in types)
{
if (typeof(GameFrameworkTabBase).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract)
{
var displayNameAttr = (DisplayNameAttribute)Attribute.GetCustomAttribute(type, typeof(DisplayNameAttribute));
if (displayNameAttr != null)
{
m_TabTypes.Add(type);
}
}
}
}
m_TabTypes = m_TabTypes.OrderBy(t => ((DisplayNameAttribute)Attribute.GetCustomAttribute(t, typeof(DisplayNameAttribute))).DisplayName).ToList();
}
protected override void OnDestroy()
{
base.OnDestroy();
if (this.MenuTree != null && this.MenuTree.Selection.SelectedValue != null)
{
var selectTarget = this.MenuTree.Selection.SelectedValue;
if (selectTarget != null)
{
var selectType = selectTarget.GetType();
if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab))
{
tab.Save();
}
}
}
}
protected override OdinMenuTree BuildMenuTree()
{
var tree = new OdinMenuTree();
foreach (var tabType in m_TabTypes)
{
DisplayNameAttribute displayNameAttribute = (DisplayNameAttribute)Attribute.GetCustomAttribute(tabType, typeof(DisplayNameAttribute));
GameFrameworkTabBase instance = (GameFrameworkTabBase)Activator.CreateInstance(tabType);
_tabBases.Add(tabType, instance);
tree.Add(displayNameAttribute.DisplayName, instance);
}
tree.Selection.SelectionChanged += SelectionOnSelectionChanged;
return tree;
}
private void SelectionOnSelectionChanged(SelectionChangedType obj)
{
var selectTarget = this.MenuTree.Selection.SelectedValue;
if (selectTarget != null)
{
var selectType = selectTarget.GetType();
if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab))
{
tab.Save();
}
}
}
}
}
// using UnityEditor;
// using UnityEngine;
// using System;
// using System.Linq;
// using System.Reflection;
// using System.Collections.Generic;
// using AlicizaX.Runtime;
// using Sirenix.OdinInspector.Editor;
//
// namespace AlicizaX.Editor
// {
// public class GameFrameworkPreferenceWindow : OdinMenuEditorWindow
// {
// private List<Type> m_TabTypes;
// private readonly Dictionary<Type, GameFrameworkTabBase> _tabBases = new();
//
// [MenuItem("Tools/AlicizaX/Preference Window")]
// public static void ShowWindow()
// {
// GetWindow<GameFrameworkPreferenceWindow>(true, "Preference Window");
// }
//
// protected override void OnEnable()
// {
// base.OnEnable();
// this.position = new Rect(this.position.x, this.position.y, 800, 600);
//
// var assemblies = Utility.Assembly.GetAssemblies();
//
// m_TabTypes = new List<Type>();
//
// foreach (var assembly in assemblies)
// {
// var types = assembly.GetTypes();
// foreach (var type in types)
// {
// if (typeof(GameFrameworkTabBase).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract)
// {
// var displayNameAttr = (DisplayNameAttribute)Attribute.GetCustomAttribute(type, typeof(DisplayNameAttribute));
// if (displayNameAttr != null)
// {
// m_TabTypes.Add(type);
// }
// }
// }
// }
//
// m_TabTypes = m_TabTypes.OrderBy(t => ((DisplayNameAttribute)Attribute.GetCustomAttribute(t, typeof(DisplayNameAttribute))).DisplayName).ToList();
// }
//
//
// protected override void OnDestroy()
// {
// base.OnDestroy();
// if (this.MenuTree != null && this.MenuTree.Selection.SelectedValue != null)
// {
// var selectTarget = this.MenuTree.Selection.SelectedValue;
// if (selectTarget != null)
// {
// var selectType = selectTarget.GetType();
// if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab))
// {
// tab.Save();
// }
// }
// }
// }
//
// protected override OdinMenuTree BuildMenuTree()
// {
// var tree = new OdinMenuTree();
// foreach (var tabType in m_TabTypes)
// {
// DisplayNameAttribute displayNameAttribute = (DisplayNameAttribute)Attribute.GetCustomAttribute(tabType, typeof(DisplayNameAttribute));
// GameFrameworkTabBase instance = (GameFrameworkTabBase)Activator.CreateInstance(tabType);
// _tabBases.Add(tabType, instance);
// tree.Add(displayNameAttribute.DisplayName, instance);
// }
//
// tree.Selection.SelectionChanged += SelectionOnSelectionChanged;
// return tree;
// }
//
// private void SelectionOnSelectionChanged(SelectionChangedType obj)
// {
// var selectTarget = this.MenuTree.Selection.SelectedValue;
// if (selectTarget != null)
// {
// var selectType = selectTarget.GetType();
// if (_tabBases.TryGetValue(selectType, out GameFrameworkTabBase tab))
// {
// tab.Save();
// }
// }
// }
// }
// }

View File

@ -10,6 +10,7 @@ using UnityEngine;
public static class BuildDLLCommand
{
private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR";
public const string AssemblyTextAssetPath = "Bundles/DLL";
static BuildDLLCommand()
{
@ -18,7 +19,7 @@ public static class BuildDLLCommand
/// <summary>
/// 禁用HybridCLR宏定义。
/// </summary>
[MenuItem("Tools/AlicizaX/HybridCLR/Define Symbols/Disable HybridCLR", false, 30)]
[MenuItem("HybridCLR/Tools/Define Symbols/Disable HybridCLR", false, 30)]
public static void Disable()
{
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
@ -29,7 +30,7 @@ public static class BuildDLLCommand
/// <summary>
/// 开启HybridCLR宏定义。
/// </summary>
[MenuItem("Tools/AlicizaX/HybridCLR/Define Symbols/Enable HybridCLR", false, 31)]
[MenuItem("HybridCLR/Tools/Tools/Define Symbols/Enable HybridCLR", false, 31)]
public static void Enable()
{
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
@ -39,10 +40,9 @@ public static class BuildDLLCommand
}
#if ENABLE_HYBRIDCLR
[MenuItem("Tools/AlicizaX/HybridCLR/Build/BuildAssets And CopyTo AssemblyTextAssetPath")]
[MenuItem("HybridCLR/Tools/Build/BuildAssets And CopyTo AssemblyTextAssetPath")]
public static void BuildAndCopyDlls()
{
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
CopyAOTHotUpdateDlls(target);
@ -69,14 +69,15 @@ public static class BuildDLLCommand
#if ENABLE_HYBRIDCLR
var target = EditorUserBuildSettings.activeBuildTarget;
string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
string aotAssembliesDstDir = Application.dataPath + "/" + ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>().AssemblyTextAssetPath;
string aotAssembliesDstDir = Application.dataPath + "/" + AssemblyTextAssetPath;
foreach (var dll in ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>().AOTMetaAssemblies)
foreach (var dll in AssemblyLoadData.Instance.AOTMetaAssemblies)
{
string srcDllPath = $"{aotAssembliesSrcDir}/{dll}";
if (!System.IO.File.Exists(srcDllPath))
{
Debug.LogError($"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成因此需要你先构建一次游戏App后再打包。");
Debug.LogError(
$"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成因此需要你先构建一次游戏App后再打包。");
continue;
}
@ -93,7 +94,7 @@ public static class BuildDLLCommand
var target = EditorUserBuildSettings.activeBuildTarget;
string hotfixDllSrcDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
string hotfixAssembliesDstDir = Application.dataPath + "/" + ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>().AssemblyTextAssetPath;
string hotfixAssembliesDstDir = Application.dataPath + "/" + AssemblyTextAssetPath;
foreach (var dll in SettingsUtil.HotUpdateAssemblyFilesExcludePreserved)
{
string dllPath = $"{hotfixDllSrcDir}/{dll}";

View File

@ -1,37 +0,0 @@
using System;
using System.Collections.Generic;
using AlicizaX.Editor;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Sirenix.Serialization;
using UnityEditor;
using UnityEngine;
namespace AlicizaX.Runtime
{
[DisplayName("热更设置")]
[Serializable]
internal sealed class HybridCLRSettingTab : GameFrameworkTabBase
{
[Required][InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)][DisableInPlayMode] [HideLabel]
public FrameworkHotUpdateSettings FrameworkHotUpdateSettings;
public HybridCLRSettingTab()
{
FrameworkHotUpdateSettings = ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>();
}
[Sirenix.OdinInspector.Button(ButtonSizes.Large)]
private void RefreshAssembly()
{
SyncAssemblyContent.RefreshAssembly();
}
protected internal override void Save()
{
base.Save();
EditorUtility.SetDirty(FrameworkHotUpdateSettings);
AssetDatabase.SaveAssets();
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ab21809ce8ad4d5ebe950b70107deb00
timeCreated: 1737525094

View File

@ -1,15 +1,20 @@
using System.IO;
using AlicizaX.Runtime;
using UnityEditor;
namespace AlicizaX.Editor
{
public static class SyncAssemblyContent
{
[MenuItem("HybridCLR/Sync Assembly")]
public static void RefreshAssembly()
{
ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>().HotUpdateAssemblies = HybridCLR.Editor.SettingsUtil.HotUpdateAssemblyFilesIncludePreserved;
ScriptableSingletonUtil.Get<FrameworkHotUpdateSettings>().AOTMetaAssemblies = HybridCLR.Editor.SettingsUtil.AOTAssemblyNames;
AssemblyLoadData assemblyLoadData = new AssemblyLoadData();
assemblyLoadData.HotUpdateAssemblies = HybridCLR.Editor.SettingsUtil.HotUpdateAssemblyFilesIncludePreserved;
assemblyLoadData.AOTMetaAssemblies = HybridCLR.Editor.SettingsUtil.AOTAssemblyNames;
File.WriteAllText("Assets/Resources/AssemblyLoadData.json", Utility.Json.ToJson(assemblyLoadData));
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
}
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 33e7b1423d7c447a984510c0d398311f
timeCreated: 1737530322

View File

@ -1,26 +0,0 @@
using AlicizaX.Runtime;
using Sirenix.OdinInspector;
using UnityEditor;
namespace AlicizaX.Editor
{
[System.Serializable]
[DisplayName("发布设置")]
internal sealed class FrameworkPublisherSettingTab : GameFrameworkTabBase
{
[Required] [InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] [DisableInPlayMode] [HideLabel]
public FrameworkPublishSettings FrameworkPublishSettings;
public FrameworkPublisherSettingTab()
{
FrameworkPublishSettings = ScriptableSingletonUtil.Get<FrameworkPublishSettings>();
}
protected internal override void Save()
{
base.Save();
EditorUtility.SetDirty(FrameworkPublishSettings);
AssetDatabase.SaveAssets();
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a6011b6ff89947deb4077e2578ad897e
timeCreated: 1737536018

View File

@ -0,0 +1,29 @@
using System;
using UnityEngine;
namespace AlicizaX.Runtime
{
[Serializable]
public class AppBuilderSetting
{
public static AppBuilderSetting Instance
{
get
{
if (_instance == null)
{
TextAsset text = Resources.Load<TextAsset>("AppBuilderSetting");
_instance = Utility.Json.ToObject<AppBuilderSetting>(text.text);
}
return _instance;
}
}
private static AppBuilderSetting _instance;
public bool DebugMode = false;
public int ResMode = 0;
public Language Language = Runtime.Language.ChineseSimplified;
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using AlicizaX.Runtime;
using UnityEngine;
using UnityEngine.Serialization;
/// <summary>
/// HybridCLRCustomGlobalSettings.
/// </summary>
[Serializable]
public class AssemblyLoadData
{
public static bool Enable
{
get
{
#if ENABLE_HYBRIDCLR
return true;
#else
return false;
#endif
}
}
public static AssemblyLoadData Instance
{
get
{
if (_instance == null)
{
TextAsset text = Resources.Load<TextAsset>("AssemblyLoadData");
_instance = Utility.Json.ToObject<AssemblyLoadData>(text.text);
}
return _instance;
}
}
private static AssemblyLoadData _instance;
public List<string> HotUpdateAssemblies = new List<string>()
{ "GameLib.dll", "GameProto.dll", "GameBase.dll", "GameLogic.dll" };
public List<string> AOTMetaAssemblies = new List<string>() { "mscorlib.dll", "System.dll", "System.Core.dll" };
}

View File

@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using AlicizaX.Runtime;
using UnityEngine;
using UnityEngine.Serialization;
/// <summary>
/// HybridCLRCustomGlobalSettings.
/// </summary>
[Serializable]
public class FrameworkHotUpdateSettings : ScriptableObject
{
public bool Enable
{
get
{
#if ENABLE_HYBRIDCLR
return true;
#else
return false;
#endif
}
}
[Header("Auto sync with [HybridCLRGlobalSettings]")] [Tooltip("You should modify the file form file path [Assets/CustomHybridCLR/Settings/HybridCLRGlobalSettings.asset]")]
public List<string> HotUpdateAssemblies = new List<string>() { "GameLib.dll", "GameProto.dll", "GameBase.dll", "GameLogic.dll" };
[Header("Need manual setting!")] public List<string> AOTMetaAssemblies = new List<string>() { "mscorlib.dll", "System.dll", "System.Core.dll" };
/// <summary>
/// Dll of main business logic assembly
/// </summary>
public string LogicMainDllName = "GameLogic.dll";
/// <summary>
/// 程序集文本资产打包Asset后缀名
/// </summary>
public string AssemblyTextAssetExtension = ".bytes";
/// <summary>
/// 程序集文本资产资源目录
/// </summary>
public string AssemblyTextAssetPath = "AssetRaw/DLL";
}

View File

@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
namespace AlicizaX.Runtime
{
[Serializable]
public class FrameworkPublishSettings : ScriptableObject
{
[BoxGroup("版本配置", true)] [TableList(ShowIndexLabels = false, DrawScrollView = true, MaxScrollViewHeight = 200, AlwaysExpanded = true)]
public List<RemoteURLConfigSetting> Configs = new List<RemoteURLConfigSetting>
{
new RemoteURLConfigSetting() { Version_Type = "Release", CheckUrl = "http://127.0.0.1:8080/UpdateData.json" },
new RemoteURLConfigSetting() { Version_Type = "Dev", CheckUrl = "http://127.0.0.1:8080/UpdateData.json" },
new RemoteURLConfigSetting() { Version_Type = "Test", CheckUrl = "http://127.0.0.1:8080/UpdateData.json" },
};
[BoxGroup("版本配置", true)] [LabelText("当前版本")] [ValueDropdown("GetAllType", ExpandAllMenuItems = true)] [SerializeField]
public string AppStageType = "Dev";
public RemoteURLConfigSetting GetConfig()
{
return Configs.Find(s => s.Version_Type == AppStageType);
}
[ValueDropdown("GetResMode")] [BoxGroup("发布设置")] [LabelText("资源模式")]
public int ResMode;
[BoxGroup("发布设置")] [LabelText("默认语言")] public Language Language = Runtime.Language.ChineseSimplified;
private System.Collections.IEnumerable GetAllType
{
get { return Configs.Select(a => a.Version_Type).ToList(); }
}
private static System.Collections.IEnumerable GetResMode = new ValueDropdownList<int>()
{
{ "EditorSimulateMode", 0 },
{ "OfflinePlayMode", 1 },
{ "HostPlayMode", 2 },
{ "WebPlayMode", 3 },
};
}
[Serializable]
public class RemoteURLConfigSetting
{
[TableColumnWidth(200, Resizable = false)]
public string Version_Type = "";
public string CheckUrl = "";
}
}

View File

@ -1,38 +0,0 @@
using UnityEngine;
namespace AlicizaX.Runtime
{
public static class FrameworkSettingsUtils
{
public static FrameworkHotUpdateSettings FrameworkHotUpdateSettings
{
get
{
if (_frameworkHotUpdateSettings == null)
{
_frameworkHotUpdateSettings = Resources.Load<FrameworkHotUpdateSettings>("FrameworkHotUpdateSettings");
}
return _frameworkHotUpdateSettings;
}
}
private static FrameworkHotUpdateSettings _frameworkHotUpdateSettings;
public static FrameworkPublishSettings FrameworkPublishSettings
{
get
{
if (_frameworkPublishSettings == null)
{
_frameworkPublishSettings = Resources.Load<FrameworkPublishSettings>("FrameworkPublishSettings");
}
return _frameworkPublishSettings;
}
}
private static FrameworkPublishSettings _frameworkPublishSettings;
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 2cd40b376b4a493faea997eb0ecf31c7
timeCreated: 1737532661