Giter VIP home page Giter VIP logo

donnyep / cosmosframework Goto Github PK

View Code? Open in Web Editor NEW
364.0 9.0 52.0 305.1 MB

CosmosFramework is a medium-lightweight plug-in Unity development framework . Has a rich Unity method extensions and toolchain. async/await syntax support, multi-network channel support.Long term support for this project

License: MIT License

C# 100.00%
kcp puremvc assetbundle await-async unity unityframework tcp-client-server tcp quadtree astar-pathfinding

cosmosframework's People

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

cosmosframework's Issues

How to handle Entity Life Cycle

Hi @DonnYep
I am reading the Entity Example and applying it to my game.
I want to reset some logic data (from table config) each time Entity is shown again, so I need some exclusive Functions like this:

  • OnInit (Can replace by Awake)
  • OnShow
  • OnHide

After reading the code, I think we can implement that functions in EntiyHelper and EntityGroupHelper classes but should we provide it in Entity Class?
Thank you so much!

感谢作者分享

代码过了一遍 ,学到了很多知识,感谢作者DonnYep大大

[Question] - Should we add PauseAllTask and UnPauseAll Task into TickTimer

Hi @DonnYep
I am using TickTimer to spawn tasks and when the game pause, I need to pause all task too
Should we add 2 functions for that purpose into TickTimer?

        public void PauseAllTask()
        {
            foreach (var taskId in taskDict.Keys)
            {
                PauseTask(taskId);
            }
        }

        public void UnPauseAllTask()
        {
            foreach (var taskId in taskDict.Keys)
            {
                UnPauseTask(taskId);
            }
        }

Thank you!

[Bug] - TickTimer PauseTask and UnPauseTask

Hi @DonnYep
I am trying using TickTimer feature. When testing Pause and Resume (UnPause), I see the problem that PauseTask removes the task from taskDict but in UnPauseTask, the taskDict is not adding the task again, so the task can not be resumed.
Please check

  public bool PauseTask(int taskId)
        {
            if (!taskDict.TryRemove(taskId, out TickTask task))
                return false;
            task.IsPause = true;
                var remainTime= task.DestTime - GetUTCMilliseconds();
            task.PauseRemainTime = remainTime > 0 ? remainTime : 0;
            return true;
        }
        public bool UnPauseTask(int taskId)
        {
            if (!taskDict.TryRemove(taskId, out TickTask task))
                return false;
            task.IsPause = false;
            task.DestTime = task.PauseRemainTime + GetUTCMilliseconds();
            return true;
        }

请教一下WaitForMainThread的用法

我写了如下的测试代码,发现"Down"的Log顺序在"AwaitableTest >>> After IEnumerator EnumWait"之后,
image

 IEnumerator EnumWait()
    {
        yield return new WaitForSeconds(3);
        Task task = new Task((() =>
        {
            Thread.Sleep(2000);
            Debug.Log("Down");
        }));
        task.Start();
        yield return task;
        Debug.Log("AwaitableTest >>> After IEnumerator EnumWait");
    }

但是当我将yield return task修改成yield return task.AsCoroutine();结果会变成
image

所以想请教一下WaitForMainThread的用法

Example

Hi @DonnYep
Thank you so much for awesome Framework, The examples list are very easy to run
When I try to run 08_ObjectPool, I see the null error here, Please check

image

NullReferenceException: Object reference not set to an instance of an object
Cosmos.Test.MyObjectSpawner+<Start>d__13.MoveNext () (at Assets/Examples/ExampleScripts/08_ObjectPool/MyObjectSpawner.cs:36)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153)
UnityEngine.UnitySynchronizationContext:ExecuteTasks() (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)

Thank you so much!

TickTimer Error in some case?

@DonnYep
I am trying the ObjectPool example and when I change the timer config to:

            //注意,这里是毫秒单位;
            tickTimer.AddTask(100, OnSpawnTime, null, int.MaxValue);
            //此写法的实际意义为,生成的单位存活时间为15秒;
            //await new WaitForSeconds(15f);
            tickTimer.AddTask(10, 1500, OnDespawnTime, null, int.MaxValue);

Then it errors :

NullReferenceException: Object reference not set to an instance of an object
Cosmos.TickTimer.TickRefresh () (at Assets/CosmosFramework/Runtime/Base/Timer/TickTimer.cs:192)
Cosmos.Test.MyObjectSpawner.Update () (at Assets/Examples/ExampleScripts/08_ObjectPool/MyObjectSpawner.cs:52)

Maybe we need to check some conditions to avoid this situation .. ?

Thank you so much!

[Question] - Can we receive more information from TickTimer Task

Hi @DonnYep
I am using CosmosFramework to implement this game requirement:

  • The enemy will spawn in some future time
    So I use addTask and set the delayTime to handle this
    But in the future, I need to know what enemy name (or enemy id) to spawn, for now, only task id is return.
    I am thinking about adding userData to Task construction, so when we call TaskCallback, we pass it like this
