Giter VIP home page Giter VIP logo

motionframework's Introduction

MotionFramework

MotionFramework是一套基于Unity3D引擎的游戏框架。框架整体遵循轻量化、易用性、低耦合、扩展性强的设计理念。工程结构清晰,代码注释详细,该框架已被应用于多款商业化的游戏项目,是作为创业游戏公司、独立游戏开发者、以及初学者们推荐的游戏框架。

image

支持版本

Unity2018.4+

开发环境

C# && .NET4.x

核心系统

  1. 引擎 - 游戏框架的核心类,它负责游戏模块的创建和管理。在核心系统的基础上,提供了许多在游戏开发过程中常用的管理器,可以帮助开发者加快游戏开发速度。
  2. 日志 - 游戏框架的日志系统,开发者通过注册可以监听框架生成的日志。
  3. 控制台 - 在游戏运行的时候,通过内置的控制台可以方便查看调试信息。控制台预设了游戏模块,游戏日志,应用详情,资源系统,引用池,游戏对象池等窗口。开发者可以扩展自定义窗口。
  4. 引用池 - 用于C#引用类型的对象池,对于频繁创建的引用类型,使用引用池可以帮助减少GC。
  5. 资源系统 - 依赖于经过商业化产品验证的YooAsset资源系统。
  6. 网络系统 - 异步IOCP SOCKET长连接方案,支持TCP和UDP协议。支持同时建立多个通信频道,例如连接逻辑服务器的同时还可以连接聊天服务器。不同的通信频道支持使用不同的网络包编码解码器,开发者可以扩展支持ProtoBuf的网络包编码解码器,也可以使用自定义的序列化和反序列化方案。
  7. 有限状态机 - 流程状态机是一种简化的有限状态机。通过流程状态机可以将复杂的业务逻辑拆分简化,例如:整个资源热更新流程可以拆分成多个独立的步骤。

管理器介绍

游戏开发过程中常用的管理器

  1. 事件管理器 (EventManager)
  2. 网络管理器 (NetworkManager)
  3. 资源管理器 (ResourceManager)
  4. 音频管理器 (AudioManager)
  5. 配表管理器 (ConfigManager)
  6. 场景管理器 (SceneManager)
  7. 窗口管理器 (WindowManager)
  8. 补间管理器 (TweenManager)
  9. 游戏对象池管理器 (GameObjectPoolManager)

新手教程

  1. 游戏启动器 (GameLauncher)

DEMO

Demo 使用MotionFramework制作的一款RPG单机游戏。

代码规范

请参考代码规范

贡献者

何冠峰 任志勇 ZensYue 徐烜 张飞涛

motionframework's People

Contributors

gmhevinci avatar zensyue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

motionframework's Issues

在事件Handler里Remove掉同事件的另一个Handler会出现异常

public class TestScript : MonoBehaviour
{
public class TestEventMsg : IEventMessage, IReference
{
public string Value;

    // 在回收的时候该方法会被执行
    public void OnRelease()
    {
        Value = null;
    }
}

// Start is called before the first frame update
void Start()
{
    // 创建模块
    MotionEngine.CreateModule<EventManager>();
    
    EventManager.Instance.AddListener<TestEventMsg>(OnMsg2);
    EventManager.Instance.AddListener<TestEventMsg>(OnMsg1);

    TestEventMsg msg = ReferencePool.Spawn<TestEventMsg>();  
    msg.Value = "hello world";
    EventManager.Instance.SendMessage(msg);
}

void OnMsg1(IEventMessage msg)
{
    if(msg is TestEventMsg temp)
    {
        Debug.Log("msg1 " + temp.Value);
        
        EventManager.Instance.RemoveListener<TestEventMsg>(OnMsg2);
    }
}

void OnMsg2(IEventMessage msg)
{
    if(msg is TestEventMsg temp)
    {
        Debug.Log("msg2 " + temp.Value);
    }
}

}

现象为触发了两次 msg1

一个小建议,ResourceManager底层能否加一个每帧LoadAssetAsync的数量限制

用100个配置做测试ConfigManager.LoadConfigs(List loadPairs),
第1个回调会在2秒后才触发, 后续99个回调会在第1个回调后面正常陆续触发,
也就是说, 虽然unity主线程不会卡顿, 但是ab线程应该是卡住了.
后来我在逻辑层把Load的数量控制在每帧10个以内, 才感觉正常.
正常是指: 不管逻辑层同时load多少个ab, 第1个回调都应该正常触发

使用编辑器模拟更新异常

