ball 项目提交
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10e424129050f3a4ab3fdc991bf91318
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public abstract class BaseDispatcher<T, Msg, Param> : IDisposable where T : class, new() where Param : class
|
||||
{
|
||||
private static T m_instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_instance == null)
|
||||
{
|
||||
m_instance = new T();
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgPriorityDict = new();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgDict = new();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgFinallyDict = new();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgOnceDict = new();
|
||||
|
||||
public void AddListener(Msg msgId, Action<Param> listener)
|
||||
{
|
||||
if (m_msgDict.TryGetValue(msgId, out var value))
|
||||
{
|
||||
value.Add(listener);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = ListPool<Action<Param>>.Get();
|
||||
list.Add(listener);
|
||||
m_msgDict.Add(msgId, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOnceListener(Msg msgId, Action<Param> listener)
|
||||
{
|
||||
if (m_msgOnceDict.TryGetValue(msgId, out var value))
|
||||
{
|
||||
value.Add(listener);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = ListPool<Action<Param>>.Get();
|
||||
list.Add(listener);
|
||||
m_msgOnceDict.Add(msgId, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveListener(Msg msgId, Action<Param> listener)
|
||||
{
|
||||
if (m_msgDict.TryGetValue(msgId, out var list))
|
||||
{
|
||||
if (list.Contains(listener))
|
||||
{
|
||||
list.Remove(listener);
|
||||
if (list.Count == 0)
|
||||
{
|
||||
ListPool<Action<Param>>.Release(list);
|
||||
m_msgDict.Remove(msgId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispatch(Msg msgId, Param param = null)
|
||||
{
|
||||
InvokeMethods(m_msgPriorityDict, msgId, param);
|
||||
InvokeMethods(m_msgDict, msgId, param);
|
||||
InvokeMethods(m_msgFinallyDict, msgId, param);
|
||||
InvokeMethods(m_msgOnceDict, msgId, param);
|
||||
|
||||
if (m_msgOnceDict.ContainsKey(msgId))
|
||||
{
|
||||
ListPool<Action<Param>>.Release(m_msgOnceDict[msgId]);
|
||||
m_msgOnceDict.Remove(msgId);
|
||||
}
|
||||
}
|
||||
|
||||
private void InvokeMethods(Dictionary<Msg, List<Action<Param>>> msgDict, Msg msgId, Param param)
|
||||
{
|
||||
if (!msgDict.ContainsKey(msgId)) return;
|
||||
|
||||
var rawList = msgDict[msgId];
|
||||
int funcCount = rawList.Count;
|
||||
if (funcCount == 1)
|
||||
{
|
||||
Action<Param> onEvent = rawList[0];
|
||||
onEvent(param);
|
||||
return;
|
||||
}
|
||||
|
||||
var invokeFuncs = ListPool<Action<Param>>.Get();
|
||||
invokeFuncs.AddRange(rawList);
|
||||
for (var i = 0; i < funcCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var onEvent = invokeFuncs[i];
|
||||
onEvent(param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
ListPool<Action<Param>>.Release(invokeFuncs);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_instance = null;
|
||||
|
||||
m_msgPriorityDict.Clear();
|
||||
m_msgDict.Clear();
|
||||
m_msgFinallyDict.Clear();
|
||||
m_msgOnceDict.Clear();
|
||||
m_msgPriorityDict = null;
|
||||
m_msgDict = null;
|
||||
m_msgFinallyDict = null;
|
||||
m_msgOnceDict = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4b55125cefc9754888cccfc76bee4c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class BaseMainThreadDispatcher<T, Msg, Param> : SingletonUnity<T>
|
||||
where T : SingletonUnity<T>
|
||||
where Param : class
|
||||
{
|
||||
private class MainThreadMsgClass
|
||||
{
|
||||
public Msg currMsgId;
|
||||
public Param currParam;
|
||||
}
|
||||
|
||||
private Queue<MainThreadMsgClass> m_msgQueue = new Queue<MainThreadMsgClass>();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgPriorityDict = new Dictionary<Msg, List<Action<Param>>>();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgDict = new Dictionary<Msg, List<Action<Param>>>();
|
||||
private Dictionary<Msg, List<Action<Param>>> m_msgOnceDict = new Dictionary<Msg, List<Action<Param>>>();
|
||||
|
||||
private object m_queueLock = new object();
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_msgQueue.Count <= 0) return;
|
||||
|
||||
while (m_msgQueue.Count > 0)
|
||||
{
|
||||
MainThreadMsgClass msg;
|
||||
lock (m_queueLock)
|
||||
{
|
||||
msg = m_msgQueue.Dequeue();
|
||||
}
|
||||
|
||||
AutoDispatch(msg.currMsgId, msg.currParam);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispatch(Msg msgId, Param param = null)
|
||||
{
|
||||
if (!m_msgPriorityDict.ContainsKey(msgId)
|
||||
&& !m_msgDict.ContainsKey(msgId)
|
||||
&& !m_msgOnceDict.ContainsKey(msgId))
|
||||
return;
|
||||
|
||||
MainThreadMsgClass msg = new MainThreadMsgClass
|
||||
{
|
||||
currMsgId = msgId,
|
||||
currParam = param,
|
||||
};
|
||||
lock (m_queueLock)
|
||||
{
|
||||
m_msgQueue.Enqueue(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoDispatch(Msg msgId, Param param)
|
||||
{
|
||||
InvokeMethods(m_msgPriorityDict, msgId, param);
|
||||
InvokeMethods(m_msgDict, msgId, param);
|
||||
InvokeMethods(m_msgOnceDict, msgId, param);
|
||||
|
||||
if (m_msgOnceDict.ContainsKey(msgId))
|
||||
{
|
||||
ListPool<Action<Param>>.Release(m_msgOnceDict[msgId]);
|
||||
m_msgOnceDict.Remove(msgId);
|
||||
}
|
||||
}
|
||||
|
||||
private void InvokeMethods(Dictionary<Msg, List<Action<Param>>> msgDict, Msg msgId, Param param)
|
||||
{
|
||||
if (!msgDict.ContainsKey(msgId)) return;
|
||||
|
||||
List<Action<Param>> rawList = msgDict[msgId];
|
||||
int funcCount = rawList.Count;
|
||||
if (funcCount == 1)
|
||||
{
|
||||
Action<Param> onEvent = rawList[0];
|
||||
onEvent(param);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Action<Param>> invokeFuncs = ListPool<Action<Param>>.Get();
|
||||
invokeFuncs.AddRange(rawList);
|
||||
for (int i = 0; i < funcCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
Action<Param> onEvent = invokeFuncs[i];
|
||||
onEvent(param);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
ListPool<Action<Param>>.Release(invokeFuncs);
|
||||
}
|
||||
|
||||
protected override string ParentRootName
|
||||
{
|
||||
get { return AppObjConst.DispatcherGoName; }
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
m_msgPriorityDict.Clear();
|
||||
m_msgDict.Clear();
|
||||
m_msgOnceDict.Clear();
|
||||
m_msgPriorityDict = null;
|
||||
m_msgDict = null;
|
||||
m_msgOnceDict = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e02321e1c5d556b4484a914fec6eafbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7926ab78fe6049f3bff905262b9b4695
|
||||
timeCreated: 1682307945
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class AppDispatcher : BaseDispatcher<AppDispatcher, uint, object> { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38ec268add4ac6743a27b7167bdcb36a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class CtrlDispatcher : BaseDispatcher<CtrlDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f627301519ad9ac43ba05e525564d3a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class DataDispatcher : BaseDispatcher<DataDispatcher, string, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 080dce14c0be15a448f7a6f1d316700f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class GameDispatcher : BaseDispatcher<GameDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab8a1624eafed174385147056385f287
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class MainThreadDispatcher : BaseMainThreadDispatcher<MainThreadDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc759fa7eaebc574da1d3990ca6acfa5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class ModelDispatcher : BaseDispatcher<ModelDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 730ba6382f4f49444a8219f08543f431
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class NetworkDispatcher : BaseDispatcher<NetworkDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81a02ff4d9ca458aa70fe26ab514bb99
|
||||
timeCreated: 1681977441
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class PreferencesDispatcher<T> : BaseDispatcher<PreferencesDispatcher<T>, string, ChangeValue<T>>
|
||||
{
|
||||
public ChangeValue<T> changeValue;
|
||||
|
||||
public PreferencesDispatcher()
|
||||
{
|
||||
changeValue = new ChangeValue<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9387267f575e6bb4ca279738a461ad61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class UICtrlDispatcher : BaseDispatcher<UICtrlDispatcher, uint, object>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1a26910085caa349b769e0be54a023a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29aecd4f55584cddae5eb19c86727362
|
||||
timeCreated: 1682308355
|
||||
@@ -0,0 +1,26 @@
|
||||
public static class AppMsg
|
||||
{
|
||||
public const uint BASE = 0;
|
||||
private static uint Cursor_BASE = BASE;
|
||||
public static readonly uint App_Quit = ++Cursor_BASE;
|
||||
public static readonly uint App_Focus_False = ++Cursor_BASE;
|
||||
public static readonly uint App_Pause_True = ++Cursor_BASE;
|
||||
public static readonly uint App_GamePause = ++Cursor_BASE;
|
||||
public static readonly uint App_GameResume = ++Cursor_BASE;
|
||||
public static readonly uint App_SwitchLanguage = ++Cursor_BASE;
|
||||
public static readonly uint UI_DisplayLoadingUI = ++Cursor_BASE;
|
||||
public static readonly uint UI_HideLoadingUI = ++Cursor_BASE;
|
||||
public static readonly uint UI_LoadingInitAsset = ++Cursor_BASE;
|
||||
public static readonly uint AppManagerRegister = ++Cursor_BASE;
|
||||
public static readonly uint InitUIMgr = ++Cursor_BASE;
|
||||
public static readonly uint UIEvent_UIOpen = ++Cursor_BASE;
|
||||
public static readonly uint UIEvent_UIClose = ++Cursor_BASE;
|
||||
public static readonly uint UIEvent_UIDisplay = ++Cursor_BASE;
|
||||
public static readonly uint UIEvent_UIHide = ++Cursor_BASE;
|
||||
public static readonly uint KeyCode_Home = ++Cursor_BASE;
|
||||
public static readonly uint KeyCode_Escape = ++Cursor_BASE;
|
||||
public static readonly uint TimeScale_Change = ++Cursor_BASE;
|
||||
public static readonly uint WorldRaycast_EnableChange = ++Cursor_BASE;
|
||||
public static readonly uint App_Focus_True = ++Cursor_BASE;
|
||||
public static readonly uint LoginInit = ++Cursor_BASE;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b87eaa2cadb1da4f8dba83b0b9d3731
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
public static class MainThreadMsg
|
||||
{
|
||||
public const uint BASE = 0;
|
||||
private static uint Cursor_BASE = BASE;
|
||||
public static readonly uint App_Focus_True = ++Cursor_BASE;
|
||||
public static readonly uint App_Pause_False = ++Cursor_BASE;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0061a4ff521ce154c8ca284f91d1cf8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user