guodong 1 жил өмнө
parent
commit
a1a154851d
25 өөрчлөгдсөн 506 нэмэгдсэн , 52 устгасан
  1. 0 11
      GameClient/Assets/Game/HotUpdate/Platform/QDManager.cs
  2. 4 33
      GameClient/Assets/Game/HotUpdate/Views/Login/LoginView.cs
  3. 8 0
      GameClient/Assets/Game/Launcher/Event.meta
  4. 9 0
      GameClient/Assets/Game/Launcher/Event/LauncherEvent.cs
  5. 11 0
      GameClient/Assets/Game/Launcher/Event/LauncherEvent.cs.meta
  6. 2 1
      GameClient/Assets/Game/Launcher/Game.Launcher.asmdef
  7. 40 7
      GameClient/Assets/Game/Launcher/LauncherController.cs
  8. 22 0
      GameClient/Assets/Game/Launcher/Platform/QDManagerInit.cs
  9. 11 0
      GameClient/Assets/Game/Launcher/Platform/QDManagerInit.cs.meta
  10. 8 0
      GameClient/Assets/UniFramework/UniEvent.meta
  11. 4 0
      GameClient/Assets/UniFramework/UniEvent/README.md
  12. 7 0
      GameClient/Assets/UniFramework/UniEvent/README.md.meta
  13. 8 0
      GameClient/Assets/UniFramework/UniEvent/Runtime.meta
  14. 48 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/EventGroup.cs
  15. 11 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/EventGroup.cs.meta
  16. 7 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/IEventMessage.cs
  17. 11 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/IEventMessage.cs.meta
  18. 206 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniEvent.cs
  19. 11 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniEvent.cs.meta
  20. 12 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniEventDriver.cs
  21. 11 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniEventDriver.cs.meta
  22. 16 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniFramework.Event.asmdef
  23. 7 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniFramework.Event.asmdef.meta
  24. 21 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniLogger.cs
  25. 11 0
      GameClient/Assets/UniFramework/UniEvent/Runtime/UniLogger.cs.meta

+ 0 - 11
GameClient/Assets/Game/HotUpdate/Platform/QDManager.cs

@@ -5,17 +5,6 @@
     {
         public static bool isInited = false;
 
-        public static void InitPlatform()
-        {
-            ViewManager.Show<ModalStatusView>("正在初始化...");
-            switch (LauncherConfig.ChannelId)
-            {
-                default:
-                    EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
-                    break;
-            }
-        }
-
         public static void Login()
         {
             ViewManager.Show<ModalStatusView>("登录中...");

+ 4 - 33
GameClient/Assets/Game/HotUpdate/Views/Login/LoginView.cs

@@ -59,7 +59,6 @@ namespace GFGGame
             base.AddEventListener();
             EventAgent.AddEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
             EventAgent.AddEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
-            EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
             EventAgent.AddEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
         }
         protected override void OnShown()
@@ -90,16 +89,10 @@ namespace GFGGame
                 return;
             }
 
-            if (QDManager.isInited)
-            {
-                EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
-            }
-            else
-            {
-                //初始化平台配置
-                QDManager.InitPlatform();
-            }
-
+            _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
+            _ui.m_btnStart.visible = !QDManager.IsTaptap;
+            //尝试自动登录
+            TryLogin();
         }
 
         protected override void OnHide()
@@ -117,7 +110,6 @@ namespace GFGGame
             base.RemoveEventListener();
             EventAgent.RemoveEventListener(ConstMessage.SERVER_CHANGE, OnSeverChangeListener);
             EventAgent.RemoveEventListener(ConstMessage.LOGIN_SUCCESS, OnLoginSuccess);
-            EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_INITED, OnPlatformInitet);
             EventAgent.RemoveEventListener(ConstMessage.ON_PLATFORM_SDK_LOGINED, OnPlatformLogined);
         }
 
@@ -135,27 +127,6 @@ namespace GFGGame
             LogServerHelperHttp.SendNodeLog((int)LogNode.ShowSelectServer);
         }
 