版本:最新 master 和 patch demo
操作:1 . 更改 GameLauncher 创建 PatchUpdater 的参数代码为 updaterCreateParam.AutoDownloadDLC = new string[] { "buildin" };只下载 buildin 资源,其他加载的 时候 自动下载
2. 打包 patch demo 资源,放到 服务器上,配置 GameVersion
3. 运行 patch demo后,加载 lodinwindow 必现 报错:
[MotionLog] WaitForAsyncComplete failed ! BundleName : assets/gameres/uipanel/loginwindow.bundle States : CheckDownload
UnityEngine.Debug:LogError(Object)
GameLauncher:HandleMotionFrameworkLog(ELogLevel, String) (at Assets/GameScript/Runtime/GameLauncher.cs:86)
MotionFramework.MotionLog:Error(String) (at Assets/MotionFramework/Scripts/Runtime/Engine/Core/MotionLog.cs:42)
MotionFramework.Resource.BundleFileLoader:WaitForAsyncComplete() (at Assets/MotionFramework/Scripts/Runtime/Engine/Engine.Resource/AssetSystem/Loader/BundleFileLoader.cs:306)
MotionFramework.Resource.BundledAssetProvider:Update() (at Assets/MotionFramework/Scripts/Runtime/Engine/Engine.Resource/AssetSystem/Provider/BundledAssetProvider.cs:45)
MotionFramework.Resource.AssetSystem:UpdatePoll() (at Assets/MotionFramework/Scripts/Runtime/Engine/Engine.Resource/AssetSystem/AssetSystem.cs:84)
MotionFramework.Resource.ResourceManager:MotionFramework.IModule.OnUpdate() (at Assets/MotionFramework/Scripts/Runtime/Module/Module.Resource/ResourceManager.cs:96)
MotionFramework.MotionEngine:Update() (at Assets/MotionFramework/Scripts/Runtime/Engine/Core/MotionEngine.cs:90)
GameLauncher:Update() (at Assets/GameScript/Runtime/GameLauncher.cs:51)

看代码 是 走到了 BundleFileLoader 的 保险机制。。。

StartCoroutine使用字符串方法名时,才能用StopCoroutine停用(StopCoroutine也必须使用字符串方法名)。

#region 协程相关
///


/// 开启一个协程
///

public static Coroutine StartCoroutine(IEnumerator coroutine)
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
return _behaviour.StartCoroutine(coroutine);
}

	/// <summary>
	/// 停止一个协程
	/// </summary>
	/// <param name="coroutine"></param>
	public static void StopCoroutine(Coroutine coroutine)
	{
		if (_behaviour == null)
			throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
		_behaviour.StopCoroutine(coroutine);
	}

需要把这两个方法改成 : 字符串的协程重载方法

ReferenceCollector内部的数据结构改成Stack?

这里的ds没必要用queue吧?
改成stack会不会好些? 还是说这里Queue有我忽略的含义?

疑惑cpucache会不会高一些.

以下是一个简单的测试代码. 速度有略微提升. 可以交换顺序. 测试一致

using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;

public class RefCls
{
    public int a;
}

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int count = 1000000;

        var s = new Stack<RefCls>(count);

        var q = new Queue<RefCls>(count);


        for (int i = 0; i < count; i++)
        {
            q.Enqueue(new RefCls());
            s.Push(new RefCls());
        }


        Stopwatch stopwatch;

        stopwatch = Stopwatch.StartNew();
        for (int i = 0; i < count; i++)
        {
            var x = q.Dequeue();
            q.Enqueue(x);
        }

        Debug.Log(stopwatch.ElapsedMilliseconds);

        stopwatch = Stopwatch.StartNew();
        for (int i = 0; i < count; i++)
        {
            var x = s.Pop();
            s.Push(x);
        }

        Debug.Log(stopwatch.ElapsedMilliseconds);
    }

    // Update is called once per frame
}

关于资源同步加载的疑问

AssetBundleLoader.ForceSyncLoad()
while (true) { ******* Update(); ******* }
请教一下,这里为什么采用挂起主线程,异步加载,而不用AssetBundle.LoadFromFile()的方式?

How can we load all assets by Type in a folder

Hi @gmhevinci
I have a folder that has some Scriptable files inside.
How can I use ResourceManager to load all assets by Type inside the folder? (Maybe the same of Unity API: public Object[] LoadAllAssets(Type type);)
I try ResourceManager.Instance.LoadSubAssetsAsync but it not works, maybe it only uses for Sprite and SpriteAtlas
Thank you so much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.