Giter Site home page Giter Site logo

saitinghu / htframework Goto Github PK

View Code? Open in Web Editor NEW
662.0 14.0 105.0 4.33 MB

Unity HTFramework, a rapid development framework of client based on Unity.

License: MIT License

C# 99.67% ShaderLab 0.29% HLSL 0.04%
unity unity-htframework fsm aop hotfix objectpool unity3d unity3d-framework ugui csharp

htframework's People

Contributors

ktdynamic avatar saitinghu 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

htframework's Issues

什么 是RealProxy ?有没demo 可以看看

Assets\HTFramework\RunTime\AspectTrack\Base\AspectProxyBase.cs(9,48): error CS0246: The type or namespace name 'RealProxy' could not be found (are you missing a using directive or an assembly reference?)

我在打ab包的时候勾选AppendHash,但是UI加载失败,因为ab包名加了hash值

我在打ab包的时候勾选AppendHash,但是UI加载失败,因为ab包名加了hash值,UI逻辑类标记的AssetBundleName好像没法加hash值,因为不确定这个值,我在用微信官方提供的转换小游戏工具,它的缓存机制需要ab包打包设置BuildAssetBundleOptions.AppendHashToAssetBundleName,这个我应该怎么处理好呢。

缺少命名空间

先说一句这个项目太棒了,文档很详细!
但是导入unity 2020.1.14f的时候出现如下错误
Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(3,22): error CS0234: The type or namespace name 'Remoting' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?) Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(4,22): error CS0234: The type or namespace name 'Remoting' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?) Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(11,48): error CS0246: The type or namespace name 'RealProxy' could not be found (are you missing a using directive or an assembly reference?) Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(49,48): error CS0246: The type or namespace name 'IMessage' could not be found (are you missing a using directive or an assembly reference?) Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(49,32): error CS0246: The type or namespace name 'IMessage' could not be found (are you missing a using directive or an assembly reference?) Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(37,39): error CS0115: 'AspectProxyBase<T>.GetTransparentProxy()': no suitable method found to override Assets\HTFramework-master\RunTime\AspectTrack\Base\AspectProxyBase.cs(49,41): error CS0115: 'AspectProxyBase<T>.Invoke(IMessage)': no suitable method found to override

DefaultResourceHelper 能否将单线加载 改为并行资源加载

单线会导致整体资源加载时间变长,特别是在需要加载大量资源的情况下。这种串行加载的方式虽然可以避免一些并发加载的问题,但在游戏启动或运行过程中可能导致明显的延迟。

public IEnumerator LoadAssetAsync<T>(ResourceInfoBase info, HTFAction<float> onLoading, HTFAction<T> onLoadDone, bool isPrefab, Transform parent, bool isUI) where T : UnityEngine.Object
        {
            float beginTime = Time.realtimeSinceStartup;

            //单线加载,如果其他地方在加载资源,则等待
            if (_isLoading)
            {
                yield return _loadWait;
            }

            //轮到本线路加载资源
            _isLoading = true;

            //等待相关依赖资源的加载
            yield return LoadDependenciesAssetBundleAsync(info.AssetBundleName);

            float waitTime = Time.realtimeSinceStartup;

            UnityEngine.Object asset = null;

            if (LoadMode == ResourceLoadMode.Resource)
            {
                ResourceRequest request = Resources.LoadAsync<T>(info.ResourcePath);
                while (!request.isDone)
                {
                    onLoading?.Invoke(request.progress);
                    yield return null;
                }
                onLoading?.Invoke(1);
                asset = request.asset;
                if (asset)
                {
                    if (isPrefab)
                    {
                        asset = ClonePrefab(asset as GameObject, parent, isUI);
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Resource, $"加载资源失败:Resources文件夹中不存在资源 {info.ResourcePath}!");
                }
            }
            else
            {
#if UNITY_EDITOR
                if (IsEditorMode)
                {
                    onLoading?.Invoke(1);
                    yield return null;

                    asset = AssetDatabase.LoadAssetAtPath<T>(info.AssetPath);
                    if (asset)
                    {
                        if (isPrefab)
                        {
                            asset = ClonePrefab(asset as GameObject, parent, isUI);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Resource, $"加载资源失败:路径中不存在资源 {info.AssetPath}!");
                    }
                }
                else
                {
                    yield return LoadAssetBundleAsync(info.AssetBundleName, onLoading);

                    if (AssetBundles.ContainsKey(info.AssetBundleName))
                    {
                        asset = AssetBundles[info.AssetBundleName].LoadAsset<T>(info.AssetPath);
                        if (asset)
                        {
                            if (isPrefab)
                            {
                                asset = ClonePrefab(asset as GameObject, parent, isUI);
                            }
                        }
                        else
                        {
                            throw new HTFrameworkException(HTFrameworkModule.Resource, $"加载资源失败:AB包 {info.AssetBundleName} 中不存在资源 {info.AssetPath}!");
                        }
                    }
                }
#else
                yield return LoadAssetBundleAsync(info.AssetBundleName, onLoading);

                if (AssetBundles.ContainsKey(info.AssetBundleName))
                {
                    asset = AssetBundles[info.AssetBundleName].LoadAsset<T>(info.AssetPath);
                    if (asset)
                    {
                        if (isPrefab)
                        {
                            asset = ClonePrefab(asset as GameObject, parent, isUI);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.Resource, $"加载资源失败:AB包 {info.AssetBundleName} 中不存在资源 {info.AssetPath}!");
                    }
                }
#endif
            }

            float endTime = Time.realtimeSinceStartup;

            Log.Info(string.Format("异步加载资源{0}[{1}模式]:\r\n{2}\r\n等待耗时:{3}秒  加载耗时:{4}秒"
                , asset ? "成功" : "失败"
                , LoadMode.ToString()
                , LoadMode == ResourceLoadMode.Resource ? info.GetResourceFullPath() : info.GetAssetBundleFullPath(AssetBundleRootPath)
                , waitTime - beginTime
                , endTime - waitTime));

            if (asset)
            {
                DataSetInfo dataSet = info as DataSetInfo;
                if (dataSet != null && dataSet.Data != null)
                {
                    asset.Cast<DataSetBase>().Fill(dataSet.Data);
                }

                onLoadDone?.Invoke(asset as T);
            }
            else
            {
                onLoadDone?.Invoke(null);
            }
            asset = null;

            //本线路加载资源结束
            _isLoading = false;
        }