-        private void OnPlatformInitet(EventContext context)
-        {
-            ViewManager.Hide<ModalStatusView>();
-            var success = (bool)context.data;
-            Debug.Log($"InitPlatform success {success}");
-            if (success)
-            {
-                QDManager.isInited = true;
-                _ui.m_btnTapLogin.visible = QDManager.IsTaptap;
-                _ui.m_btnStart.visible = !QDManager.IsTaptap;
-                //尝试自动登录
-                TryLogin();
-            }
-            else
-            {
-                AlertSystem.Show("初始化平台sdk失败!")
-                .SetRightButton(true, "重试", (t) => { QDManager.InitPlatform(); });
-            }
-
-        }
-
         private void OnPlatformLogined(EventContext context)
         {
             var account = (string)context.data;

+ 8 - 0
GameClient/Assets/Game/Launcher/Event.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 18bcdfa4a5637d7479927ec159a93d34
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
GameClient/Assets/Game/Launcher/Event/LauncherEvent.cs

@@ -0,0 +1,9 @@
+using UniFramework.Event;
+
+namespace GFGGame.LauncherEvent
+{
+    public class InitPlatformResult : IEventMessage
+    {
+        public bool success;
+    }
+}

+ 11 - 0
GameClient/Assets/Game/Launcher/Event/LauncherEvent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: de135b03ea247e045889c62b1641a579
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 1
GameClient/Assets/Game/Launcher/Game.Launcher.asmdef

@@ -5,7 +5,8 @@
         "GUID:7a41fac89c3ce014e99efb3723e6a98e",
         "GUID:13ba8ce62aa80c74598530029cb2d649",
         "GUID:e34a5702dd353724aa315fb8011f08c3",
-        "GUID:b0a84d582f6a6fa4185f67ce934d99c2"
+        "GUID:b0a84d582f6a6fa4185f67ce934d99c2",
+        "GUID:f22fac247a56d2d41b687bb0d900e54e"
     ],
     "includePlatforms": [],
     "excludePlatforms": [],

+ 40 - 7
GameClient/Assets/Game/Launcher/LauncherController.cs

@@ -1,12 +1,13 @@
 using System;
 using GFGGame.Launcher;
 using UnityEngine;
