mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-12-11 20:15:10 +01:00
fix invoke issues
This commit is contained in:
parent
545cf27f8f
commit
d4e9b372b8
@ -1,4 +1,5 @@
|
||||
using QSB.Events;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Messages;
|
||||
@ -59,13 +60,13 @@ namespace QSB.Messaging
|
||||
private void OnClientReceiveMessageHandler(QNetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnClientReceiveMessage?.Invoke(message);
|
||||
OnClientReceiveMessage?.SafeInvoke(message);
|
||||
}
|
||||
|
||||
private void OnServerReceiveMessageHandler(QNetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnServerReceiveMessage?.Invoke(message);
|
||||
OnServerReceiveMessage?.SafeInvoke(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,11 +15,9 @@ using System.Linq;
|
||||
|
||||
namespace QSB.Patches
|
||||
{
|
||||
public delegate void PatchEvent(QSBPatchTypes type);
|
||||
|
||||
public static class QSBPatchManager
|
||||
{
|
||||
public static event PatchEvent OnPatchType;
|
||||
public static event Action<QSBPatchTypes> OnPatchType;
|
||||
|
||||
private static List<QSBPatch> _patchList = new List<QSBPatch>();
|
||||
|
||||
@ -46,7 +44,7 @@ namespace QSB.Patches
|
||||
|
||||
public static void DoPatchType(QSBPatchTypes type)
|
||||
{
|
||||
OnPatchType?.Invoke(type);
|
||||
OnPatchType?.SafeInvoke(type);
|
||||
DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info);
|
||||
foreach (var patch in _patchList.Where(x => x.Type == type))
|
||||
{
|
||||
|
||||
@ -185,7 +185,7 @@ namespace QSB
|
||||
|
||||
_lobby.CanEditName = false;
|
||||
|
||||
OnNetworkManagerReady?.Invoke();
|
||||
OnNetworkManagerReady?.SafeInvoke();
|
||||
IsReady = true;
|
||||
|
||||
QSBCore.Helper.Events.Unity.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
@ -11,7 +12,6 @@ namespace QSB
|
||||
public static bool IsInUniverse => InUniverse(CurrentScene);
|
||||
|
||||
public static event Action<OWScene, bool> OnSceneLoaded;
|
||||
|
||||
public static event Action<OWScene> OnUniverseSceneLoaded;
|
||||
|
||||
static QSBSceneManager()
|
||||
@ -24,10 +24,10 @@ namespace QSB
|
||||
{
|
||||
DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
|
||||
var universe = InUniverse(newScene);
|
||||
OnSceneLoaded?.Invoke(newScene, universe);
|
||||
OnSceneLoaded?.SafeInvoke(newScene, universe);
|
||||
if (universe)
|
||||
{
|
||||
OnUniverseSceneLoaded?.Invoke(newScene);
|
||||
OnUniverseSceneLoaded?.SafeInvoke(newScene, universe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ namespace QSB.TimeSync
|
||||
if (QNetworkServer.active)
|
||||
{
|
||||
QSBCore.HasWokenUp = true;
|
||||
RespawnOnDeath.Instance.Init();
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +85,6 @@ namespace QSB.TimeSync
|
||||
if (IsServer)
|
||||
{
|
||||
SendServerTime();
|
||||
RespawnOnDeath.Instance.Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
using QSB.Player;
|
||||
using OWML.Common;
|
||||
using QSB.Player;
|
||||
using QSB.TransformSync;
|
||||
using QuantumUNET;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility
|
||||
@ -24,7 +26,7 @@ namespace QSB.Utility
|
||||
public static GameObject InstantiateInactive(this GameObject original)
|
||||
{
|
||||
original.SetActive(false);
|
||||
var copy = Object.Instantiate(original);
|
||||
var copy = UnityEngine.Object.Instantiate(original);
|
||||
original.SetActive(true);
|
||||
return copy;
|
||||
}
|
||||
@ -39,5 +41,21 @@ namespace QSB.Utility
|
||||
var controller = go.GetComponent<PlayerTransformSync>();
|
||||
return QSBPlayerManager.GetPlayer(controller.NetId.Value);
|
||||
}
|
||||
|
||||
// C#
|
||||
public static void SafeInvoke(this MulticastDelegate multicast, params object[] args)
|
||||
{
|
||||
foreach (var del in multicast.GetInvocationList())
|
||||
{
|
||||
try
|
||||
{
|
||||
del.DynamicInvoke(args);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugLog.DebugWrite($"Error while invoking delegate {del.Method.DeclaringType.Name}.{del.Method.Name}", MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,11 +26,11 @@ namespace QSB.Utility
|
||||
_wasEnabled = state;
|
||||
if (state == ComponentState.Enabled)
|
||||
{
|
||||
OnEnableEvent?.Invoke();
|
||||
OnEnableEvent?.SafeInvoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDisableEvent?.Invoke();
|
||||
OnDisableEvent?.SafeInvoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user