是否可以将UI元素注入UIRegion?

UIRegion中是否可以通过反射(或其他方式)得到当前UI的元素?
类似 [InejctPath("")] 的方式。

虽然在UIRegion中可以通过 Parent 获取当前UI,但业务逻辑定义和UI注入处在不同的地方,可能解耦得不够彻底。

感谢您的解答!

UI Entity 会重复创建

当LoadPrefab时间较长时,在此期间多次调用Main.m_UI.OpenUI ,会产生多个 UIEntity

  /// <summary>
        /// 创建并打开UI实体
        /// </summary>
        /// <param name="uIResource">UI资源标记</param>
        /// <param name="uITypeName">UI逻辑类型</param>
        /// <param name="uILogic">UI逻辑类对象</param>
        /// <param name="uIParent">UI的父级</param>
        /// <param name="args">UI打开的参数</param>
        /// <returns>加载协程</returns>
        private Coroutine CreateOpenUIEntity(UIResourceAttribute uIResource, string uITypeName, UILogicBase uILogic, Transform uIParent, params object[] args)
        {
            if (uILogic.IsOpened)
                return null;

            if (!uILogic.IsCreated)
            {
                if (_defineUIAndEntitys.ContainsKey(uITypeName) && _defineUIAndEntitys[uITypeName] != null)
                {
                    uILogic.UIEntity = Main.Clone(_defineUIAndEntitys[uITypeName], uIParent);
                    uILogic.UIEntity.SetActive(true);
                    uILogic.OnInit();
                    uILogic.OnOpen(args);
                    PlaceTopUIEntity(uILogic as UILogicResident);
                    return null;
                }
                else
                {
                    return Main.m_Resource.LoadPrefab(new PrefabInfo(uIResource), uIParent, null, (obj) =>
                    {
                        uILogic.UIEntity = obj;
                        uILogic.UIEntity.SetActive(true);
                        uILogic.OnInit();
                        uILogic.OnOpen(args);
                        PlaceTopUIEntity(uILogic as UILogicResident);
                    }, true);
                }
            }
            else
            {
                uILogic.UIEntity.SetActive(true);
                uILogic.OnOpen(args);
                PlaceTopUIEntity(uILogic as UILogicResident);
                return null;
            }
        }

LoadSceneAsync add an AsyncOperation callback

//SceneInfo .cs
public sealed class SceneInfo : ResourceInfoBase
   {
       public LoadSceneMode LoadMode
       {
           get;
           protected set;
       }
       public SceneInfo(string assetBundleName, string assetPath, string sceneName,LoadSceneMode loadMode=LoadSceneMode.Additive) : base(assetBundleName, assetPath, sceneName)
       {
           LoadMode = loadMode;
       }
   }  
//DefaultResourceHelper.cs
public IEnumerator LoadSceneAsync(SceneInfo info,  HTFAction<float> loadingAction, HTFAction<AsyncOperation> loadedBundleAction,HTFAction loadDoneAction)
       {
           float beginTime = Time.realtimeSinceStartup;

           //单线加载,如果其他地方在加载资源,则等待
           if (_isLoading)
           {
               yield return _loadWait;
           }

           //轮到本线路加载资源
           _isLoading = true;

           //等待相关依赖资源的加载
           yield return LoadDependenciesAssetBundleAsync(info.AssetBundleName);

           float waitTime = Time.realtimeSinceStartup;

           if (LoadMode == ResourceLoadMode.Resource)
           {
               throw new HTFrameworkException(HTFrameworkModule.Resource, "加载场景失败:场景加载不允许使用Resource模式!");
           }
           else
           {
#if UNITY_EDITOR
               if (IsEditorMode)
               {
                   LoadSceneParameters parameters = new LoadSceneParameters()
                   {
                       loadSceneMode = LoadSceneMode.Additive,
                       localPhysicsMode = LocalPhysicsMode.None
                   };
                   yield return EditorSceneManager.LoadSceneAsyncInPlayMode(info.AssetPath, parameters);
               }
               else
               {
                   yield return LoadAssetBundleAsync(info.AssetBundleName, loadingAction);
                   var asyncOp = SceneManager.LoadSceneAsync(info.ResourcePath, info.LoadMode);
                   loadedBundleAction?.Invoke(asyncOp);
                   yield return asyncOp;
               }
#else
               yield return LoadAssetBundleAsync(info.AssetBundleName, loadingAction);
               var asyncOp = SceneManager.LoadSceneAsync(info.ResourcePath, info.LoadMode);
               loadedBundleAction?.Invoke(asyncOp);
               yield return asyncOp;
               // yield return SceneManager.LoadSceneAsync(info.ResourcePath, LoadSceneMode.Additive);
#endif
           }

           float endTime = Time.realtimeSinceStartup;

           Log.Info(string.Format("异步加载场景完成[{0}模式]:{1}\r\n等待耗时:{2}秒  加载耗时:{3}秒"
               , LoadMode.ToString()
               , info.ResourcePath
               , waitTime - beginTime
               , endTime - waitTime));

           loadDoneAction?.Invoke();

           //本线路加载资源结束
           _isLoading = false;
       }

加载AssetBundle好像有问题

isManifest=false时,调用了GetAssetBundleHash方法,报NullReferenceException
代码:
UnityWebRequest request = isManifest
? UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + assetBundleName)
: UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + assetBundleName,GetAssetBundleHash(assetBundleName))

ProtocolChannelBase

      /// <summary>
        /// 发送消息(需要保持连接的协议)
        /// </summary>
        private void SendMessageNeedConnect()
        {
            while (_isEnableThread)
            {
                if (IsConnect && _isCanSend && _sendDataBuffer.Count > 0)
                {
                    int sendCount = Client.Send(_sendDataBuffer[0], _sendDataBuffer[0].Length, 0);
                    if (sendCount > 0)
                    {
                        _sendDataBuffer.RemoveAt(0);

                        Main.Current.QueueOnMainThread(() =>
                        {
                            SendMessageEvent?.Invoke(this);
                        });
                    }
                }
            }
        }

error

会出现_sendDataBuffer[0] 为空的情况

我如果修改了打包方法,做了AB包加密,是否只能自己实现DefaultResourceHelper,无法实现加载进度条了?

我打AB包的时候做了Offset加密,官方的加载方式是

//第三个参数是Offset,这样就完成了解密并加载
AssetBundle assetBundle = AssetBundle.LoadFromFile(filePath, 0, 2);

但默认的资源加载助手采用的是UnityWebRequestAssetBundle.GetAssetBundle的实现方式
而这种方式不支持传入Offset参数进行解密加载

那我是否只能自己实现ResourceHelper,这样就无法使用加载进度条了

新建了一个MyDefaultResourceHelper,无法切换回DefaultResourceHelper了

我对新建了一个MyDefaultResourceHelper,在ResourceManager面板选择后正常使用

但当我想切换回DefaultResourceHelper时,一旦运行就自动变成MyDefaultResourceHelper了

无法正常切换使用

image

image

image

下图的切换逻辑有问题,点一次并会不更改_module.HelperType,需要再点一次
image

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.