+using UniFramework.Event;
 
 namespace GFGGame
 {
     public class LauncherController
     {
-
+        private static EventGroup eventGroup = new EventGroup();
         /// <summary>
         /// 初始化启动器配置
         /// </summary>
@@ -38,9 +39,6 @@ namespace GFGGame
 
         public static void CheckGameStatus()
         {
-            InitReporter();
-            InitBugly();
-
             if (LauncherConfig.serverStatus == 1)
             {
                 if(string.IsNullOrEmpty(LauncherConfig.statusPrompt))
@@ -56,12 +54,47 @@ namespace GFGGame
             }
             else
             {
+                InitSDK();
+            }
+        }
+
+        private static void InitSDK()
+        {
+            InitReporter();
+            InitBugly();
+            eventGroup.AddListener<LauncherEvent.InitPlatformResult>(OnInitPlatform);
+            QDManagerInit.InitPlatform();
+        }
+
+        private static void OnInitPlatform(IEventMessage obj)
+        {
+            LauncherEvent.InitPlatformResult initPlatformResult = obj as LauncherEvent.InitPlatformResult;
+            if (initPlatformResult != null)
+            {
+                if(initPlatformResult.success)
+                {
+                    OnInitSDKSuccess();
+                }
+                else
+                {
+                    OnInitSDKFail();
+                }
+            }
+        }
+
+        private static void OnInitSDKFail()
+        {
+            Alert.Show("初始化平台sdk失败!")
+                .SetRightButton(true, "重试", (t) => { QDManagerInit.InitPlatform(); });
+        }
+
+        private static void OnInitSDKSuccess()
+        {
 #if UNITY_EDITOR
-                InitResVersion();
+            InitResVersion();
 #else
-                CheckApkVersion();
+            CheckApkVersion();
 #endif
-            }
         }
 
         private static void CheckApkVersion()

+ 22 - 0
GameClient/Assets/Game/Launcher/Platform/QDManagerInit.cs

@@ -0,0 +1,22 @@
+using UnityEngine;
+using UniFramework.Event;
+
+
+namespace GFGGame.Launcher
+{
+    public class QDManagerInit : MonoBehaviour
+    {
+
+        public static void InitPlatform()
+        {
+            switch (LauncherConfig.ChannelId)
+            {
+                default:
+                    UniEvent.SendMessage(new LauncherEvent.InitPlatformResult() { success = true});
+                    break;
+            }
+        }
+
+    }
+}
+

+ 11 - 0
GameClient/Assets/Game/Launcher/Platform/QDManagerInit.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 44d474cedeece3f4d84f3277cf609ac5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
GameClient/Assets/UniFramework/UniEvent.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 8c5a15c7124154d4d8e57cc8ee0fccc4
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 0
GameClient/Assets/UniFramework/UniEvent/README.md

@@ -0,0 +1,4 @@
+# UniFramework.Event
+
+一个轻量级的事件系统。
+

+ 7 - 0
GameClient/Assets/UniFramework/UniEvent/README.md.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 5dfad42c0d1a02f429a99108a35bbfce
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e86e06e6a95e6cc43940623bcc15721c
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 48 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/EventGroup.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace UniFramework.Event
+{
+	public class EventGroup
+	{
+		private readonly Dictionary<System.Type, List<Action<IEventMessage>>> _cachedListener = new Dictionary<System.Type, List<Action<IEventMessage>>>();
+
+		/// <summary>
+		/// 添加一个监听
+		/// </summary>
+		public void AddListener<TEvent>(System.Action<IEventMessage> listener) where TEvent : IEventMessage
+		{
+			System.Type eventType = typeof(TEvent);
+			if (_cachedListener.ContainsKey(eventType) == false)
+				_cachedListener.Add(eventType, new List<Action<IEventMessage>>());
+
+			if (_cachedListener[eventType].Contains(listener) == false)
+			{
+				_cachedListener[eventType].Add(listener);
+				UniEvent.AddListener(eventType, listener);
+			}
+			else
+			{
+				UniLogger.Warning($"Event listener is exist : {eventType}");
+			}
+		}
+
+		/// <summary>
+		/// 移除所有缓存的监听
+		/// </summary>
+		public void RemoveAllListener()
+		{
+			foreach (var pair in _cachedListener)
+			{
+				System.Type eventType = pair.Key;
+				for (int i = 0; i < pair.Value.Count; i++)
+				{
+					UniEvent.RemoveListener(eventType, pair.Value[i]);
+				}
+				pair.Value.Clear();
+			}
+			_cachedListener.Clear();
+		}
+	}
+}

+ 11 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/EventGroup.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: dcc5e4008d087434eb5db1390d8e4e6a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/IEventMessage.cs

@@ -0,0 +1,7 @@
+
+namespace UniFramework.Event
+{
+	public interface IEventMessage
+	{
+	}
+}

+ 11 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/IEventMessage.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7dcd12aabf986c6468f748911b1af65a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 206 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniEvent.cs

@@ -0,0 +1,206 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace UniFramework.Event
+{
+	public static class UniEvent
+	{
+		private class PostWrapper
+		{
+			public int PostFrame;
+			public int EventID;
+			public IEventMessage Message;
+
+			public void OnRelease()
+			{
+				PostFrame = 0;
+				EventID = 0;
+				Message = null;
+			}
+		}
+
+		private static bool _isInitialize = false;
+		private static GameObject _driver = null;
+		private static readonly Dictionary<int, LinkedList<Action<IEventMessage>>> _listeners = new Dictionary<int, LinkedList<Action<IEventMessage>>>(1000);
+		private static readonly List<PostWrapper> _postingList = new List<PostWrapper>(1000);
+
+		/// <summary>
+		/// 初始化事件系统
+		/// </summary>
+		public static void Initalize()
+		{
+			if (_isInitialize)
+				throw new Exception($"{nameof(UniEvent)} is initialized !");
+
+			if (_isInitialize == false)
+			{
+				// 创建驱动器
+				_isInitialize = true;
+				_driver = new UnityEngine.GameObject($"[{nameof(UniEvent)}]");
+				_driver.AddComponent<UniEventDriver>();
+				UnityEngine.Object.DontDestroyOnLoad(_driver);
+				UniLogger.Log($"{nameof(UniEvent)} initalize !");
+			}
+		}
+
+		/// <summary>
+		/// 销毁事件系统
+		/// </summary>
+		public static void Destroy()
+		{
+			if (_isInitialize)
+			{
+				ClearAll();
+
+				_isInitialize = false;
+				if (_driver != null)
+					GameObject.Destroy(_driver);
+				UniLogger.Log($"{nameof(UniEvent)} destroy all !");
+			}
+		}
+
+		/// <summary>
+		/// 更新事件系统
+		/// </summary>
+		internal static void Update()
+		{
+			for (int i = _postingList.Count - 1; i >= 0; i--)
+			{
+				var wrapper = _postingList[i];
+				if (UnityEngine.Time.frameCount > wrapper.PostFrame)
+				{
+					SendMessage(wrapper.EventID, wrapper.Message);
+					_postingList.RemoveAt(i);
+				}
+			}
+		}
+
+		/// <summary>
+		/// 清空所有监听
+		/// </summary>
+		public static void ClearAll()
+		{
+			foreach (int eventId in _listeners.Keys)
+			{
+				_listeners[eventId].Clear();
+			}
+			_listeners.Clear();
+			_postingList.Clear();
+		}
+
+		/// <summary>
+		/// 添加监听
+		/// </summary>
+		public static void AddListener<TEvent>(System.Action<IEventMessage> listener) where TEvent : IEventMessage
+		{
+			System.Type eventType = typeof(TEvent);
+			int eventId = eventType.GetHashCode();
+			AddListener(eventId, listener);
+		}
+
+		/// <summary>
+		/// 添加监听
+		/// </summary>
+		public static void AddListener(System.Type eventType, System.Action<IEventMessage> listener)
+		{
+			int eventId = eventType.GetHashCode();
+			AddListener(eventId, listener);
+		}
+
+		/// <summary>
+		/// 添加监听
+		/// </summary>
+		public static void AddListener(int eventId, System.Action<IEventMessage> listener)
+		{
+			if (_listeners.ContainsKey(eventId) == false)
+				_listeners.Add(eventId, new LinkedList<Action<IEventMessage>>());
+			if (_listeners[eventId].Contains(listener) == false)
+				_listeners[eventId].AddLast(listener);
+		}
+
+
+		/// <summary>
+		/// 移除监听
+		/// </summary>
+		public static void RemoveListener<TEvent>(System.Action<IEventMessage> listener) where TEvent : IEventMessage
+		{
+			System.Type eventType = typeof(TEvent);
+			int eventId = eventType.GetHashCode();
+			RemoveListener(eventId, listener);
+		}
+
+		/// <summary>
+		/// 移除监听
+		/// </summary>
+		public static void RemoveListener(System.Type eventType, System.Action<IEventMessage> listener)
+		{
+			int eventId = eventType.GetHashCode();
+			RemoveListener(eventId, listener);
+		}
+
+		/// <summary>
+		/// 移除监听
+		/// </summary>
+		public static void RemoveListener(int eventId, System.Action<IEventMessage> listener)
+		{
+			if (_listeners.ContainsKey(eventId))
+			{
+				if (_listeners[eventId].Contains(listener))
+					_listeners[eventId].Remove(listener);
+			}
+		}
+
+
+		/// <summary>
+		/// 实时广播事件
+		/// </summary>
+		public static void SendMessage(IEventMessage message)
+		{
+			int eventId = message.GetType().GetHashCode();
+			SendMessage(eventId, message);
+		}
+
+		/// <summary>
+		/// 实时广播事件
+		/// </summary>
+		public static void SendMessage(int eventId, IEventMessage message)
+		{
+			if (_listeners.ContainsKey(eventId) == false)
+				return;
+
+			LinkedList<Action<IEventMessage>> listeners = _listeners[eventId];
+			if (listeners.Count > 0)
+			{
+				var currentNode = listeners.Last;
+				while (currentNode != null)
+				{
+					currentNode.Value.Invoke(message);
+					currentNode = currentNode.Previous;
+				}
+			}
+		}
+
+		/// <summary>
+		/// 延迟广播事件
+		/// </summary>
+		public static void PostMessage(IEventMessage message)
+		{
+			int eventId = message.GetType().GetHashCode();
+			PostMessage(eventId, message);
+		}
+
+		/// <summary>
+		/// 延迟广播事件
+		/// </summary>
+		public static void PostMessage(int eventId, IEventMessage message)
+		{
+			var wrapper = new PostWrapper();
+			wrapper.PostFrame = UnityEngine.Time.frameCount;
+			wrapper.EventID = eventId;
+			wrapper.Message = message;
+			_postingList.Add(wrapper);
+		}
+	}
+}

+ 11 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniEvent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a2a39e0393e22c44b8416d1445c9bb2c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 12 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniEventDriver.cs

@@ -0,0 +1,12 @@
+using UnityEngine;
+
+namespace UniFramework.Event
+{
+	internal class UniEventDriver : MonoBehaviour
+	{
+		void Update()
+		{
+			UniEvent.Update();
+		}
+	}
+}

+ 11 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniEventDriver.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 91e57d06457f3ec40914e4d3ed58c070
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 16 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniFramework.Event.asmdef

@@ -0,0 +1,16 @@
+{
+    "name": "UniFramework.Event",
+    "rootNamespace": "",
+    "references": [
+        "GUID:e34a5702dd353724aa315fb8011f08c3"
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniFramework.Event.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: f22fac247a56d2d41b687bb0d900e54e
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 21 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniLogger.cs

@@ -0,0 +1,21 @@
+using System.Diagnostics;
+
+namespace UniFramework.Event
+{
+	internal static class UniLogger
+	{
+		[Conditional("DEBUG")]
+		public static void Log(string info)
+		{
+			UnityEngine.Debug.Log(info);
+		}
+		public static void Warning(string info)
+		{
+			UnityEngine.Debug.LogWarning(info);
+		}
+		public static void Error(string info)
+		{
+			UnityEngine.Debug.LogError(info);
+		}
+	}
+}

+ 11 - 0
GameClient/Assets/UniFramework/UniEvent/Runtime/UniLogger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9bb2f71f321705a4286de583f1c930d7
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: