diff --git a/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs b/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs index 499877b87d07105cac0d7ec3f569e075098ee69e..01ddcb08a23aafe9189c206251158bdb05885583 100644 --- a/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs +++ b/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs @@ -7,15 +7,13 @@ namespace Model /// 消息分发组件 /// [ObjectEvent(EntityEventId.MessageDispatherComponent)] - public class MessageDispatherComponent: Component, IAwake, ILoad + public class MessageDispatherComponent: Component, IAwake, ILoad { - private AppType AppType; private Dictionary> handlers; private DoubleMap opcodeTypes = new DoubleMap(); - public void Awake(AppType appType) + public void Awake() { - this.AppType = appType; this.Load(); } diff --git a/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta b/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta index b3a181170d6148b04fd89262188ec72fdc305b6e..d520cd55ad9e79903d5a5505d220ff7aba3154f0 100644 --- a/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta +++ b/Unity/Assets/Scripts/Component/MessageDispatherComponent.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 8e97599ee372f6f40aaa5e743851a74c -timeCreated: 1498117781 +timeCreated: 1498200974 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Unity/Assets/Scripts/Component/ResourcesComponent.cs b/Unity/Assets/Scripts/Component/ResourcesComponent.cs index 5cb7f460796b50484bd1c979157884d3798d1de7..9fbec81b479810d3230c1b7718bd6b548aae2130 100644 --- a/Unity/Assets/Scripts/Component/ResourcesComponent.cs +++ b/Unity/Assets/Scripts/Component/ResourcesComponent.cs @@ -99,17 +99,9 @@ namespace Model { // 异步load资源到内存cache住 UnityEngine.Object[] assets; - AssetBundleLoaderAsync assetBundleLoaderAsync = null; - try - { - assetBundleLoaderAsync = new AssetBundleLoaderAsync(assetBundle); - - assets = await assetBundleLoaderAsync.LoadAllAssetsAsync(); - - } - finally - { - assetBundleLoaderAsync?.Dispose(); + using (AssetBundleLoaderAsync assetBundleLoaderAsync = new AssetBundleLoaderAsync(assetBundle)) + { + assets = await assetBundleLoaderAsync.LoadAllAssetsAsync(); } diff --git a/Unity/Assets/Scripts/Entity/Scene.cs b/Unity/Assets/Scripts/Entity/Scene.cs index 25ed10dd7a8ee0af70295e9d1f148434a0640c92..6208899f4960b95905907ef037e346da72e0909e 100644 --- a/Unity/Assets/Scripts/Entity/Scene.cs +++ b/Unity/Assets/Scripts/Entity/Scene.cs @@ -21,8 +21,6 @@ public string Name { get; set; } - public SceneType SceneType { get; private set; } - public Scene(): base(EntityType.Scene) { } diff --git a/Unity/Assets/Scripts/Init.cs b/Unity/Assets/Scripts/Init.cs index cd59408fcdafd6b270faf36a07ea6b98384b2640..21bf3ea1c657a0c416cdf96903b90bdcb7e0e00d 100644 --- a/Unity/Assets/Scripts/Init.cs +++ b/Unity/Assets/Scripts/Init.cs @@ -34,7 +34,7 @@ namespace Model this.RegisterDelegate(); this.RegisterRedirection(); - IType hotfixInitType = AppDomain.LoadedTypes["Hotfix.HotfixInit"]; + IType hotfixInitType = AppDomain.LoadedTypes["Hotfix.Init"]; start = hotfixInitType.GetMethod("Start", 0); update = hotfixInitType.GetMethod("Update", 0); onApplicationQuit = hotfixInitType.GetMethod("OnApplicationQuit", 0); @@ -50,9 +50,9 @@ namespace Model private void Update() { - ObjectEvents.Instance.Update(); - this.AppDomain.Invoke(this.update, null, this.param0); + + ObjectEvents.Instance.Update(); } private void OnApplicationQuit() @@ -75,14 +75,14 @@ namespace Model public unsafe void RegisterRedirection() { - var mi = typeof(Log).GetMethod("Debug", new System.Type[] { typeof(string) }); + MethodInfo mi = typeof(Log).GetMethod("Debug", new Type[] { typeof(string) }); this.AppDomain.RegisterCLRMethodRedirection(mi, ILRedirection.LogDebug); } public void RegisterDelegate() { AppDomain.DelegateManager.RegisterMethodDelegate(); - AppDomain.DelegateManager.RegisterMethodDelegate(); + AppDomain.DelegateManager.RegisterMethodDelegate(); } diff --git a/Unity/Hotfix/Component/ResourcesComponent.cs b/Unity/Hotfix/Component/ResourcesComponent.cs deleted file mode 100644 index e3304d160b6a78ea8bb62e1d8696948a645149bd..0000000000000000000000000000000000000000 --- a/Unity/Hotfix/Component/ResourcesComponent.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Model; -using UnityEngine; - -namespace Hotfix -{ - [ObjectEvent(EntityEventId.ResourcesComponent)] - public class ResourcesComponent: Component - { - public static AssetBundleManifest AssetBundleManifestObject { get; set; } - - private readonly Dictionary resourceCache = new Dictionary(); - - private readonly Dictionary bundleCaches = new Dictionary(); - - public K GetReference(string bundle, string prefab, string key) where K : class - { - GameObject gameObject = this.GetAsset(bundle, prefab); - return gameObject.GetComponent().Get(key); - } - - public K GetAsset(string bundleName, string prefab) where K : class - { - string path = $"{bundleName}.unity3d/{prefab}".ToLower(); - - UnityEngine.Object resource = null; - if (this.resourceCache.TryGetValue(path, out resource)) - { - return resource as K; - } - - if (Define.LoadResourceType == LoadResourceType.Async) - { - if (!this.bundleCaches.ContainsKey($"{bundleName}.unity3d".ToLower())) - { - return null; - } - - throw new Exception($"异步加载资源,资源不在resourceCache中: {bundleName} {path}"); - } - - try - { - resource = ResourceHelper.LoadResource(bundleName, prefab); - this.resourceCache.Add(path, resource); - } - catch (Exception e) - { - throw new Exception($"加载资源出错,输入路径:{path}", e); - } - - return resource as K; - } - - public async Task DownloadAndCacheAsync(string uri, string assetBundleName) - { - assetBundleName = (assetBundleName + ".unity3d").ToLower(); - - AssetBundle assetBundle; - // 异步下载资源 - string url = uri + "StreamingAssets/" + assetBundleName; - int count = 0; - while (true) - { - WWWAsync wwwAsync = null; - try - { - ++count; - if (count > 1) - { - await Hotfix.Scene.GetComponent().WaitAsync(2000); - } - - if (this.Id == 0) - { - return; - } - - wwwAsync = new WWWAsync(); - - await wwwAsync.LoadFromCacheOrDownload(url, ResourcesComponent.AssetBundleManifestObject.GetAssetBundleHash(assetBundleName)); - assetBundle = wwwAsync.www.assetBundle; - - break; - } - catch (Exception e) - { - Log.Error(e.ToString()); - } - finally - { - wwwAsync?.Dispose(); - } - } - - if (!assetBundle.isStreamedSceneAssetBundle) - { - // 异步load资源到内存cache住 - UnityEngine.Object[] assets; - AssetBundleLoaderAsync assetBundleLoaderAsync = null; - try - { - assetBundleLoaderAsync = new AssetBundleLoaderAsync(assetBundle); - - assets = await assetBundleLoaderAsync.LoadAllAssetsAsync(); - - } - finally - { - assetBundleLoaderAsync?.Dispose(); - } - - - foreach (UnityEngine.Object asset in assets) - { - string path = $"{assetBundleName}/{asset.name}".ToLower(); - this.resourceCache[path] = asset; - } - } - - if (this.bundleCaches.ContainsKey(assetBundleName)) - { - throw new Exception($"重复加载资源: {assetBundleName}"); - } - this.bundleCaches[assetBundleName] = assetBundle; - } - - public override void Dispose() - { - if (this.Id == 0) - { - return; - } - - base.Dispose(); - - foreach (var assetBundle in bundleCaches) - { - assetBundle.Value?.Unload(true); - } - } - } -} \ No newline at end of file diff --git a/Unity/Hotfix/Component/UIComponent.cs b/Unity/Hotfix/Component/UIComponent.cs index a222e1c823141c673a5faf424c7959ece87fdeec..91d9139f734ba0f6bf135beb2c3c38e2be85838c 100644 --- a/Unity/Hotfix/Component/UIComponent.cs +++ b/Unity/Hotfix/Component/UIComponent.cs @@ -23,7 +23,7 @@ namespace Hotfix this.params3[0] = scene; this.params3[1] = type; this.params3[2] = parent; - return (UI)Init.Instance.AppDomain.Invoke(this.methodInfo, this.instance, this.params3); + return (UI)Model.Init.Instance.AppDomain.Invoke(this.methodInfo, this.instance, this.params3); } } diff --git a/Unity/Hotfix/Entity/Scene.cs b/Unity/Hotfix/Entity/Scene.cs index 33fb5d6821c25add6629cd564efef8c0ad488632..f769adec5cd4213c8820b1de8617e3f3410e946b 100644 --- a/Unity/Hotfix/Entity/Scene.cs +++ b/Unity/Hotfix/Entity/Scene.cs @@ -19,9 +19,9 @@ { public Scene Parent { get; set; } - public string Name { get; set; } + public Model.Scene ModelScene { get; set; } = new Model.Scene(); - public SceneType SceneType { get; private set; } + public string Name { get; set; } public Scene(): base(EntityType.Scene) { @@ -39,6 +39,8 @@ } base.Dispose(); + + this.ModelScene.Dispose(); } } } \ No newline at end of file diff --git a/Unity/Hotfix/HotfixInit.cs b/Unity/Hotfix/Init.cs similarity index 78% rename from Unity/Hotfix/HotfixInit.cs rename to Unity/Hotfix/Init.cs index c8d922ccffa4f2f3ced93bdcee91201716bb0231..eca46c6f20aa76730011e099d83a348a1be71a13 100644 --- a/Unity/Hotfix/HotfixInit.cs +++ b/Unity/Hotfix/Init.cs @@ -3,13 +3,14 @@ using Model; namespace Hotfix { - public static class HotfixInit + public static class Init { private static void Start() { try { - Hotfix.Scene.AddComponent(); + Hotfix.Scene.ModelScene.AddComponent(); + Hotfix.Scene.ModelScene.AddComponent(); Hotfix.Scene.AddComponent(); Hotfix.Scene.AddComponent(); Hotfix.Scene.GetComponent().Run(EventIdType.InitSceneStart); diff --git a/Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs b/Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs index 31f266e9094e902486bef2a5ee543e47ae471c0e..e05629f9c324e8077490cf73016244d1d4298699 100644 --- a/Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs +++ b/Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs @@ -1,6 +1,5 @@ using Model; using UnityEngine; -using Object = UnityEngine.Object; namespace Hotfix { @@ -9,7 +8,7 @@ namespace Hotfix { public UI Create(Scene scene, int type, UI parent) { - GameObject bundleGameObject = scene.GetComponent().GetAsset("uilobby", "Lobby"); + GameObject bundleGameObject = scene.ModelScene.GetComponent().GetAsset("uilobby", "Lobby"); GameObject lobby = UnityEngine.Object.Instantiate(bundleGameObject); lobby.layer = LayerMask.NameToLayer(LayerNames.UI); UI ui = new UI(scene, type, parent, lobby); diff --git a/Unity/Hotfix/Unity.Hotfix.csproj b/Unity/Hotfix/Unity.Hotfix.csproj index 800c92b50cdc8ec52cdea5c0b7fc228447b58630..42e5e14c937e6507227b8f5c47286ceee300cf56 100644 --- a/Unity/Hotfix/Unity.Hotfix.csproj +++ b/Unity/Hotfix/Unity.Hotfix.csproj @@ -56,7 +56,7 @@ - + @@ -71,7 +71,6 @@ -