🔥顶级热门框架
1.ML-Agents ⭐ 16.5K Stars
Unity Technologies官方框架
机器学习框架
// Unity ML-Agents - 用强化学习训练AI
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
public class CarAgent : Agent {
public Transform target;
private Rigidbody rBody;
public override void Initialize() {
rBody = GetComponent<Rigidbody>();
}
// 观察环境
public override void CollectObservations(VectorSensor sensor) {
// 目标位置
sensor.AddObservation(target.localPosition);
// 自身位置
sensor.AddObservation(transform.localPosition);
// 速度
sensor.AddObservation(rBody.velocity.x);
sensor.AddObservation(rBody.velocity.z);
}
// 执行动作
public override void OnActionReceived(ActionBuffers actions) {
// 获取动作(前进/转向)
float moveForward = actions.ContinuousActions[0];
float turn = actions.ContinuousActions[1];
rBody.AddForce(transform.forward * moveForward * 10f);
transform.Rotate(0, turn * 5f, 0);
// 到达目标 = 奖励
float distanceToTarget = Vector3.Distance(transform.localPosition, target.localPosition);
if (distanceToTarget < 1.4f) {
SetReward(1.0f);
EndEpisode();
}
// 掉下平台 = 惩罚
if (transform.localPosition.y < 0) {
SetReward(-1.0f);
EndEpisode();
}
}
// 人类控制(用于测试)
public override void Heuristic(in ActionBuffers actionsOut) {
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = Input.GetAxis("Vertical");
continuousActionsOut[1] = Input.GetAxis("Horizontal");
}
}
// ⭐训练后可导出为ONNX模型在游戏中使用
// 被用于:
// - AI对手训练
// - NPC行为学习
// - 游戏测试自动化
// - 程序化内容生成
GitHub: https://github.com/Unity-Technologies/ml-agents
2. xNode ⭐ 2.4K Stars
可视化节点编辑器
using XNode;
// Reddit推荐:技能/对话/AI编辑器
[CreateAssetMenu]
public class DialogueGraph : NodeGraph { }
public class DialogueNode : Node {
[Input] public int entry;
[Output] public int exit;
public string speakerName;
[TextArea] public string dialogueText;
public Sprite portrait;
public override object GetValue(NodePort port) {
return null;
}
}
public class ChoiceNode : Node {
[Input] public int entry;
[Output] public int option1;
[Output] public int option2;
[Output] public int option3;
public string choice1Text;
public string choice2Text;
public string choice3Text;
}
// 技能系统示例
public class SkillNode : Node {
public enum SkillType { Damage, Heal, Buff, Debuff }
[Input] public int entry;
[Output(dynamicPortList = true)] public int[] outputs;
public SkillType type;
public float value;
public float cooldown;
public GameObject effectPrefab;
}
// 运行时执行
public class DialoguePlayer : MonoBehaviour {
public DialogueGraph graph;
private Node currentNode;
void Start() {
currentNode = graph.nodes[0];
ShowDialogue();
}
void ShowDialogue() {
if (currentNode is DialogueNode dialogue) {
// 显示对话
UIManager.ShowDialogue(dialogue.speakerName, dialogue.dialogueText);
} else if (currentNode is ChoiceNode choice) {
// 显示选项
UIManager.ShowChoices(choice.choice1Text, choice.choice2Text);
}
}
public void NextNode(string portName = "exit") {
NodePort exitPort = currentNode.GetOutputPort(portName);
if (exitPort != null && exitPort.IsConnected) {
currentNode = exitPort.Connection.node;
ShowDialogue();
}
}
}
// ⭐用途:
// - 对话系统
// - 技能编辑器
// - 任务系统
// - 行为树
GitHub: https://github.com/Siccity/xNode
3. UniTask ⭐ 2.9K Stars
异步编程神器
using Cysharp.Threading.Tasks;
// Reddit推荐:替代Unity协程
public class UniTaskExamples : MonoBehaviour {
async UniTaskVoid Start() {
// 异步加载
var sprite = await Resources.LoadAsync<Sprite>("icon").ToUniTask();
// 延迟
await UniTask.Delay(TimeSpan.FromSeconds(3));
// 等待条件
await UniTask.WaitUntil(() => Input.anyKeyDown);
// 超时控制
try {
await LoadDataAsync().Timeout(TimeSpan.FromSeconds(5));
} catch (TimeoutException) {
Debug.Log("加载超时");
}
// 取消令牌
var cts = new CancellationTokenSource();
await LongRunningTask(cts.Token);
// 并发执行
var (result1, result2, result3) = await UniTask.WhenAll(
LoadTexture1(),
LoadTexture2(),
LoadTexture3()
);
}
async UniTask LoadDataAsync() {
// 模拟网络请求
await UniTask.Delay(1000);
}
async UniTask LongRunningTask(CancellationToken ct) {
while (!ct.IsCancellationRequested) {
await UniTask.Yield();
}
}
// 异步事件
async UniTask WaitForButtonClick() {
await button.OnClickAsync();
Debug.Log("按钮被点击");
}
// AsyncReactiveProperty
private AsyncReactiveProperty<int> score = new AsyncReactiveProperty<int>(0);
async UniTask ObserveScore() {
await foreach (var value in score.WithoutCurrent()) {
Debug.Log($"分数变化: {value}");
}
}
// 比协程快3-5倍
// 零GC分配
private UnityEngine.UI.Button button;
async UniTask<Texture2D> LoadTexture1() { return null; }
async UniTask<Texture2D> LoadTexture2() { return null; }
async UniTask<Texture2D> LoadTexture3() { return null; }
}
GitHub: https://github.com/Cysharp/UniTask
4. ProBuilder ⭐
Unity官方收购
// Unity内置的关卡编辑器
// Reddit推荐:快速原型制作
using UnityEngine.ProBuilder;
using UnityEngine.ProBuilder.MeshOperations;
public class ProBuilderRuntime : MonoBehaviour {
void CreateCube() {
var mesh = ProBuilderMesh.Create();
mesh.CreateShapeFromPolygon(ShapeFactory.Cube.GetFaces());
mesh.Refresh();
}
void ExtrudeFace(ProBuilderMesh mesh, Face face) {
mesh.Extrude(new[] { face }, ExtrudeMethod.FaceNormal, 1f);
mesh.ToMesh();
mesh.Refresh();
}
}
// ⭐用途:
// - 快速搭建关卡
// - 灰盒测试
// - 程序化建筑
5. CatLib ⭐ 2.2K Stars
搜狐畅游技术栈(天龙八部3D等)
// CatLib - 渐进式框架,搜狐畅游开源
using CatLib;
// 1. 服务提供者(Service Provider)
public class ConfigServiceProvider : IServiceProvider {
public void Init() {
// 初始化
}
public void Register() {
App.Singleton<IConfigManager, ConfigManager>()
.OnResolving((bind, obj) => {
// 解析时回调
var config = (ConfigManager)obj;
config.Load();
return obj;
});
}
}
// 2. 门面(Facade)模式
public class Config : Facade<IConfigManager> { }
// 使用
void Example() {
// 通过门面访问
string value = Config.Instance.Get("game.version");
// 或直接解析
var configManager = App.Make<IConfigManager>();
}
// 3. 事件系统
public class GameEvents {
void Start() {
// 订阅事件
App.On("player.levelup", (sender, e) => {
var level = (int)e.Args[0];
Debug.Log($"玩家升级到 {level}");
});
// 触发事件
App.Trigger("player.levelup", this, 10);
}
}
// 4. 路由系统(场景/UI管理)
public class RouteExample {
void NavigateToScene() {
// 路由到场景
App.Make<IRouter>().Dispatch("scene://battle", new {
level = 5,
difficulty = "hard"
});
}
void OpenUI() {
// 路由到UI
App.Make<IRouter>().Dispatch("ui://shop", new {
tab = "weapon"
});
}
}
// 5. 配置管理
public class ConfigExample {
void LoadConfig() {
var config = App.Make<IConfigManager>();
// 获取配置
int maxLevel = config.Get<int>("game.max_level", 100);
string serverUrl = config.Get<string>("network.server_url");
// 设置配置
config.Set("player.name", "玩家1");
// 保存配置
config.Save();
}
}
// 6. 容器高级用法
public class ContainerAdvanced {
void Setup() {
// 单例绑定
App.Singleton<IPlayerService, PlayerService>();
// 实例绑定
App.Instance<GameConfig>(new GameConfig());
// 别名
App.Alias<IPlayerService>("player");
// 上下文绑定(根据调用者不同返回不同实例)
App.BindIf<ILogger>()
.Needs<BattleSystem>()
.Given<FileLogger>();
App.BindIf<ILogger>()
.Needs<UISystem>()
.Given<ConsoleLogger>();
}
}
// ⭐搜狐畅游实际使用:
// - 天龙八部3D
// - 鹿鼎记
// - 多款手游项目
// ⭐特点:
// Laravel风格(PHP框架)
// 渐进式框架
// 服务提供者模式
// 门面模式
// 事件驱动
// 依赖注入
GitHub: https://github.com/CatLib/Core
官网: https://catlib.io/
6. TinaX Framework ⭐ 450 Stars
新一代Unity开发框架,小众但现代
// TinaX - 模块化设计
using TinaX;
using TinaX.Core;
using TinaX.UIKit;
using TinaX.VFSKit;
// 1. 启动入口
public class GameStartup : IXBootstrap {
public void OnInit(IXCore core) {
// 注册服务
core.Services.AddSingleton<IPlayerService, PlayerService>();
}
public void OnStart(IXCore core) {
// 启动逻辑
Debug.Log("游戏启动");
}
public void OnAppRestart() {
// 热重启
}
public void OnQuit() {
// 退出清理
}
}
// 2. UI系统(UIKit)
public class MainUIController : XUIBehaviour {
[Inject]
private IPlayerService playerService;
[BindUIComponent("Button_Start")]
private Button startButton;
[BindUIComponent("Text_Score")]
private Text scoreText;
protected override void OnOpen(object param) {
base.OnOpen(param);
startButton.onClick.AddListener(() => {
OnStartClicked();
});
UpdateScore();
}
void OnStartClicked() {
playerService.StartGame();
}
void UpdateScore() {
scoreText.text = $"分数: {playerService.GetScore()}";
}
}
// 3. 虚拟文件系统(VFS)
public class VFSExample {
async Task LoadAsset() {
// 统一的资源加载接口
var sprite = await VFSKit.LoadAssetAsync<Sprite>("icon_weapon_001");
// 支持Addressables、AssetBundle、Resources等多种后端
}
}
// 4. 本地化(I18N)
public class LocalizationExample {
void Setup() {
// 切换语言
I18N.UseLanguage("zh-CN");
// 获取翻译
string text = I18N.Get("ui.main.title");
// 格式化
string welcome = I18N.Format("ui.welcome", "玩家1");
}
}
// 5. 时间管理
public class TimeExample {
void Update() {
// 使用TinaX的时间系统(支持变速)
float deltaTime = XTime.DeltaTime;
float unscaledDelta = XTime.UnscaledDeltaTime;
// 定时器
XTime.Delay(3f, () => {
Debug.Log("3秒后执行");
});
// 循环定时器
XTime.ScheduleRepeating(1f, () => {
Debug.Log("每秒执行");
});
}
}
// ⭐特点:
// 模块化(可选组件)
// 依赖注入
// 热重载支持
// 虚拟文件系统
// 现代化设计
GitHub: https://github.com/yomunsam/TinaX
7. ColaFramework ⭐ 800+ Stars
龙图游戏的开源框架
// ColaFramework - UI/资源管理为核心
using ColaFramework;
// 1. UI管理
public class UIExample : UIBase {
private Button loginButton;
private InputField usernameInput;
public override void OnCreate() {
base.OnCreate();
// 绑定UI
loginButton = transform.Find("Button_Login").GetComponent<Button>();
usernameInput = transform.Find("Input_Username").GetComponent<InputField>();
loginButton.onClick.AddListener(OnLoginClick);
}
void OnLoginClick() {
string username = usernameInput.text;
// 登录逻辑
}
public override void OnDestroy() {
base.OnDestroy();
loginButton.onClick.RemoveAllListeners();
}
}
// 打开UI
UIManager.Instance.OpenUI<MainUI>("MainUI");
// 2. 资源加载
public class ResourceExample {
async Task LoadAssets() {
// 异步加载
var prefab = await ResourceManager.Instance.LoadAsync<GameObject>("Prefabs/Enemy");
// 同步加载
var texture = ResourceManager.Instance.Load<Texture2D>("Textures/Icon");
// 释放资源
ResourceManager.Instance.Unload("Prefabs/Enemy");
}
}
// 3. 事件系统
public class EventExample {
void Start() {
// 注册事件
EventManager.Instance.Register("OnPlayerDead", OnPlayerDead);
}
void OnPlayerDead(object sender, object args) {
Debug.Log("玩家死亡");
}
void TriggerEvent() {
// 触发事件
EventManager.Instance.Trigger("OnPlayerDead", this, null);
}
}
// ⭐特点:
// 资源热更新
// UI管理完善
// 对象池
// Excel配置表工具
GitHub: https://github.com/XINCGer/ColaFramework
其他小众但优秀的框架
A. KSFramework ⭐ 1.5K Stars
金山系技术栈
// KSFramework - xLua + 热更新
using KSFramework;
public class GameStart : MonoBehaviour {
void Start() {
// Lua热更新
AppEngine.New(gameObject, (isOk) => {
if (isOk) {
// 执行Lua入口
LuaModule.Instance.CallScript("main");
}
});
}
}
// Lua代码
/*
-- main.lua
function main()
print("从Lua启动游戏")
-- 加载UI
UIModule.OpenWindow("LoginUI", function(ui)
ui:SetTitle("欢迎")
end)
end
*/
// ⭐特点:
// xLua集成
// AssetBundle管理
// UI框架(UGUI)
// Excel导表
// 资源热更新完整方案
GitHub: https://github.com/mr-kelly/KSFramework
B.JEngine ⭐ 2.4K Stars
ILRuntime/HotUpdate专注框架
// JEngine - 专注热更新
using JEngine.Core;
public class GameLauncher : MonoBehaviour {
async void Start() {
// 初始化热更新
await InitAsync();
// 加载热更新代码
var go = ClassBind.Instantiate("HotUpdateMain");
}
async Task InitAsync() {
await JEngine.Init();
// 加载热更新DLL
await AssetMgr.LoadAssetAsync<TextAsset>("HotUpdateScripts.bytes");
}
}
// 热更新代码(HotUpdateMain)
/*
namespace HotUpdate {
public class HotUpdateMain : MonoBehaviour {
void Start() {
Debug.Log("热更新代码运行");
}
}
}
*/
// ⭐特点:
// ILRuntime/HybridCLR双支持
// 资源加密
// 热更新流程完整
// 工具链完善
GitHub: https://github.com/JasonXuDeveloper/JEngine
C. Xiyu Game Framework ⭐ 300+ Stars
完美世界系技术
// Xiyu - 数据驱动设计
using Xiyu.GameFunction;
// 配置驱动的关卡系统
[CreateAssetMenu]
public class LevelConfig : ScriptableObject {
public int levelId;
public string levelName;
public List<WaveConfig> waves;
public RewardConfig reward;
}
// 数据表管理
public class GameDataManager : MonoSingleton<GameDataManager> {
private Dictionary<int, LevelConfig> levelConfigs;
public void LoadConfigs() {
// 从Excel生成的ScriptableObject加载
levelConfigs = Resources.LoadAll<LevelConfig>("Configs/Levels")
.ToDictionary(x => x.levelId);
}
public LevelConfig GetLevel(int id) {
return levelConfigs.TryGetValue(id, out var config) ? config : null;
}
}
// ⭐特点:
// 数据驱动
// ScriptableObject为核心
// 策划友好
// Excel工作流
GitHub: https://github.com/Jiaoziji/XiyuGameFunction
D. HuatuoFramework ⭐ 小众但前沿
基于HybridCLR(原Huatuo)的热更新框架
// 新一代热更新方案
using HybridCLR;
public class HotUpdateEntry : MonoBehaviour {
async void Start() {
// 下载热更新DLL
byte[] dllBytes = await DownloadDLL("http://cdn.com/HotUpdate.dll.bytes");
// 加载补充元数据(泛型支持)
byte[] aotDllBytes = await DownloadDLL("http://cdn.com/mscorlib.dll.bytes");
HybridCLR.RuntimeApi.LoadMetadataForAOTAssembly(aotDllBytes,
HybridCLR.HomologousImageMode.SuperSet);
// 加载热更新程序集
System.Reflection.Assembly hotUpdateAssembly =
System.Reflection.Assembly.Load(dllBytes);
// 调用热更新入口
Type entryType = hotUpdateAssembly.GetType("HotUpdate.Entry");
MethodInfo startMethod = entryType.GetMethod("Start");
startMethod.Invoke(null, null);
}
async Task<byte[]> DownloadDLL(string url) {
// 下载逻辑
return null;
}
}
// ⭐特点:
// 原生C#热更新(不是Lua/ILRuntime)
// 性能接近原生
// 完整C#特性支持
// IL2CPP兼容
GitHub: https://github.com/focus-creative-games/hybridclr
💎 隐藏的宝藏框架
a. PowerUtilities ⭐ 小众但强大
// Unity工具集合
// GitHub: https://github.com/redcool/PowerUtilities
// 特点:各种实用工具
b. BDFramework.Core ⭐ 600+ Stars
// 国产全栈框架
// GitHub: https://github.com/yimengfan/BDFramework.Core
// 特点:UI/资源/热更新一体化
c. Tetris ⭐ 小众UI框架
// UGUI增强框架
// 特点:UI组件库、动画系统
🎯 大厂技术栈揭秘
- 腾讯系
– 内部框架: T4(不开源)
– 开源贡献: xlua, InjectFix
– 公开案例: 王者荣耀用自研ECS - 网易系
– 内部框架: Messiah(不开源)
– 开源项目: Pomelo(服务器框架)
– 技术栈: 魔改Entitas - 米哈游
– 完全自研: 不开源
– 早期使用: Entitas魔改
– 原神: 完全自研引擎 - 莉莉丝(剑与远征)
– 基于: ET Framework改造
– 技术点: 帧同步 + ECS - 叠纸(恋与制作人)
– 基于: Entitas魔改
– 特色: 剧情编辑器(自研)
💡 选择建议
- 选CatLib如果:
– 喜欢Laravel风格
– 需要渐进式框架
– 服务提供者模式 - 选TinaX如果:
– 追求现代化设计
– 需要模块化
– 新项目从零开始 - 选HybridCLR如果:
– 必须热更新
– 不想用Lua
– 追求性能
✨随便写写
by 李沧东
Unity热门游戏框架盘点

3万+

被折叠的 条评论
为什么被折叠?



