saitinghu / htframework Goto Github PK
View Code? Open in Web Editor NEWUnity HTFramework, a rapid development framework of client based on Unity.
License: MIT License
Unity HTFramework, a rapid development framework of client based on Unity.
License: MIT License
目前仅支持UGUI部分组件,未来是否支持TextMeshPro?
或扩展为接口,支持自定义组件类型
资源管理面板中如果资源过多,全部展示会一直卡着,建议对资源列表进行分页展示处理
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值,UI逻辑类标记的AssetBundleName好像没法加hash值,因为不确定这个值,我在用微信官方提供的转换小游戏工具,它的缓存机制需要ab包打包设置BuildAssetBundleOptions.AppendHashToAssetBundleName,这个我应该怎么处理好呢。
RT,准备下载研究一下
先说一句这个项目太棒了,文档很详细!
但是导入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
Hi @SaiTingHu ,
HTFamework is an awesome framework to make Unity game. For now, is this support export game to ios yet?
Thank you
!
单线会导致整体资源加载时间变长,特别是在需要加载大量资源的情况下。这种串行加载的方式虽然可以避免一些并发加载的问题,但在游戏启动或运行过程中可能导致明显的延迟。
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;
}
UIRegion中是否可以通过反射(或其他方式)得到当前UI的元素?
类似 [InejctPath("")]
的方式。
虽然在UIRegion中可以通过 Parent 获取当前UI,但业务逻辑定义和UI注入处在不同的地方,可能解耦得不够彻底。
感谢您的解答!
当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;
}
}
//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;
}
isManifest=false时,调用了GetAssetBundleHash方法,报NullReferenceException
代码:
UnityWebRequest request = isManifest
? UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + assetBundleName)
: UnityWebRequestAssetBundle.GetAssetBundle(AssetBundleRootPath + assetBundleName,GetAssetBundleHash(assetBundleName))
/// <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);
});
}
}
}
}
会出现_sendDataBuffer[0] 为空的情况
我打AB包的时候做了Offset加密,官方的加载方式是
//第三个参数是Offset,这样就完成了解密并加载
AssetBundle assetBundle = AssetBundle.LoadFromFile(filePath, 0, 2);
但默认的资源加载助手采用的是UnityWebRequestAssetBundle.GetAssetBundle的实现方式
而这种方式不支持传入Offset参数进行解密加载
那我是否只能自己实现ResourceHelper,这样就无法使用加载进度条了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.