task.TaskCallback.Invoke(task.TaskId,task.UserData);

Is there another way to do it? Thank you so much, I am learning CosmosFramework every day

框架Resource模块是否能够同步加载资源?

目前看来所有加载资源的方法都是异步的,不知道有没同步的方式
由于本人不熟习异步思路开发,感觉困难重重
主要在与异步的污染性,一条代码是异步导致所有上层都要改为异步.
这样来,代码凡是和加载资源有关的(创建预制体这种很频繁的操作),都需要改为异步
在资源加载逻辑上下游也要变为异步

[UI Manager] - Should we add some default Layers and some Tweening function

Hi @DonnYep
It is only my suggestion, currently, the UI in our Framework is simple and easy to use enough.

  • Add some layer node likes: Top Layer, Middle Layer, Bottom Layer, or some parent as a placeholder for the panel group
  • Add basic Tweenning function for UI components before and after Panel Open and Close (Need some async function to await the tweens to completed)
    Thank you so much! Have a nice day!

建议:资源加载失败的时候打印一个警告

想起之前容易出错的一点就是场景管理器切换场景的时候,调用了方法但是没任何反应,场景也没切换成功
后来才发现是SCENE的资源路径错误了,但是系统没提示,排查起来费劲

Client.cs中ReceiveThreadFunction函数中少了Finally

!!!下面语句应该放finally中

        // add 'Disconnected' event to receive pipe so that the caller
        // knows that the Connect failed. otherwise they will never know
        state.receivePipe.Enqueue(0, EventType.Disconnected, default);
        
        // sendthread might be waiting on ManualResetEvent,
        // so let's make sure to end it if the connection
        // closed.
        // otherwise the send thread would only end if it's
        // actually sending data while the connection is
        // closed.
        sendThread?.Interrupt();

        // Connect might have failed. thread might have been closed.
        // let's reset connecting state no matter what.
        state.Connecting = false;

        // if we got here then we are done. ReceiveLoop cleans up already,
        // but we may never get there if connect fails. so let's clean up
        // here too.
        state.client?.Close();
    }

network help

能弄个有tcp和kcp同时存在的例子吗?

DefaultDownloadRequester.cs EnumGetFileSize函数if逻辑写反了

    IEnumerator EnumGetFileSize(string uri, Action<long> callback)
    {
        using (UnityWebRequest request = UnityWebRequest.Head(uri))
        {
            yield return request.SendWebRequest();
            string size = request.GetResponseHeader("Content-Length");

            if (request.result != UnityWebRequest.Result.ConnectionError && request.result != UnityWebRequest.Result.ProtocolError)
                callback?.Invoke(-1);
            else
                callback?.Invoke(Convert.ToInt64(size));
        }
    }

We are hiring

hi DonnYep,

I've read ur resume from BOSS (直聘), wondering if u still interested to have a new job in Ningbo Zhoushan Port (base Ningbo). I would be delighted if u would like to add my wx: MTM3MzIxNzU3MDA=, which I encoded with base64.

Sry to leave irrelevant issue as a message here since BOSS stop us from contact u, feel free to delete this message.

Best regards,
Li

20_AOI SquareGrid.cs数组越界

    public Square[] GetNearbySquares(float posX, float posY, int level = 0)
    {
        if (!IsOverlapping(posX, posY))
            return new Square[0];

!!!重复 if (!IsOverlapping(posX, posY))
!!!重复 return new Square[0];

!!! var row = (int)((posX - OffsetX) / CellSideLength);
!!! var col = (int)((posY - OffsetY) / CellSideLength);

        level = level >= 0 ? level : 0;
        if (level == 0)
            return new Square[] { square2d[col, row] };
        if (level == CellSection)
            return square1d;
        int sideCellCount = level * 2 + 1;
        int squareCount = sideCellCount * sideCellCount;
        Square[] neabySquares = new Square[squareCount + 1];
        int idx = 0;
        for (int x = -level; x <= level; x++)
        {
            for (int y = -level; y <= level; y++)
            {
                int idxX = col + x;
                int idxY = row + y;
                if (idxX < CellSection && idxX >= 0 && idxY < CellSection && idxY >= 0)
                {
                    neabySquares[idx] = square2d[idxX, idxY];
                    idx++;
                }
            }
        }
        var dstSquares = new Square[idx];

!!!越界 dstSquares[0] = square2d[col , row];

        Array.Copy(neabySquares, 0, dstSquares, 0, idx);
        return dstSquares;
    }

框架不错,希望能持续更新

感谢 开源这个框架。

最担心开发者因为其他事情导致这种框架类项目中途停滞,半途而废,希望这个项目不要出现这种情况。

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.