diff --git a/GameFramework/Base/GameFrameworkEntry.cs b/GameFramework/Base/GameFrameworkEntry.cs index c5fd83086..95d193293 100644 --- a/GameFramework/Base/GameFrameworkEntry.cs +++ b/GameFramework/Base/GameFrameworkEntry.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; -using System.Reflection; namespace GameFramework { @@ -16,32 +15,9 @@ namespace GameFramework /// public static class GameFrameworkEntry { - private const string GameFrameworkVersion = "3.0.0"; - private static readonly IDictionary s_AssemblyGameFrameworkModules = new Dictionary(); + private const string GameFrameworkVersion = "3.0.0.p1"; private static readonly LinkedList s_GameFrameworkModules = new LinkedList(); - /// - /// 初始化游戏框架入口的新实例。 - /// - static GameFrameworkEntry() - { - Type gameFrameworkModule = typeof(GameFrameworkModule); - Type[] types = Assembly.GetExecutingAssembly().GetTypes(); - foreach (Type i in types) - { - if (i.BaseType != gameFrameworkModule) - { - continue; - } - - Type[] interfaces = i.GetInterfaces(); - foreach (Type j in interfaces) - { - s_AssemblyGameFrameworkModules.Add(j.FullName, i); - } - } - } - /// /// 获取游戏框架版本号。 /// @@ -93,10 +69,16 @@ public static T GetModule() where T : class throw new GameFrameworkException(string.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName)); } - Type moduleType = null; - if (!s_AssemblyGameFrameworkModules.TryGetValue(interfaceType.FullName, out moduleType)) + if (!interfaceType.FullName.StartsWith("GameFramework.")) + { + throw new GameFrameworkException(string.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName)); + } + + string moduleName = string.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); + Type moduleType = Type.GetType(moduleName); + if (moduleType == null) { - throw new GameFrameworkException(string.Format("Can not find module '{0}'.", interfaceType.FullName)); + throw new GameFrameworkException(string.Format("Can not find Game Framework module type '{0}'.", moduleName)); } return GetModule(moduleType) as T; diff --git a/GameFramework/DataTable/DataTableManager.cs b/GameFramework/DataTable/DataTableManager.cs index 249e24966..62f61ee3f 100644 --- a/GameFramework/DataTable/DataTableManager.cs +++ b/GameFramework/DataTable/DataTableManager.cs @@ -419,7 +419,10 @@ private void LoadDataTableSuccessCallback(string dataTableAssetName, object data m_DataTableHelper.ReleaseDataTableAsset(dataTableAsset); } - m_LoadDataTableSuccessEventHandler?.Invoke(this, new LoadDataTableSuccessEventArgs(dataTableAssetName, duration, userData)); + if (m_LoadDataTableSuccessEventHandler != null) + { + m_LoadDataTableSuccessEventHandler(this, new LoadDataTableSuccessEventArgs(dataTableAssetName, duration, userData)); + } } private void LoadDataTableFailureCallback(string dataTableAssetName, LoadResourceStatus status, string errorMessage, object userData) @@ -436,12 +439,18 @@ private void LoadDataTableFailureCallback(string dataTableAssetName, LoadResourc private void LoadDataTableUpdateCallback(string dataTableAssetName, float progress, object userData) { - m_LoadDataTableUpdateEventHandler?.Invoke(this, new LoadDataTableUpdateEventArgs(dataTableAssetName, progress, userData)); + if (m_LoadDataTableUpdateEventHandler != null) + { + m_LoadDataTableUpdateEventHandler(this, new LoadDataTableUpdateEventArgs(dataTableAssetName, progress, userData)); + } } private void LoadDataTableDependencyAssetCallback(string dataTableAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { - m_LoadDataTableDependencyAssetEventHandler?.Invoke(this, new LoadDataTableDependencyAssetEventArgs(dataTableAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + if (m_LoadDataTableDependencyAssetEventHandler != null) + { + m_LoadDataTableDependencyAssetEventHandler(this, new LoadDataTableDependencyAssetEventArgs(dataTableAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + } } } } diff --git a/GameFramework/Download/DownloadManager.DownloadAgent.cs b/GameFramework/Download/DownloadManager.DownloadAgent.cs index 7570bf3d4..4147e6a2f 100644 --- a/GameFramework/Download/DownloadManager.DownloadAgent.cs +++ b/GameFramework/Download/DownloadManager.DownloadAgent.cs @@ -201,7 +201,10 @@ public void Start(DownloadTask task) m_StartLength = m_SavedLength = m_DownloadedLength = 0; } - DownloadAgentStart?.Invoke(this); + if (DownloadAgentStart != null) + { + DownloadAgentStart(this); + } if (m_StartLength > 0) { @@ -306,7 +309,10 @@ private void OnDownloadAgentHelperUpdate(object sender, DownloadAgentHelperUpdat m_DownloadedLength = e.Length; - DownloadAgentUpdate?.Invoke(this, bytes != null ? bytes.Length : 0); + if (DownloadAgentUpdate != null) + { + DownloadAgentUpdate(this, bytes != null ? bytes.Length : 0); + } } private void OnDownloadAgentHelperComplete(object sender, DownloadAgentHelperCompleteEventArgs e) @@ -336,7 +342,10 @@ private void OnDownloadAgentHelperComplete(object sender, DownloadAgentHelperCom m_Task.Status = DownloadTaskStatus.Done; - DownloadAgentSuccess?.Invoke(this, bytes != null ? bytes.Length : 0); + if (DownloadAgentSuccess != null) + { + DownloadAgentSuccess(this, bytes != null ? bytes.Length : 0); + } m_Task.Done = true; } @@ -352,7 +361,10 @@ private void OnDownloadAgentHelperError(object sender, DownloadAgentHelperErrorE m_Task.Status = DownloadTaskStatus.Error; - DownloadAgentFailure?.Invoke(this, e.ErrorMessage); + if (DownloadAgentFailure != null) + { + DownloadAgentFailure(this, e.ErrorMessage); + } m_Task.Done = true; } diff --git a/GameFramework/Download/DownloadManager.cs b/GameFramework/Download/DownloadManager.cs index 7d05aebde..733ee339f 100644 --- a/GameFramework/Download/DownloadManager.cs +++ b/GameFramework/Download/DownloadManager.cs @@ -291,24 +291,36 @@ public void RemoveAllDownload() private void OnDownloadAgentStart(DownloadAgent sender) { - m_DownloadStartEventHandler?.Invoke(this, new DownloadStartEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + if (m_DownloadStartEventHandler != null) + { + m_DownloadStartEventHandler(this, new DownloadStartEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + } } private void OnDownloadAgentUpdate(DownloadAgent sender, int lastDownloadedLength) { m_DownloadCounter.RecordDownloadedLength(lastDownloadedLength); - m_DownloadUpdateEventHandler?.Invoke(this, new DownloadUpdateEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + if (m_DownloadUpdateEventHandler != null) + { + m_DownloadUpdateEventHandler(this, new DownloadUpdateEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + } } private void OnDownloadAgentSuccess(DownloadAgent sender, int lastDownloadedLength) { m_DownloadCounter.RecordDownloadedLength(lastDownloadedLength); - m_DownloadSuccessEventHandler?.Invoke(this, new DownloadSuccessEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + if (m_DownloadSuccessEventHandler != null) + { + m_DownloadSuccessEventHandler(this, new DownloadSuccessEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, sender.CurrentLength, sender.Task.UserData)); + } } private void OnDownloadAgentFailure(DownloadAgent sender, string errorMessage) { - m_DownloadFailureEventHandler?.Invoke(this, new DownloadFailureEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, errorMessage, sender.Task.UserData)); + if (m_DownloadFailureEventHandler != null) + { + m_DownloadFailureEventHandler(this, new DownloadFailureEventArgs(sender.Task.SerialId, sender.Task.DownloadPath, sender.Task.DownloadUri, errorMessage, sender.Task.UserData)); + } } } } diff --git a/GameFramework/Entity/EntityManager.cs b/GameFramework/Entity/EntityManager.cs index 047b94625..0b77ca61c 100644 --- a/GameFramework/Entity/EntityManager.cs +++ b/GameFramework/Entity/EntityManager.cs @@ -933,7 +933,11 @@ private void InternalShowEntity(int entityId, string entityAssetName, string ent entityInfo.Status = EntityStatus.WillShow; entity.OnShow(userData); entityInfo.Status = EntityStatus.Showed; - m_ShowEntitySuccessEventHandler?.Invoke(this, new ShowEntitySuccessEventArgs(entityAssetName, entity, duration, userData)); + + if (m_ShowEntitySuccessEventHandler != null) + { + m_ShowEntitySuccessEventHandler(this, new ShowEntitySuccessEventArgs(entityAssetName, entity, duration, userData)); + } } catch (Exception exception) { @@ -974,7 +978,10 @@ private void InternalHideEntity(EntityInfo entityInfo, object userData) throw new GameFrameworkException("Entity info is unmanaged."); } - m_HideEntityCompleteEventHandler?.Invoke(this, new HideEntityCompleteEventArgs(entity.Id, userData)); + if (m_HideEntityCompleteEventHandler != null) + { + m_HideEntityCompleteEventHandler(this, new HideEntityCompleteEventArgs(entity.Id, userData)); + } m_RecycleQueue.AddLast(new RecycleNode(entityInfo)); } @@ -1035,7 +1042,10 @@ private void InstantiateEntityUpdateCallback(string entityAssetName, float progr throw new GameFrameworkException("Show entity info is invalid."); } - m_ShowEntityUpdateEventHandler?.Invoke(this, new ShowEntityUpdateEventArgs(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroupName, progress, showEntityInfo.UserData)); + if (m_ShowEntityUpdateEventHandler != null) + { + m_ShowEntityUpdateEventHandler(this, new ShowEntityUpdateEventArgs(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroupName, progress, showEntityInfo.UserData)); + } } private void InstantiateEntityDependencyAssetCallback(string entityAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) @@ -1046,7 +1056,10 @@ private void InstantiateEntityDependencyAssetCallback(string entityAssetName, st throw new GameFrameworkException("Show entity info is invalid."); } - m_ShowEntityDependencyAssetEventHandler?.Invoke(this, new ShowEntityDependencyAssetEventArgs(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroupName, dependencyAssetName, loadedCount, totalCount, showEntityInfo.UserData)); + if (m_ShowEntityDependencyAssetEventHandler != null) + { + m_ShowEntityDependencyAssetEventHandler(this, new ShowEntityDependencyAssetEventArgs(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroupName, dependencyAssetName, loadedCount, totalCount, showEntityInfo.UserData)); + } } } } diff --git a/GameFramework/Fsm/FsmState.cs b/GameFramework/Fsm/FsmState.cs index b42edac82..2b7c93bd5 100644 --- a/GameFramework/Fsm/FsmState.cs +++ b/GameFramework/Fsm/FsmState.cs @@ -158,7 +158,10 @@ internal void OnEvent(IFsm fsm, object sender, int eventId, object userData) FsmEventHandler eventHandlers = null; if (m_EventHandlers.TryGetValue(eventId, out eventHandlers)) { - eventHandlers?.Invoke(fsm, sender, userData); + if (eventHandlers != null) + { + eventHandlers(fsm, sender, userData); + } } } } diff --git a/GameFramework/Localization/LocalizationManager.cs b/GameFramework/Localization/LocalizationManager.cs index 5c3d9ee83..aa0e5e095 100644 --- a/GameFramework/Localization/LocalizationManager.cs +++ b/GameFramework/Localization/LocalizationManager.cs @@ -381,7 +381,10 @@ private void LoadDictionarySuccessCallback(string dictionaryAssetName, object di m_LocalizationHelper.ReleaseDictionaryAsset(dictionaryAsset); } - m_LoadDictionarySuccessEventHandler?.Invoke(this, new LoadDictionarySuccessEventArgs(dictionaryAssetName, duration, userData)); + if (m_LoadDictionarySuccessEventHandler != null) + { + m_LoadDictionarySuccessEventHandler(this, new LoadDictionarySuccessEventArgs(dictionaryAssetName, duration, userData)); + } } private void LoadDictionaryFailureCallback(string dictionaryAssetName, LoadResourceStatus status, string errorMessage, object userData) @@ -398,12 +401,18 @@ private void LoadDictionaryFailureCallback(string dictionaryAssetName, LoadResou private void LoadDictionaryUpdateCallback(string dictionaryAssetName, float progress, object userData) { - m_LoadDictionaryUpdateEventHandler?.Invoke(this, new LoadDictionaryUpdateEventArgs(dictionaryAssetName, progress, userData)); + if (m_LoadDictionaryUpdateEventHandler != null) + { + m_LoadDictionaryUpdateEventHandler(this, new LoadDictionaryUpdateEventArgs(dictionaryAssetName, progress, userData)); + } } private void LoadDictionaryDependencyAssetCallback(string dictionaryAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { - m_LoadDictionaryDependencyAssetEventHandler?.Invoke(this, new LoadDictionaryDependencyAssetEventArgs(dictionaryAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + if (m_LoadDictionaryDependencyAssetEventHandler != null) + { + m_LoadDictionaryDependencyAssetEventHandler(this, new LoadDictionaryDependencyAssetEventArgs(dictionaryAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + } } } } diff --git a/GameFramework/Network/NetworkManager.NetworkChannel.cs b/GameFramework/Network/NetworkManager.NetworkChannel.cs index 5149496bd..7f647d7c9 100644 --- a/GameFramework/Network/NetworkManager.NetworkChannel.cs +++ b/GameFramework/Network/NetworkManager.NetworkChannel.cs @@ -507,7 +507,10 @@ public void Close() m_Socket = null; m_ReceiveState = null; - NetworkChannelClosed?.Invoke(this); + if (NetworkChannelClosed != null) + { + NetworkChannelClosed(this); + } } } @@ -761,11 +764,17 @@ private bool Process() m_ReceiveState.Reset(); if (packet == null) { - NetworkChannelCustomError?.Invoke(this, customErrorData); + if (NetworkChannelCustomError != null) + { + NetworkChannelCustomError(this, customErrorData); + } } else { - NetworkChannelReceived?.Invoke(this, packet); + if (NetworkChannelReceived != null) + { + NetworkChannelReceived(this, packet); + } } } catch (Exception exception) @@ -812,7 +821,10 @@ private void ConnectCallback(IAsyncResult ar) m_HeartBeatState.Reset(true); } - NetworkChannelConnected?.Invoke(this, socketUserData.UserData); + if (NetworkChannelConnected != null) + { + NetworkChannelConnected(this, socketUserData.UserData); + } Receive(); } @@ -841,7 +853,10 @@ private void SendCallback(IAsyncResult ar) throw; } - NetworkChannelSended?.Invoke(this, bytesSent, socketUserData.UserData); + if (NetworkChannelSended != null) + { + NetworkChannelSended(this, bytesSent, socketUserData.UserData); + } } private void ReceiveCallback(IAsyncResult ar) diff --git a/GameFramework/Resource/ResourceManager.ResourceLoader.InstantiateAssetTask.cs b/GameFramework/Resource/ResourceManager.ResourceLoader.InstantiateAssetTask.cs index ef00aebcc..5e0fb9fe9 100644 --- a/GameFramework/Resource/ResourceManager.ResourceLoader.InstantiateAssetTask.cs +++ b/GameFramework/Resource/ResourceManager.ResourceLoader.InstantiateAssetTask.cs @@ -40,13 +40,19 @@ public override bool IsScene public override void OnLoadSuccess(LoadResourceAgent agent, object asset, object instance, float duration) { base.OnLoadSuccess(agent, asset, instance, duration); - m_InstantiateAssetCallbacks.InstantiateAssetSuccessCallback?.Invoke(AssetName, instance, duration, UserData); + if (m_InstantiateAssetCallbacks.InstantiateAssetSuccessCallback != null) + { + m_InstantiateAssetCallbacks.InstantiateAssetSuccessCallback(AssetName, instance, duration, UserData); + } } public override void OnLoadFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage) { base.OnLoadFailure(agent, status, errorMessage); - m_InstantiateAssetCallbacks.InstantiateAssetFailureCallback?.Invoke(AssetName, status, errorMessage, UserData); + if (m_InstantiateAssetCallbacks.InstantiateAssetFailureCallback != null) + { + m_InstantiateAssetCallbacks.InstantiateAssetFailureCallback(AssetName, status, errorMessage, UserData); + } } public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress type, float progress) @@ -54,14 +60,20 @@ public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress base.OnLoadUpdate(agent, type, progress); if (type == LoadResourceProgress.LoadAsset) { - m_InstantiateAssetCallbacks.InstantiateAssetUpdateCallback?.Invoke(AssetName, progress, UserData); + if (m_InstantiateAssetCallbacks.InstantiateAssetUpdateCallback != null) + { + m_InstantiateAssetCallbacks.InstantiateAssetUpdateCallback(AssetName, progress, UserData); + } } } public override void OnLoadDependencyAsset(LoadResourceAgent agent, string dependencyAssetName, object dependencyAsset) { base.OnLoadDependencyAsset(agent, dependencyAssetName, dependencyAsset); - m_InstantiateAssetCallbacks.InstantiateAssetDependencyAssetCallback?.Invoke(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + if (m_InstantiateAssetCallbacks.InstantiateAssetDependencyAssetCallback != null) + { + m_InstantiateAssetCallbacks.InstantiateAssetDependencyAssetCallback(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + } } } } diff --git a/GameFramework/Resource/ResourceManager.ResourceLoader.LoadAssetTask.cs b/GameFramework/Resource/ResourceManager.ResourceLoader.LoadAssetTask.cs index af3c821e3..38b54803e 100644 --- a/GameFramework/Resource/ResourceManager.ResourceLoader.LoadAssetTask.cs +++ b/GameFramework/Resource/ResourceManager.ResourceLoader.LoadAssetTask.cs @@ -40,13 +40,19 @@ public override bool IsScene public override void OnLoadSuccess(LoadResourceAgent agent, object asset, object instance, float duration) { base.OnLoadSuccess(agent, asset, instance, duration); - m_LoadAssetCallbacks.LoadAssetSuccessCallback?.Invoke(AssetName, asset, duration, UserData); + if (m_LoadAssetCallbacks.LoadAssetSuccessCallback != null) + { + m_LoadAssetCallbacks.LoadAssetSuccessCallback(AssetName, asset, duration, UserData); + } } public override void OnLoadFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage) { base.OnLoadFailure(agent, status, errorMessage); - m_LoadAssetCallbacks.LoadAssetFailureCallback?.Invoke(AssetName, status, errorMessage, UserData); + if (m_LoadAssetCallbacks.LoadAssetFailureCallback != null) + { + m_LoadAssetCallbacks.LoadAssetFailureCallback(AssetName, status, errorMessage, UserData); + } } public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress type, float progress) @@ -54,14 +60,20 @@ public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress base.OnLoadUpdate(agent, type, progress); if (type == LoadResourceProgress.LoadAsset) { - m_LoadAssetCallbacks.LoadAssetUpdateCallback?.Invoke(AssetName, progress, UserData); + if (m_LoadAssetCallbacks.LoadAssetUpdateCallback != null) + { + m_LoadAssetCallbacks.LoadAssetUpdateCallback(AssetName, progress, UserData); + } } } public override void OnLoadDependencyAsset(LoadResourceAgent agent, string dependencyAssetName, object dependencyAsset) { base.OnLoadDependencyAsset(agent, dependencyAssetName, dependencyAsset); - m_LoadAssetCallbacks.LoadAssetDependencyAssetCallback?.Invoke(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + if (m_LoadAssetCallbacks.LoadAssetDependencyAssetCallback != null) + { + m_LoadAssetCallbacks.LoadAssetDependencyAssetCallback(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + } } } } diff --git a/GameFramework/Resource/ResourceManager.ResourceLoader.LoadSceneTask.cs b/GameFramework/Resource/ResourceManager.ResourceLoader.LoadSceneTask.cs index 5ac906b7b..51d45ae28 100644 --- a/GameFramework/Resource/ResourceManager.ResourceLoader.LoadSceneTask.cs +++ b/GameFramework/Resource/ResourceManager.ResourceLoader.LoadSceneTask.cs @@ -40,13 +40,19 @@ public override bool IsScene public override void OnLoadSuccess(LoadResourceAgent agent, object asset, object instance, float duration) { base.OnLoadSuccess(agent, asset, instance, duration); - m_LoadSceneCallbacks.LoadSceneSuccessCallback?.Invoke(AssetName, duration, UserData); + if (m_LoadSceneCallbacks.LoadSceneSuccessCallback != null) + { + m_LoadSceneCallbacks.LoadSceneSuccessCallback(AssetName, duration, UserData); + } } public override void OnLoadFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage) { base.OnLoadFailure(agent, status, errorMessage); - m_LoadSceneCallbacks.LoadSceneFailureCallback?.Invoke(AssetName, status, errorMessage, UserData); + if (m_LoadSceneCallbacks.LoadSceneFailureCallback != null) + { + m_LoadSceneCallbacks.LoadSceneFailureCallback(AssetName, status, errorMessage, UserData); + } } public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress type, float progress) @@ -54,14 +60,20 @@ public override void OnLoadUpdate(LoadResourceAgent agent, LoadResourceProgress base.OnLoadUpdate(agent, type, progress); if (type == LoadResourceProgress.LoadScene) { - m_LoadSceneCallbacks.LoadSceneUpdateCallback?.Invoke(AssetName, progress, UserData); + if (m_LoadSceneCallbacks.LoadSceneUpdateCallback != null) + { + m_LoadSceneCallbacks.LoadSceneUpdateCallback(AssetName, progress, UserData); + } } } public override void OnLoadDependencyAsset(LoadResourceAgent agent, string dependencyAssetName, object dependencyAsset) { base.OnLoadDependencyAsset(agent, dependencyAssetName, dependencyAsset); - m_LoadSceneCallbacks.LoadSceneDependencyAssetCallback?.Invoke(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + if (m_LoadSceneCallbacks.LoadSceneDependencyAssetCallback != null) + { + m_LoadSceneCallbacks.LoadSceneDependencyAssetCallback(AssetName, dependencyAssetName, LoadedDependencyAssetCount, TotalDependencyAssetCount, UserData); + } } } } diff --git a/GameFramework/Resource/ResourceManager.ResourceUpdater.cs b/GameFramework/Resource/ResourceManager.ResourceUpdater.cs index dbaab1f26..4594819ca 100644 --- a/GameFramework/Resource/ResourceManager.ResourceUpdater.cs +++ b/GameFramework/Resource/ResourceManager.ResourceUpdater.cs @@ -116,7 +116,10 @@ public void Update(float elapseSeconds, float realElapseSeconds) { m_UpdateComplete = true; Utility.Path.RemoveEmptyDirectory(m_ResourceManager.m_ReadWritePath); - ResourceUpdateAllComplete?.Invoke(); + if (ResourceUpdateAllComplete != null) + { + ResourceUpdateAllComplete(); + } } } } @@ -312,7 +315,10 @@ private void OnDownloadStart(object sender, DownloadStartEventArgs e) return; } - ResourceUpdateStart?.Invoke(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, e.CurrentLength, updateInfo.ZipLength, updateInfo.RetryCount); + if (ResourceUpdateStart != null) + { + ResourceUpdateStart(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, e.CurrentLength, updateInfo.ZipLength, updateInfo.RetryCount); + } } private void OnDownloadUpdate(object sender, DownloadUpdateEventArgs e) @@ -342,7 +348,10 @@ private void OnDownloadUpdate(object sender, DownloadUpdateEventArgs e) return; } - ResourceUpdateChanged?.Invoke(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, e.CurrentLength, updateInfo.ZipLength); + if (ResourceUpdateChanged != null) + { + ResourceUpdateChanged(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, e.CurrentLength, updateInfo.ZipLength); + } } private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e) @@ -425,7 +434,10 @@ private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e) GenerateReadWriteList(); - ResourceUpdateSuccess?.Invoke(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, updateInfo.Length, updateInfo.ZipLength); + if (ResourceUpdateSuccess != null) + { + ResourceUpdateSuccess(updateInfo.ResourceName, e.DownloadPath, e.DownloadUri, updateInfo.Length, updateInfo.ZipLength); + } } private void OnDownloadFailure(object sender, DownloadFailureEventArgs e) @@ -441,7 +453,10 @@ private void OnDownloadFailure(object sender, DownloadFailureEventArgs e) File.Delete(e.DownloadPath); } - ResourceUpdateFailure?.Invoke(updateInfo.ResourceName, e.DownloadUri, updateInfo.RetryCount, m_RetryCount, e.ErrorMessage); + if (ResourceUpdateFailure != null) + { + ResourceUpdateFailure(updateInfo.ResourceName, e.DownloadUri, updateInfo.RetryCount, m_RetryCount, e.ErrorMessage); + } if (updateInfo.RetryCount < m_RetryCount) { diff --git a/GameFramework/Resource/ResourceManager.VersionListProcessor.cs b/GameFramework/Resource/ResourceManager.VersionListProcessor.cs index 2377f48a0..f8dcb6db9 100644 --- a/GameFramework/Resource/ResourceManager.VersionListProcessor.cs +++ b/GameFramework/Resource/ResourceManager.VersionListProcessor.cs @@ -211,7 +211,10 @@ private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e) File.WriteAllBytes(e.DownloadPath, bytes); - VersionListUpdateSuccess?.Invoke(e.DownloadPath, e.DownloadUri); + if (VersionListUpdateSuccess != null) + { + VersionListUpdateSuccess(e.DownloadPath, e.DownloadUri); + } } private void OnDownloadFailure(object sender, DownloadFailureEventArgs e) @@ -227,7 +230,10 @@ private void OnDownloadFailure(object sender, DownloadFailureEventArgs e) File.Delete(e.DownloadPath); } - VersionListUpdateFailure?.Invoke(e.DownloadUri, e.ErrorMessage); + if (VersionListUpdateFailure != null) + { + VersionListUpdateFailure(e.DownloadUri, e.ErrorMessage); + } } } } diff --git a/GameFramework/Resource/ResourceManager.cs b/GameFramework/Resource/ResourceManager.cs index 1544bbd3c..de0f9ecce 100644 --- a/GameFramework/Resource/ResourceManager.cs +++ b/GameFramework/Resource/ResourceManager.cs @@ -1273,17 +1273,26 @@ private void OnIniterResourceInitComplete() m_ResourceIniter.Shutdown(); m_ResourceIniter = null; - m_ResourceInitCompleteEventHandler?.Invoke(this, new ResourceInitCompleteEventArgs()); + if (m_ResourceInitCompleteEventHandler != null) + { + m_ResourceInitCompleteEventHandler(this, new ResourceInitCompleteEventArgs()); + } } private void OnVersionListProcessorUpdateSuccess(string downloadPath, string downloadUri) { - m_VersionListUpdateSuccessEventHandler?.Invoke(this, new VersionListUpdateSuccessEventArgs(downloadPath, downloadUri)); + if (m_VersionListUpdateSuccessEventHandler != null) + { + m_VersionListUpdateSuccessEventHandler(this, new VersionListUpdateSuccessEventArgs(downloadPath, downloadUri)); + } } private void OnVersionListProcessorUpdateFailure(string downloadUri, string errorMessage) { - m_VersionListUpdateFailureEventHandler?.Invoke(this, new VersionListUpdateFailureEventArgs(downloadUri, errorMessage)); + if (m_VersionListUpdateFailureEventHandler != null) + { + m_VersionListUpdateFailureEventHandler(this, new VersionListUpdateFailureEventArgs(downloadUri, errorMessage)); + } } private void OnCheckerResourceNeedUpdate(ResourceName resourceName, LoadType loadType, int length, int hashCode, int zipLength, int zipHashCode) @@ -1316,27 +1325,42 @@ private void OnCheckerResourceCheckComplete(int removedCount, int updateCount, i m_ResourceUpdater = null; } - m_ResourceCheckCompleteEventHandler?.Invoke(this, new ResourceCheckCompleteEventArgs(removedCount, updateCount, updateTotalLength, updateTotalZipLength)); + if (m_ResourceCheckCompleteEventHandler != null) + { + m_ResourceCheckCompleteEventHandler(this, new ResourceCheckCompleteEventArgs(removedCount, updateCount, updateTotalLength, updateTotalZipLength)); + } } private void OnUpdaterResourceUpdateStart(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int zipLength, int retryCount) { - m_ResourceUpdateStartEventHandler?.Invoke(this, new ResourceUpdateStartEventArgs(resourceName.FullName, downloadPath, downloadUri, currentLength, zipLength, retryCount)); + if (m_ResourceUpdateStartEventHandler != null) + { + m_ResourceUpdateStartEventHandler(this, new ResourceUpdateStartEventArgs(resourceName.FullName, downloadPath, downloadUri, currentLength, zipLength, retryCount)); + } } private void OnUpdaterResourceUpdateChanged(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int zipLength) { - m_ResourceUpdateChangedEventHandler?.Invoke(this, new ResourceUpdateChangedEventArgs(resourceName.FullName, downloadPath, downloadUri, currentLength, zipLength)); + if (m_ResourceUpdateChangedEventHandler != null) + { + m_ResourceUpdateChangedEventHandler(this, new ResourceUpdateChangedEventArgs(resourceName.FullName, downloadPath, downloadUri, currentLength, zipLength)); + } } private void OnUpdaterResourceUpdateSuccess(ResourceName resourceName, string downloadPath, string downloadUri, int length, int zipLength) { - m_ResourceUpdateSuccessEventHandler?.Invoke(this, new ResourceUpdateSuccessEventArgs(resourceName.FullName, downloadPath, downloadUri, length, zipLength)); + if (m_ResourceUpdateSuccessEventHandler != null) + { + m_ResourceUpdateSuccessEventHandler(this, new ResourceUpdateSuccessEventArgs(resourceName.FullName, downloadPath, downloadUri, length, zipLength)); + } } private void OnUpdaterResourceUpdateFailure(ResourceName resourceName, string downloadUri, int retryCount, int totalRetryCount, string errorMessage) { - m_ResourceUpdateFailureEventHandler?.Invoke(this, new ResourceUpdateFailureEventArgs(resourceName.FullName, downloadUri, retryCount, totalRetryCount, errorMessage)); + if (m_ResourceUpdateFailureEventHandler != null) + { + m_ResourceUpdateFailureEventHandler(this, new ResourceUpdateFailureEventArgs(resourceName.FullName, downloadUri, retryCount, totalRetryCount, errorMessage)); + } } private void OnUpdaterResourceUpdateAllComplete() @@ -1349,7 +1373,10 @@ private void OnUpdaterResourceUpdateAllComplete() m_ResourceUpdater.Shutdown(); m_ResourceUpdater = null; - m_ResourceUpdateAllCompleteEventHandler?.Invoke(this, new ResourceUpdateAllCompleteEventArgs()); + if (m_ResourceUpdateAllCompleteEventHandler != null) + { + m_ResourceUpdateAllCompleteEventHandler(this, new ResourceUpdateAllCompleteEventArgs()); + } } } } diff --git a/GameFramework/Scene/SceneManager.cs b/GameFramework/Scene/SceneManager.cs index e1a20e062..bbfd2b4fb 100644 --- a/GameFramework/Scene/SceneManager.cs +++ b/GameFramework/Scene/SceneManager.cs @@ -338,7 +338,10 @@ private void LoadSceneSuccessCallback(string sceneAssetName, float duration, obj { m_LoadingSceneAssetNames.Remove(sceneAssetName); m_LoadedSceneAssetNames.Add(sceneAssetName); - m_LoadSceneSuccessEventHandler?.Invoke(this, new LoadSceneSuccessEventArgs(sceneAssetName, duration, userData)); + if (m_LoadSceneSuccessEventHandler != null) + { + m_LoadSceneSuccessEventHandler(this, new LoadSceneSuccessEventArgs(sceneAssetName, duration, userData)); + } } private void LoadSceneFailureCallback(string sceneAssetName, LoadResourceStatus status, string errorMessage, object userData) @@ -356,19 +359,28 @@ private void LoadSceneFailureCallback(string sceneAssetName, LoadResourceStatus private void LoadSceneUpdateCallback(string sceneAssetName, float progress, object userData) { - m_LoadSceneUpdateEventHandler?.Invoke(this, new LoadSceneUpdateEventArgs(sceneAssetName, progress, userData)); + if (m_LoadSceneUpdateEventHandler != null) + { + m_LoadSceneUpdateEventHandler(this, new LoadSceneUpdateEventArgs(sceneAssetName, progress, userData)); + } } private void LoadSceneDependencyAssetCallback(string sceneAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { - m_LoadSceneDependencyAssetEventHandler?.Invoke(this, new LoadSceneDependencyAssetEventArgs(sceneAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + if (m_LoadSceneDependencyAssetEventHandler != null) + { + m_LoadSceneDependencyAssetEventHandler(this, new LoadSceneDependencyAssetEventArgs(sceneAssetName, dependencyAssetName, loadedCount, totalCount, userData)); + } } private void UnloadSceneSuccessCallback(string sceneAssetName, object userData) { m_UnloadingSceneAssetNames.Remove(sceneAssetName); m_LoadedSceneAssetNames.Remove(sceneAssetName); - m_UnloadSceneSuccessEventHandler?.Invoke(this, new UnloadSceneSuccessEventArgs(sceneAssetName, userData)); + if (m_UnloadSceneSuccessEventHandler != null) + { + m_UnloadSceneSuccessEventHandler(this, new UnloadSceneSuccessEventArgs(sceneAssetName, userData)); + } } private void UnloadSceneFailureCallback(string sceneAssetName, object userData) diff --git a/GameFramework/Sound/SoundManager.cs b/GameFramework/Sound/SoundManager.cs index 4a15fd53b..3bae67c1c 100644 --- a/GameFramework/Sound/SoundManager.cs +++ b/GameFramework/Sound/SoundManager.cs @@ -425,7 +425,10 @@ private void LoadSoundSuccessCallback(string soundAssetName, object soundAsset, ISoundAgent soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode); if (soundAgent != null) { - m_PlaySoundSuccessEventHandler?.Invoke(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData)); + if (m_PlaySoundSuccessEventHandler != null) + { + m_PlaySoundSuccessEventHandler(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData)); + } } else { @@ -467,7 +470,10 @@ private void LoadSoundUpdateCallback(string soundAssetName, float progress, obje throw new GameFrameworkException("Play sound info is invalid."); } - m_PlaySoundUpdateEventHandler?.Invoke(this, new PlaySoundUpdateEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, progress, playSoundInfo.UserData)); + if (m_PlaySoundUpdateEventHandler != null) + { + m_PlaySoundUpdateEventHandler(this, new PlaySoundUpdateEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, progress, playSoundInfo.UserData)); + } } private void LoadSoundDependencyAssetCallback(string soundAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) @@ -478,7 +484,10 @@ private void LoadSoundDependencyAssetCallback(string soundAssetName, string depe throw new GameFrameworkException("Play sound info is invalid."); } - m_PlaySoundDependencyAssetEventHandler?.Invoke(this, new PlaySoundDependencyAssetEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, dependencyAssetName, loadedCount, totalCount, playSoundInfo.UserData)); + if (m_PlaySoundDependencyAssetEventHandler != null) + { + m_PlaySoundDependencyAssetEventHandler(this, new PlaySoundDependencyAssetEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, dependencyAssetName, loadedCount, totalCount, playSoundInfo.UserData)); + } } } } diff --git a/GameFramework/UI/UIManager.cs b/GameFramework/UI/UIManager.cs index 21df7641f..76ac4d50c 100644 --- a/GameFramework/UI/UIManager.cs +++ b/GameFramework/UI/UIManager.cs @@ -520,7 +520,10 @@ public void CloseUIForm(IUIForm uiForm, object userData) uiForm.OnClose(userData); uiGroup.Refresh(); - m_CloseUIFormCompleteEventHandler?.Invoke(this, new CloseUIFormCompleteEventArgs(uiForm.TypeId, userData)); + if (m_CloseUIFormCompleteEventHandler != null) + { + m_CloseUIFormCompleteEventHandler(this, new CloseUIFormCompleteEventArgs(uiForm.TypeId, userData)); + } m_RecycleQueue.AddLast(new RecycleNode(uiForm)); } @@ -601,7 +604,11 @@ private void InternalOpenUIForm(int uiFormTypeId, string uiFormAssetName, UIGrou uiGroup.AddUIForm(uiForm); uiForm.OnOpen(userData); uiGroup.Refresh(); - m_OpenUIFormSuccessEventHandler?.Invoke(this, new OpenUIFormSuccessEventArgs(uiFormAssetName, uiForm, duration, userData)); + + if (m_OpenUIFormSuccessEventHandler != null) + { + m_OpenUIFormSuccessEventHandler(this, new OpenUIFormSuccessEventArgs(uiFormAssetName, uiForm, duration, userData)); + } } catch (Exception exception) { @@ -655,7 +662,10 @@ private void InstantiateUIFormUpdateCallback(string uiFormAssetName, float progr throw new GameFrameworkException("Open UI form info is invalid."); } - m_OpenUIFormUpdateEventHandler?.Invoke(this, new OpenUIFormUpdateEventArgs(openUIFormInfo.UIFormTypeId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, progress, openUIFormInfo.UserData)); + if (m_OpenUIFormUpdateEventHandler != null) + { + m_OpenUIFormUpdateEventHandler(this, new OpenUIFormUpdateEventArgs(openUIFormInfo.UIFormTypeId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, progress, openUIFormInfo.UserData)); + } } private void InstantiateUIFormDependencyAssetCallback(string uiFormAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) @@ -666,7 +676,10 @@ private void InstantiateUIFormDependencyAssetCallback(string uiFormAssetName, st throw new GameFrameworkException("Open UI form info is invalid."); } - m_OpenUIFormDependencyAssetEventHandler?.Invoke(this, new OpenUIFormDependencyAssetEventArgs(openUIFormInfo.UIFormTypeId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, dependencyAssetName, loadedCount, totalCount, openUIFormInfo.UserData)); + if (m_OpenUIFormDependencyAssetEventHandler != null) + { + m_OpenUIFormDependencyAssetEventHandler(this, new OpenUIFormDependencyAssetEventArgs(openUIFormInfo.UIFormTypeId, uiFormAssetName, openUIFormInfo.UIGroup.Name, openUIFormInfo.PauseCoveredUIForm, dependencyAssetName, loadedCount, totalCount, openUIFormInfo.UserData)); + } } } } diff --git a/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs b/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs index 34d41394b..6e2594edd 100644 --- a/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs +++ b/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs @@ -112,9 +112,12 @@ public void Start(WebRequestTask task) } m_Task = task; - m_Task.Status = WebRequestTaskStatus.Doing; - WebRequestAgentStart?.Invoke(this); + + if (WebRequestAgentStart != null) + { + WebRequestAgentStart(this); + } if (m_Task.PostData == null) { @@ -141,10 +144,12 @@ public void Reset() private void OnWebRequestAgentHelperComplete(object sender, WebRequestAgentHelperCompleteEventArgs e) { m_Helper.Reset(); - m_Task.Status = WebRequestTaskStatus.Done; - WebRequestAgentSuccess?.Invoke(this, e.GetWebResponseBytes()); + if (WebRequestAgentSuccess != null) + { + WebRequestAgentSuccess(this, e.GetWebResponseBytes()); + } m_Task.Done = true; } @@ -152,10 +157,12 @@ private void OnWebRequestAgentHelperComplete(object sender, WebRequestAgentHelpe private void OnWebRequestAgentHelperError(object sender, WebRequestAgentHelperErrorEventArgs e) { m_Helper.Reset(); - m_Task.Status = WebRequestTaskStatus.Error; - WebRequestAgentFailure?.Invoke(this, e.ErrorMessage); + if (WebRequestAgentFailure != null) + { + WebRequestAgentFailure(this, e.ErrorMessage); + } m_Task.Done = true; } diff --git a/GameFramework/WebRequest/WebRequestManager.cs b/GameFramework/WebRequest/WebRequestManager.cs index 580bc1eeb..7edb0b643 100644 --- a/GameFramework/WebRequest/WebRequestManager.cs +++ b/GameFramework/WebRequest/WebRequestManager.cs @@ -242,17 +242,26 @@ public void RemoveAllWebRequests() private void OnWebRequestAgentStart(WebRequestAgent sender) { - m_WebRequestStartEventHandler?.Invoke(this, new WebRequestStartEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, sender.Task.UserData)); + if (m_WebRequestStartEventHandler != null) + { + m_WebRequestStartEventHandler(this, new WebRequestStartEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, sender.Task.UserData)); + } } private void OnWebRequestAgentSuccess(WebRequestAgent sender, byte[] webResponseBytes) { - m_WebRequestSuccessEventHandler?.Invoke(this, new WebRequestSuccessEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, webResponseBytes, sender.Task.UserData)); + if (m_WebRequestSuccessEventHandler != null) + { + m_WebRequestSuccessEventHandler(this, new WebRequestSuccessEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, webResponseBytes, sender.Task.UserData)); + } } private void OnWebRequestAgentFailure(WebRequestAgent sender, string errorMessage) { - m_WebRequestFailureEventHandler?.Invoke(this, new WebRequestFailureEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, errorMessage, sender.Task.UserData)); + if (m_WebRequestFailureEventHandler != null) + { + m_WebRequestFailureEventHandler(this, new WebRequestFailureEventArgs(sender.Task.SerialId, sender.Task.WebRequestUri, errorMessage, sender.Task.UserData)); + } } } } diff --git a/README.md b/README.md index 19ef7662e..600d6eeb9 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ --- +![Game Framework](http://gameframework.cn/wp-content/uploads/2016/04/Game-Framework.png) + +--- + ## INTRODUCTION Game Framework is literally a game framework, based on Unity 5.3+ game engine. It encapsulates commonly used game modules during development, and, to a large degree, standardises the process, enhances the development speed and ensures the product quality. diff --git a/UnityGameFramework.Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.cs b/UnityGameFramework.Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.cs index 43ad54783..2dab1b4b6 100644 --- a/UnityGameFramework.Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.cs +++ b/UnityGameFramework.Editor/AssetBundleAnalyzer/AssetBundleAnalyzerController.cs @@ -30,9 +30,30 @@ public AssetBundleAnalyzerController() public AssetBundleAnalyzerController(AssetBundleCollection assetBundleCollection) { m_AssetBundleCollection = (assetBundleCollection != null ? assetBundleCollection : new AssetBundleCollection()); - m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) { OnLoadingAssetBundle?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) { OnLoadingAsset?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadCompleted += delegate () { OnLoadCompleted?.Invoke(); }; + + m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) + { + if (OnLoadingAssetBundle != null) + { + OnLoadingAssetBundle(index, count); + } + }; + + m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) + { + if (OnLoadingAsset != null) + { + OnLoadingAsset(index, count); + } + }; + + m_AssetBundleCollection.OnLoadCompleted += delegate () + { + if (OnLoadCompleted != null) + { + OnLoadCompleted(); + } + }; m_DependencyDatas = new Dictionary(); m_ScatteredAssets = new Dictionary>(); @@ -74,7 +95,11 @@ public void Analyze() int count = assets.Length; for (int i = 0; i < count; i++) { - OnAnalyzingAsset?.Invoke(i, count); + if (OnAnalyzingAsset != null) + { + OnAnalyzingAsset(i, count); + } + string assetName = assets[i].Name; if (string.IsNullOrEmpty(assetName)) { @@ -93,7 +118,10 @@ public void Analyze() scatteredAsset.Sort((a, b) => a.Name.CompareTo(b.Name)); } - OnAnalyzeCompleted?.Invoke(); + if (OnAnalyzeCompleted != null) + { + OnAnalyzeCompleted(); + } } private void AnalyzeAsset(string assetName, Asset hostAsset, DependencyData dependencyData, HashSet scriptAssetNames) diff --git a/UnityGameFramework.Editor/AssetBundleBuilder/AssetBundleBuilderController.cs b/UnityGameFramework.Editor/AssetBundleBuilder/AssetBundleBuilderController.cs index 7564672d6..ae4e9e362 100644 --- a/UnityGameFramework.Editor/AssetBundleBuilder/AssetBundleBuilderController.cs +++ b/UnityGameFramework.Editor/AssetBundleBuilder/AssetBundleBuilderController.cs @@ -40,13 +40,48 @@ internal sealed partial class AssetBundleBuilderController : Utility.Zip.IZipHel public AssetBundleBuilderController() { m_AssetBundleCollection = new AssetBundleCollection(); - m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) { OnLoadingAssetBundle?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) { OnLoadingAsset?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadCompleted += delegate () { OnLoadCompleted?.Invoke(); }; + + m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) + { + if (OnLoadingAssetBundle != null) + { + OnLoadingAssetBundle(index, count); + } + }; + + m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) + { + if (OnLoadingAsset != null) + { + OnLoadingAsset(index, count); + } + }; + + m_AssetBundleCollection.OnLoadCompleted += delegate () + { + if (OnLoadCompleted != null) + { + OnLoadCompleted(); + } + }; m_AssetBundleAnalyzerController = new AssetBundleAnalyzerController(m_AssetBundleCollection); - m_AssetBundleAnalyzerController.OnAnalyzingAsset += delegate (int index, int count) { OnAnalyzingAsset?.Invoke(index, count); }; - m_AssetBundleAnalyzerController.OnAnalyzeCompleted += delegate () { OnAnalyzeCompleted?.Invoke(); }; + + m_AssetBundleAnalyzerController.OnAnalyzingAsset += delegate (int index, int count) + { + if (OnAnalyzingAsset != null) + { + OnAnalyzingAsset(index, count); + } + }; + + m_AssetBundleAnalyzerController.OnAnalyzeCompleted += delegate () + { + if (OnAnalyzeCompleted != null) + { + OnAnalyzeCompleted(); + } + }; m_AssetBundleDatas = new SortedDictionary(); m_VersionListDatas = new Dictionary(); @@ -616,7 +651,11 @@ public bool BuildAssetBundles() { m_BuildReport.LogError(exception.Message); m_BuildReport.SaveReport(); - BuildAssetBundlesError?.Invoke(exception.Message); + if (BuildAssetBundlesError != null) + { + BuildAssetBundlesError(exception.Message); + } + return false; } } @@ -727,7 +766,10 @@ private void BuildAssetBundles(AssetBundleBuild[] buildMap, BuildAssetBundleOpti m_VersionListDatas.Add(buildTarget, versionListData); - ProcessAssetBundleComplete?.Invoke(buildTarget, versionListData.Path, versionListData.Length, versionListData.HashCode, versionListData.ZipLength, versionListData.ZipHashCode); + if (ProcessAssetBundleComplete != null) + { + ProcessAssetBundleComplete(buildTarget, versionListData.Path, versionListData.Length, versionListData.HashCode, versionListData.ZipLength, versionListData.ZipHashCode); + } m_BuildReport.LogInfo("Build AssetBundles for '{0}' success.", buildTarget.ToString()); } diff --git a/UnityGameFramework.Editor/AssetBundleCollection/AssetBundleCollection.cs b/UnityGameFramework.Editor/AssetBundleCollection/AssetBundleCollection.cs index cacdeb093..6e86907a5 100644 --- a/UnityGameFramework.Editor/AssetBundleCollection/AssetBundleCollection.cs +++ b/UnityGameFramework.Editor/AssetBundleCollection/AssetBundleCollection.cs @@ -90,7 +90,11 @@ public bool Load() count = xmlNodeList.Count; for (int i = 0; i < count; i++) { - OnLoadingAssetBundle?.Invoke(i, count); + if (OnLoadingAssetBundle != null) + { + OnLoadingAssetBundle(i, count); + } + xmlNode = xmlNodeList.Item(i); if (xmlNode.Name != "AssetBundle") { @@ -122,7 +126,11 @@ public bool Load() count = xmlNodeList.Count; for (int i = 0; i < count; i++) { - OnLoadingAsset?.Invoke(i, count); + if (OnLoadingAsset != null) + { + OnLoadingAsset(i, count); + } + xmlNode = xmlNodeList.Item(i); if (xmlNode.Name != "Asset") { @@ -140,13 +148,21 @@ public bool Load() } } - OnLoadCompleted?.Invoke(); + if (OnLoadCompleted != null) + { + OnLoadCompleted(); + } + return true; } catch { File.Delete(configurationName); - OnLoadCompleted?.Invoke(); + if (OnLoadCompleted != null) + { + OnLoadCompleted(); + } + return false; } } diff --git a/UnityGameFramework.Editor/AssetBundleEditor/AssetBundleEditorController.cs b/UnityGameFramework.Editor/AssetBundleEditor/AssetBundleEditorController.cs index bd4ec68cb..7de6a55f2 100644 --- a/UnityGameFramework.Editor/AssetBundleEditor/AssetBundleEditorController.cs +++ b/UnityGameFramework.Editor/AssetBundleEditor/AssetBundleEditorController.cs @@ -34,9 +34,30 @@ internal sealed partial class AssetBundleEditorController public AssetBundleEditorController() { m_AssetBundleCollection = new AssetBundleCollection(); - m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) { OnLoadingAssetBundle?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) { OnLoadingAsset?.Invoke(index, count); }; - m_AssetBundleCollection.OnLoadCompleted += delegate () { OnLoadCompleted?.Invoke(); }; + + m_AssetBundleCollection.OnLoadingAssetBundle += delegate (int index, int count) + { + if (OnLoadingAssetBundle != null) + { + OnLoadingAssetBundle(index, count); + } + }; + + m_AssetBundleCollection.OnLoadingAsset += delegate (int index, int count) + { + if (OnLoadingAsset != null) + { + OnLoadingAsset(index, count); + } + }; + + m_AssetBundleCollection.OnLoadCompleted += delegate () + { + if (OnLoadCompleted != null) + { + OnLoadCompleted(); + } + }; m_SourceAssetSearchPaths = new List(); m_SourceAssetSearchRelativePaths = new List(); @@ -369,7 +390,11 @@ public bool RemoveAssetBundle(string assetBundleName, string assetBundleVariant) } } - OnAssetUnassigned?.Invoke(unassignedSourceAssets.ToArray()); + if (OnAssetUnassigned != null) + { + OnAssetUnassigned(unassignedSourceAssets.ToArray()); + } + return true; } @@ -426,7 +451,11 @@ public bool AssignAsset(string assetGuid, string assetBundleName, string assetBu { if (m_AssetBundleCollection.AssignAsset(assetGuid, assetBundleName, assetBundleVariant)) { - OnAssetAssigned?.Invoke(new SourceAsset[] { GetSourceAsset(assetGuid) }); + if (OnAssetAssigned != null) + { + OnAssetAssigned(new SourceAsset[] { GetSourceAsset(assetGuid) }); + } + return true; } @@ -440,7 +469,10 @@ public bool UnassignAsset(string assetGuid) SourceAsset sourceAsset = GetSourceAsset(assetGuid); if (sourceAsset != null) { - OnAssetUnassigned?.Invoke(new SourceAsset[] { sourceAsset }); + if (OnAssetUnassigned != null) + { + OnAssetUnassigned(new SourceAsset[] { sourceAsset }); + } } return true; diff --git a/UnityGameFramework/Assets/GameFramework/Libraries/Editor/UnityGameFramework.Editor.dll b/UnityGameFramework/Assets/GameFramework/Libraries/Editor/UnityGameFramework.Editor.dll index 8bbc2987b..c0b035375 100644 Binary files a/UnityGameFramework/Assets/GameFramework/Libraries/Editor/UnityGameFramework.Editor.dll and b/UnityGameFramework/Assets/GameFramework/Libraries/Editor/UnityGameFramework.Editor.dll differ diff --git a/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.dll b/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.dll index d2ac52006..cc5bee092 100644 Binary files a/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.dll and b/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.dll differ diff --git a/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.xml b/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.xml index b5eaddffb..0801447ca 100644 --- a/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.xml +++ b/UnityGameFramework/Assets/GameFramework/Libraries/GameFramework.xml @@ -478,11 +478,6 @@ 游戏框架入口。 - - - 初始化游戏框架入口的新实例。 - - 获取游戏框架版本号。