mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-09 22:14:26 +00:00
C L E A N
This commit is contained in:
parent
8a5600aa6a
commit
c6c76cb395
@ -3,24 +3,24 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public static class AnimControllerPatch
|
||||
{
|
||||
public static RuntimeAnimatorController SuitedAnimController { get; private set; }
|
||||
public static class AnimControllerPatch
|
||||
{
|
||||
public static RuntimeAnimatorController SuitedAnimController { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
QSB.Helper.Events.Subscribe<PlayerAnimController>(OWML.Common.Events.BeforeStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
QSB.Helper.Events.Subscribe<PlayerAnimController>(OWML.Common.Events.BeforeStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
|
||||
private static void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerAnimController playerAnimController &&
|
||||
ev == OWML.Common.Events.BeforeStart &&
|
||||
SuitedAnimController == null)
|
||||
{
|
||||
SuitedAnimController = playerAnimController.GetValue<RuntimeAnimatorController>("_baseAnimController");
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerAnimController playerAnimController &&
|
||||
ev == OWML.Common.Events.BeforeStart &&
|
||||
SuitedAnimController == null)
|
||||
{
|
||||
SuitedAnimController = playerAnimController.GetValue<RuntimeAnimatorController>("_baseAnimController");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,17 +2,17 @@
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimFloatParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
||||
public class AnimFloatParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
||||
|
||||
private float _velocity;
|
||||
private float _velocity;
|
||||
|
||||
public float Smooth(float smoothTime)
|
||||
{
|
||||
Current = Mathf.SmoothDamp(Current, Target, ref _velocity, smoothTime);
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
public float Smooth(float smoothTime)
|
||||
{
|
||||
Current = Mathf.SmoothDamp(Current, Target, ref _velocity, smoothTime);
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public enum AnimationType
|
||||
{
|
||||
Chert,
|
||||
Esker,
|
||||
Feldspar,
|
||||
Gabbro,
|
||||
PlayerSuited,
|
||||
PlayerUnsuited,
|
||||
Riebeck
|
||||
}
|
||||
public enum AnimationType
|
||||
{
|
||||
Chert,
|
||||
Esker,
|
||||
Feldspar,
|
||||
Gabbro,
|
||||
PlayerSuited,
|
||||
PlayerUnsuited,
|
||||
Riebeck
|
||||
}
|
||||
}
|
@ -7,92 +7,92 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
private const float SmoothTime = 0.05f;
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
private const float SmoothTime = 0.05f;
|
||||
|
||||
private Animator _from;
|
||||
private Animator _to;
|
||||
private Animator _from;
|
||||
private Animator _to;
|
||||
|
||||
private readonly Dictionary<string, AnimFloatParam> _floatParams = new Dictionary<string, AnimFloatParam>();
|
||||
private readonly Dictionary<string, AnimFloatParam> _floatParams = new Dictionary<string, AnimFloatParam>();
|
||||
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
_from = from;
|
||||
_to = to;
|
||||
if (_from.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
|
||||
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
|
||||
}
|
||||
else if (_to.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
_from = from;
|
||||
_to = to;
|
||||
if (_from.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
|
||||
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
|
||||
}
|
||||
else if (_to.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerInfo GetPlayer()
|
||||
{
|
||||
return QSBPlayerManager.GetSyncObjects<AnimationSync>().First(x => x.Mirror == this).Player;
|
||||
}
|
||||
private PlayerInfo GetPlayer()
|
||||
{
|
||||
return QSBPlayerManager.GetSyncObjects<AnimationSync>().First(x => x.Mirror == this).Player;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_to == null || _from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_to.runtimeAnimatorController != _from.runtimeAnimatorController)
|
||||
{
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
SyncParams();
|
||||
SmoothFloats();
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (_to == null || _from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_to.runtimeAnimatorController != _from.runtimeAnimatorController)
|
||||
{
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
SyncParams();
|
||||
SmoothFloats();
|
||||
}
|
||||
|
||||
private void SyncParams()
|
||||
{
|
||||
foreach (var fromParam in _from.parameters)
|
||||
{
|
||||
switch (fromParam.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
if (!_floatParams.ContainsKey(fromParam.name))
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Tried to sync anim float that doesn't exist in dict : {fromParam.name}", MessageType.Warning);
|
||||
RebuildFloatParams();
|
||||
break;
|
||||
}
|
||||
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
_to.SetBool(fromParam.name, _from.GetBool(fromParam.name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void SyncParams()
|
||||
{
|
||||
foreach (var fromParam in _from.parameters)
|
||||
{
|
||||
switch (fromParam.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
if (!_floatParams.ContainsKey(fromParam.name))
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Tried to sync anim float that doesn't exist in dict : {fromParam.name}", MessageType.Warning);
|
||||
RebuildFloatParams();
|
||||
break;
|
||||
}
|
||||
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
_to.SetBool(fromParam.name, _from.GetBool(fromParam.name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SmoothFloats()
|
||||
{
|
||||
foreach (var floatParam in _floatParams)
|
||||
{
|
||||
var current = floatParam.Value.Smooth(SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, current);
|
||||
}
|
||||
}
|
||||
private void SmoothFloats()
|
||||
{
|
||||
foreach (var floatParam in _floatParams)
|
||||
{
|
||||
var current = floatParam.Value.Smooth(SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, current);
|
||||
}
|
||||
}
|
||||
|
||||
public void RebuildFloatParams()
|
||||
{
|
||||
_floatParams.Clear();
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RebuildFloatParams()
|
||||
{
|
||||
_floatParams.Clear();
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using QSB.QuantumUNET;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
|
@ -5,26 +5,26 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
public class ChangeAnimTypeEvent : QSBEvent<EnumMessage<AnimationType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayInstrument;
|
||||
public class ChangeAnimTypeEvent : QSBEvent<EnumMessage<AnimationType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayInstrument;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<uint, AnimationType>.AddListener(EventNames.QSBChangeAnimType, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<uint, AnimationType>.AddListener(EventNames.QSBChangeAnimType, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<uint, AnimationType>.RemoveListener(EventNames.QSBChangeAnimType, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<uint, AnimationType>.RemoveListener(EventNames.QSBChangeAnimType, Handler);
|
||||
|
||||
private void Handler(uint player, AnimationType type) => SendEvent(CreateMessage(player, type));
|
||||
private void Handler(uint player, AnimationType type) => SendEvent(CreateMessage(player, type));
|
||||
|
||||
private EnumMessage<AnimationType> CreateMessage(uint player, AnimationType type) => new EnumMessage<AnimationType>
|
||||
{
|
||||
AboutId = player,
|
||||
Value = type
|
||||
};
|
||||
private EnumMessage<AnimationType> CreateMessage(uint player, AnimationType type) => new EnumMessage<AnimationType>
|
||||
{
|
||||
AboutId = player,
|
||||
Value = type
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(EnumMessage<AnimationType> message)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetSyncObject<InstrumentsManager>(message.AboutId).CheckInstrumentProps(message.Value);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(EnumMessage<AnimationType> message)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetSyncObject<InstrumentsManager>(message.AboutId).CheckInstrumentProps(message.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,30 +4,30 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
public class CrouchEvent : QSBEvent<FloatMessage>
|
||||
{
|
||||
public override EventType Type => EventType.AnimTrigger;
|
||||
public class CrouchEvent : QSBEvent<FloatMessage>
|
||||
{
|
||||
public override EventType Type => EventType.AnimTrigger;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<float>.AddListener(EventNames.QSBCrouch, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<float>.AddListener(EventNames.QSBCrouch, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<float>.RemoveListener(EventNames.QSBCrouch, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<float>.RemoveListener(EventNames.QSBCrouch, Handler);
|
||||
|
||||
private void Handler(float value) => SendEvent(CreateMessage(value));
|
||||
private void Handler(float value) => SendEvent(CreateMessage(value));
|
||||
|
||||
private FloatMessage CreateMessage(float value) => new FloatMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = value
|
||||
};
|
||||
private FloatMessage CreateMessage(float value) => new FloatMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = value
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(FloatMessage message)
|
||||
{
|
||||
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
|
||||
if (animationSync == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
animationSync.HandleCrouch(message.Value);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(FloatMessage message)
|
||||
{
|
||||
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
|
||||
if (animationSync == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
animationSync.HandleCrouch(message.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,52 +4,52 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.SuitActiveChange;
|
||||
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.SuitActiveChange;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
|
||||
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
||||
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
||||
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
||||
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
||||
|
||||
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = value
|
||||
};
|
||||
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = value
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player?.UpdateState(State.Suit, message.ToggleValue);
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player?.UpdateState(State.Suit, message.ToggleValue);
|
||||
|
||||
if (!player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var animator = player.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.SetAnimationType(type);
|
||||
}
|
||||
var animator = player.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.SetAnimationType(type);
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(ToggleMessage message)
|
||||
{
|
||||
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
|
||||
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.CurrentType = type;
|
||||
}
|
||||
}
|
||||
public override void OnReceiveLocal(ToggleMessage message)
|
||||
{
|
||||
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
|
||||
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.CurrentType = type;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,34 +2,34 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
class QSBAnimationMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
stateHash = (int)reader.ReadPackedUInt32();
|
||||
normalizedTime = reader.ReadSingle();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
stateHash = (int)reader.ReadPackedUInt32();
|
||||
normalizedTime = reader.ReadSingle();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)stateHash);
|
||||
writer.Write(normalizedTime);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)stateHash);
|
||||
writer.Write(normalizedTime);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,28 +2,28 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationParametersMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
class QSBAnimationParametersMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,21 +2,21 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationTriggerMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int hash;
|
||||
class QSBAnimationTriggerMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int hash;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
hash = (int)reader.ReadPackedUInt32();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
hash = (int)reader.ReadPackedUInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)hash);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)hash);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,23 +2,23 @@
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class PlayerHeadRotationSync : MonoBehaviour
|
||||
{
|
||||
private Animator _attachedAnimator;
|
||||
private Transform _lookBase;
|
||||
public class PlayerHeadRotationSync : MonoBehaviour
|
||||
{
|
||||
private Animator _attachedAnimator;
|
||||
private Transform _lookBase;
|
||||
|
||||
public void Init(Transform lookBase)
|
||||
{
|
||||
_attachedAnimator = GetComponent<Animator>();
|
||||
_lookBase = lookBase;
|
||||
}
|
||||
public void Init(Transform lookBase)
|
||||
{
|
||||
_attachedAnimator = GetComponent<Animator>();
|
||||
_lookBase = lookBase;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
|
||||
// Get the camera's local rotation with respect to the player body
|
||||
var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation;
|
||||
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
|
||||
}
|
||||
}
|
||||
void LateUpdate()
|
||||
{
|
||||
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
|
||||
// Get the camera's local rotation with respect to the player body
|
||||
var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation;
|
||||
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,135 +11,135 @@ using UnityEngine.UI;
|
||||
|
||||
namespace QSB.ConversationSync
|
||||
{
|
||||
public class ConversationManager : MonoBehaviour
|
||||
{
|
||||
public static ConversationManager Instance { get; private set; }
|
||||
public AssetBundle ConversationAssetBundle { get; private set; }
|
||||
private GameObject BoxPrefab;
|
||||
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings = new Dictionary<CharacterDialogueTree, GameObject>();
|
||||
public class ConversationManager : MonoBehaviour
|
||||
{
|
||||
public static ConversationManager Instance { get; private set; }
|
||||
public AssetBundle ConversationAssetBundle { get; private set; }
|
||||
private GameObject BoxPrefab;
|
||||
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings = new Dictionary<CharacterDialogueTree, GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Instance = this;
|
||||
private void Start()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
ConversationAssetBundle = QSB.Helper.Assets.LoadBundle("assets/conversation");
|
||||
ConversationAssetBundle = QSB.Helper.Assets.LoadBundle("assets/conversation");
|
||||
|
||||
BoxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
|
||||
// TODO : make dynamic so it can be different sizes!
|
||||
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
|
||||
if (font == null)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Font is null!", MessageType.Error);
|
||||
}
|
||||
BoxPrefab.GetComponent<Text>().font = font;
|
||||
BoxPrefab.GetComponent<Text>().color = Color.white;
|
||||
}
|
||||
BoxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
|
||||
// TODO : make dynamic so it can be different sizes!
|
||||
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
|
||||
if (font == null)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Font is null!", MessageType.Error);
|
||||
}
|
||||
BoxPrefab.GetComponent<Text>().font = font;
|
||||
BoxPrefab.GetComponent<Text>().color = Color.white;
|
||||
}
|
||||
|
||||
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
||||
{
|
||||
var treeIndex = WorldRegistry.OldDialogueTrees.IndexOf(tree);
|
||||
if (!QSBPlayerManager.PlayerList.Any(x => x.CurrentDialogueID == treeIndex))
|
||||
{
|
||||
// No player talking to tree
|
||||
return uint.MaxValue;
|
||||
}
|
||||
// .First() should be fine here as only one player should be talking to a character.
|
||||
return QSBPlayerManager.PlayerList.First(x => x.CurrentDialogueID == treeIndex).PlayerId;
|
||||
}
|
||||
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
||||
{
|
||||
var treeIndex = WorldRegistry.OldDialogueTrees.IndexOf(tree);
|
||||
if (!QSBPlayerManager.PlayerList.Any(x => x.CurrentDialogueID == treeIndex))
|
||||
{
|
||||
// No player talking to tree
|
||||
return uint.MaxValue;
|
||||
}
|
||||
// .First() should be fine here as only one player should be talking to a character.
|
||||
return QSBPlayerManager.PlayerList.First(x => x.CurrentDialogueID == treeIndex).PlayerId;
|
||||
}
|
||||
|
||||
public void SendPlayerOption(string text)
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
|
||||
}
|
||||
public void SendPlayerOption(string text)
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
|
||||
}
|
||||
|
||||
public void SendCharacterDialogue(int id, string text)
|
||||
{
|
||||
if (id == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
|
||||
}
|
||||
public void SendCharacterDialogue(int id, string text)
|
||||
{
|
||||
if (id == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
|
||||
}
|
||||
|
||||
public void CloseBoxPlayer()
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
|
||||
}
|
||||
public void CloseBoxPlayer()
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
|
||||
}
|
||||
|
||||
public void CloseBoxCharacter(int id)
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
|
||||
}
|
||||
public void CloseBoxCharacter(int id)
|
||||
{
|
||||
GlobalMessenger<uint, string, ConversationType>
|
||||
.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
|
||||
}
|
||||
|
||||
public void SendConvState(int charId, bool state)
|
||||
{
|
||||
if (charId == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
GlobalMessenger<int, uint, bool>
|
||||
.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
|
||||
}
|
||||
public void SendConvState(int charId, bool state)
|
||||
{
|
||||
if (charId == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
GlobalMessenger<int, uint, bool>
|
||||
.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
|
||||
}
|
||||
|
||||
public void DisplayPlayerConversationBox(uint playerId, string text)
|
||||
{
|
||||
if (playerId == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Cannot display conversation box for local player!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
public void DisplayPlayerConversationBox(uint playerId, string text)
|
||||
{
|
||||
if (playerId == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Cannot display conversation box for local player!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var player = QSBPlayerManager.GetPlayer(playerId);
|
||||
var player = QSBPlayerManager.GetPlayer(playerId);
|
||||
|
||||
// Destroy old box if it exists
|
||||
var playerBox = player.CurrentDialogueBox;
|
||||
if (playerBox != null)
|
||||
{
|
||||
Destroy(playerBox);
|
||||
}
|
||||
// Destroy old box if it exists
|
||||
var playerBox = player.CurrentDialogueBox;
|
||||
if (playerBox != null)
|
||||
{
|
||||
Destroy(playerBox);
|
||||
}
|
||||
|
||||
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueBox = CreateBox(player.Body.transform, 25, text);
|
||||
}
|
||||
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueBox = CreateBox(player.Body.transform, 25, text);
|
||||
}
|
||||
|
||||
public void DisplayCharacterConversationBox(int index, string text)
|
||||
{
|
||||
if (WorldRegistry.OldDialogueTrees.ElementAtOrDefault(index) == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Tried to display character conversation box for id {index}! (Doesn't exist!)", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
public void DisplayCharacterConversationBox(int index, string text)
|
||||
{
|
||||
if (WorldRegistry.OldDialogueTrees.ElementAtOrDefault(index) == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Tried to display character conversation box for id {index}! (Doesn't exist!)", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove old box if it exists
|
||||
var oldDialogueTree = WorldRegistry.OldDialogueTrees[index];
|
||||
if (BoxMappings.ContainsKey(oldDialogueTree))
|
||||
{
|
||||
Destroy(BoxMappings[oldDialogueTree]);
|
||||
BoxMappings.Remove(oldDialogueTree);
|
||||
}
|
||||
// Remove old box if it exists
|
||||
var oldDialogueTree = WorldRegistry.OldDialogueTrees[index];
|
||||
if (BoxMappings.ContainsKey(oldDialogueTree))
|
||||
{
|
||||
Destroy(BoxMappings[oldDialogueTree]);
|
||||
BoxMappings.Remove(oldDialogueTree);
|
||||
}
|
||||
|
||||
BoxMappings.Add(oldDialogueTree, CreateBox(oldDialogueTree.gameObject.transform, 2, text));
|
||||
}
|
||||
BoxMappings.Add(oldDialogueTree, CreateBox(oldDialogueTree.gameObject.transform, 2, text));
|
||||
}
|
||||
|
||||
private GameObject CreateBox(Transform parent, float vertOffset, string text)
|
||||
{
|
||||
var newBox = Instantiate(BoxPrefab);
|
||||
newBox.SetActive(false);
|
||||
newBox.transform.parent = parent;
|
||||
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
|
||||
newBox.transform.rotation = parent.rotation;
|
||||
var lookAt = newBox.AddComponent<FaceActiveCamera>();
|
||||
lookAt.SetValue("_useLookAt", false);
|
||||
lookAt.SetValue("_localFacingVector", Vector3.back);
|
||||
lookAt.SetValue("_localRotationAxis", Vector3.up);
|
||||
newBox.GetComponent<Text>().text = text;
|
||||
newBox.SetActive(true);
|
||||
return newBox;
|
||||
}
|
||||
}
|
||||
private GameObject CreateBox(Transform parent, float vertOffset, string text)
|
||||
{
|
||||
var newBox = Instantiate(BoxPrefab);
|
||||
newBox.SetActive(false);
|
||||
newBox.transform.parent = parent;
|
||||
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
|
||||
newBox.transform.rotation = parent.rotation;
|
||||
var lookAt = newBox.AddComponent<FaceActiveCamera>();
|
||||
lookAt.SetValue("_useLookAt", false);
|
||||
lookAt.SetValue("_localFacingVector", Vector3.back);
|
||||
lookAt.SetValue("_localRotationAxis", Vector3.up);
|
||||
newBox.GetComponent<Text>().text = text;
|
||||
newBox.SetActive(true);
|
||||
return newBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,108 +7,108 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ConversationSync
|
||||
{
|
||||
public class ConversationPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
public class ConversationPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
public static void StartConversation(CharacterDialogueTree __instance)
|
||||
{
|
||||
var index = WorldRegistry.OldDialogueTrees.FindIndex(x => x == __instance);
|
||||
if (index == -1)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Index for tree {__instance.name} was -1.", MessageType.Warning);
|
||||
}
|
||||
QSBPlayerManager.LocalPlayer.CurrentDialogueID = index;
|
||||
ConversationManager.Instance.SendConvState(index, true);
|
||||
}
|
||||
public static void StartConversation(CharacterDialogueTree __instance)
|
||||
{
|
||||
var index = WorldRegistry.OldDialogueTrees.FindIndex(x => x == __instance);
|
||||
if (index == -1)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Index for tree {__instance.name} was -1.", MessageType.Warning);
|
||||
}
|
||||
QSBPlayerManager.LocalPlayer.CurrentDialogueID = index;
|
||||
ConversationManager.Instance.SendConvState(index, true);
|
||||
}
|
||||
|
||||
public static bool EndConversation(CharacterDialogueTree __instance)
|
||||
{
|
||||
if (!__instance.enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (QSBPlayerManager.LocalPlayer.CurrentDialogueID == -1)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Ending conversation with CurrentDialogueId of -1! Called from {__instance.name}", MessageType.Warning);
|
||||
return false;
|
||||
}
|
||||
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentDialogueID, false);
|
||||
ConversationManager.Instance.CloseBoxCharacter(QSBPlayerManager.LocalPlayer.CurrentDialogueID);
|
||||
QSBPlayerManager.LocalPlayer.CurrentDialogueID = -1;
|
||||
ConversationManager.Instance.CloseBoxPlayer();
|
||||
return true;
|
||||
}
|
||||
public static bool EndConversation(CharacterDialogueTree __instance)
|
||||
{
|
||||
if (!__instance.enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (QSBPlayerManager.LocalPlayer.CurrentDialogueID == -1)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Ending conversation with CurrentDialogueId of -1! Called from {__instance.name}", MessageType.Warning);
|
||||
return false;
|
||||
}
|
||||
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentDialogueID, false);
|
||||
ConversationManager.Instance.CloseBoxCharacter(QSBPlayerManager.LocalPlayer.CurrentDialogueID);
|
||||
QSBPlayerManager.LocalPlayer.CurrentDialogueID = -1;
|
||||
ConversationManager.Instance.CloseBoxPlayer();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox)
|
||||
{
|
||||
if (optionIndex < 0)
|
||||
{
|
||||
// in a page where there is no selectable options
|
||||
ConversationManager.Instance.CloseBoxPlayer();
|
||||
return true;
|
||||
}
|
||||
public static bool InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox)
|
||||
{
|
||||
if (optionIndex < 0)
|
||||
{
|
||||
// in a page where there is no selectable options
|
||||
ConversationManager.Instance.CloseBoxPlayer();
|
||||
return true;
|
||||
}
|
||||
|
||||
var selectedOption = ____currentDialogueBox.OptionFromUIIndex(optionIndex);
|
||||
ConversationManager.Instance.SendPlayerOption(selectedOption.Text);
|
||||
return true;
|
||||
}
|
||||
var selectedOption = ____currentDialogueBox.OptionFromUIIndex(optionIndex);
|
||||
ConversationManager.Instance.SendPlayerOption(selectedOption.Text);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void GetNextPage(string ____name, List<string> ____listPagesToDisplay, int ____currentPage)
|
||||
{
|
||||
var key = ____name + ____listPagesToDisplay[____currentPage];
|
||||
// Sending key so translation can be done on client side - should make different language-d clients compatible
|
||||
QSB.Helper.Events.Unity.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentDialogueID != -1,
|
||||
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentDialogueID, key));
|
||||
}
|
||||
public static void GetNextPage(string ____name, List<string> ____listPagesToDisplay, int ____currentPage)
|
||||
{
|
||||
var key = ____name + ____listPagesToDisplay[____currentPage];
|
||||
// Sending key so translation can be done on client side - should make different language-d clients compatible
|
||||
QSB.Helper.Events.Unity.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentDialogueID != -1,
|
||||
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentDialogueID, key));
|
||||
}
|
||||
|
||||
public static bool OnAnimatorIK(float ___headTrackingWeight,
|
||||
bool ___lookOnlyWhenTalking,
|
||||
bool ____playerInHeadZone,
|
||||
bool ____inConversation,
|
||||
ref float ____currentLookWeight,
|
||||
ref Vector3 ____currentLookTarget,
|
||||
DampedSpring3D ___lookSpring,
|
||||
Animator ____animator,
|
||||
CharacterDialogueTree ____dialogueTree)
|
||||
{
|
||||
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
||||
Vector3 position;
|
||||
if (playerId == uint.MaxValue)
|
||||
{
|
||||
// TODO : Find closest player and track to that camera.
|
||||
position = Locator.GetActiveCamera().transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
position = QSBPlayerManager.GetPlayer(playerId).Camera.transform.position;
|
||||
}
|
||||
float b = ___headTrackingWeight * Mathf.Min(1, (!___lookOnlyWhenTalking) ? ((!____playerInHeadZone) ? 0 : 1) : ((!____inConversation || !____playerInHeadZone) ? 0 : 1));
|
||||
____currentLookWeight = Mathf.Lerp(____currentLookWeight, b, Time.deltaTime * 2f);
|
||||
____currentLookTarget = ___lookSpring.Update(____currentLookTarget, position, Time.deltaTime);
|
||||
____animator.SetLookAtPosition(____currentLookTarget);
|
||||
____animator.SetLookAtWeight(____currentLookWeight);
|
||||
return false;
|
||||
}
|
||||
public static bool OnAnimatorIK(float ___headTrackingWeight,
|
||||
bool ___lookOnlyWhenTalking,
|
||||
bool ____playerInHeadZone,
|
||||
bool ____inConversation,
|
||||
ref float ____currentLookWeight,
|
||||
ref Vector3 ____currentLookTarget,
|
||||
DampedSpring3D ___lookSpring,
|
||||
Animator ____animator,
|
||||
CharacterDialogueTree ____dialogueTree)
|
||||
{
|
||||
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
||||
Vector3 position;
|
||||
if (playerId == uint.MaxValue)
|
||||
{
|
||||
// TODO : Find closest player and track to that camera.
|
||||
position = Locator.GetActiveCamera().transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
position = QSBPlayerManager.GetPlayer(playerId).Camera.transform.position;
|
||||
}
|
||||
float b = ___headTrackingWeight * Mathf.Min(1, (!___lookOnlyWhenTalking) ? ((!____playerInHeadZone) ? 0 : 1) : ((!____inConversation || !____playerInHeadZone) ? 0 : 1));
|
||||
____currentLookWeight = Mathf.Lerp(____currentLookWeight, b, Time.deltaTime * 2f);
|
||||
____currentLookTarget = ___lookSpring.Update(____currentLookTarget, position, Time.deltaTime);
|
||||
____animator.SetLookAtPosition(____currentLookTarget);
|
||||
____animator.SetLookAtWeight(____currentLookWeight);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool OnZoneExit(CharacterDialogueTree ____dialogueTree)
|
||||
{
|
||||
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
||||
if (playerId == uint.MaxValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool OnZoneExit(CharacterDialogueTree ____dialogueTree)
|
||||
{
|
||||
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
||||
if (playerId == uint.MaxValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<DialogueNode>("GetNextPage", typeof(ConversationPatches), nameof(GetNextPage));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterDialogueTree>("InputDialogueOption", typeof(ConversationPatches), nameof(InputDialogueOption));
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<CharacterDialogueTree>("StartConversation", typeof(ConversationPatches), nameof(StartConversation));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterDialogueTree>("EndConversation", typeof(ConversationPatches), nameof(EndConversation));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnAnimatorIK", typeof(ConversationPatches), nameof(OnAnimatorIK));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnZoneExit", typeof(ConversationPatches), nameof(OnZoneExit));
|
||||
}
|
||||
}
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<DialogueNode>("GetNextPage", typeof(ConversationPatches), nameof(GetNextPage));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterDialogueTree>("InputDialogueOption", typeof(ConversationPatches), nameof(InputDialogueOption));
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<CharacterDialogueTree>("StartConversation", typeof(ConversationPatches), nameof(StartConversation));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterDialogueTree>("EndConversation", typeof(ConversationPatches), nameof(EndConversation));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnAnimatorIK", typeof(ConversationPatches), nameof(OnAnimatorIK));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnZoneExit", typeof(ConversationPatches), nameof(OnZoneExit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
namespace QSB.ConversationSync
|
||||
{
|
||||
public enum ConversationType
|
||||
{
|
||||
Character,
|
||||
Player,
|
||||
CloseCharacter,
|
||||
ClosePlayer
|
||||
}
|
||||
public enum ConversationType
|
||||
{
|
||||
Character,
|
||||
Player,
|
||||
CloseCharacter,
|
||||
ClosePlayer
|
||||
}
|
||||
}
|
||||
|
@ -4,47 +4,47 @@ using QSB.WorldSync;
|
||||
|
||||
namespace QSB.ConversationSync.Events
|
||||
{
|
||||
public class ConversationEvent : QSBEvent<ConversationMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Conversation;
|
||||
public class ConversationEvent : QSBEvent<ConversationMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Conversation;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
|
||||
|
||||
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
|
||||
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
|
||||
|
||||
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = (int)id,
|
||||
Type = type,
|
||||
Message = message
|
||||
};
|
||||
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = (int)id,
|
||||
Type = type,
|
||||
Message = message
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ConversationMessage message)
|
||||
{
|
||||
switch (message.Type)
|
||||
{
|
||||
case ConversationType.Character:
|
||||
var translated = TextTranslation.Translate(message.Message).Trim();
|
||||
ConversationManager.Instance.DisplayCharacterConversationBox(message.ObjectId, translated);
|
||||
break;
|
||||
case ConversationType.Player:
|
||||
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
|
||||
break;
|
||||
case ConversationType.CloseCharacter:
|
||||
if (message.ObjectId == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
var tree = WorldRegistry.OldDialogueTrees[message.ObjectId];
|
||||
UnityEngine.Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
|
||||
break;
|
||||
case ConversationType.ClosePlayer:
|
||||
UnityEngine.Object.Destroy(QSBPlayerManager.GetPlayer((uint)message.ObjectId).CurrentDialogueBox);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(ConversationMessage message)
|
||||
{
|
||||
switch (message.Type)
|
||||
{
|
||||
case ConversationType.Character:
|
||||
var translated = TextTranslation.Translate(message.Message).Trim();
|
||||
ConversationManager.Instance.DisplayCharacterConversationBox(message.ObjectId, translated);
|
||||
break;
|
||||
case ConversationType.Player:
|
||||
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
|
||||
break;
|
||||
case ConversationType.CloseCharacter:
|
||||
if (message.ObjectId == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
var tree = WorldRegistry.OldDialogueTrees[message.ObjectId];
|
||||
UnityEngine.Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
|
||||
break;
|
||||
case ConversationType.ClosePlayer:
|
||||
UnityEngine.Object.Destroy(QSBPlayerManager.GetPlayer((uint)message.ObjectId).CurrentDialogueBox);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,26 +3,26 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.ConversationSync.Events
|
||||
{
|
||||
public class ConversationMessage : PlayerMessage
|
||||
{
|
||||
public ConversationType Type { get; set; }
|
||||
public int ObjectId { get; set; }
|
||||
public string Message { get; set; }
|
||||
public class ConversationMessage : PlayerMessage
|
||||
{
|
||||
public ConversationType Type { get; set; }
|
||||
public int ObjectId { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ObjectId = reader.ReadInt32();
|
||||
Type = (ConversationType)reader.ReadInt32();
|
||||
Message = reader.ReadString();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ObjectId = reader.ReadInt32();
|
||||
Type = (ConversationType)reader.ReadInt32();
|
||||
Message = reader.ReadString();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ObjectId);
|
||||
writer.Write((int)Type);
|
||||
writer.Write(Message);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ObjectId);
|
||||
writer.Write((int)Type);
|
||||
writer.Write(Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,62 +9,62 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ConversationSync.Events
|
||||
{
|
||||
public class ConversationStartEndEvent : QSBEvent<ConversationStartEndMessage>
|
||||
{
|
||||
public override EventsCore.EventType Type => EventsCore.EventType.ConversationStartEnd;
|
||||
public class ConversationStartEndEvent : QSBEvent<ConversationStartEndMessage>
|
||||
{
|
||||
public override EventsCore.EventType Type => EventsCore.EventType.ConversationStartEnd;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<int, uint, bool>.AddListener(EventNames.QSBConversationStartEnd, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<int, uint, bool>.AddListener(EventNames.QSBConversationStartEnd, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<int, uint, bool>.RemoveListener(EventNames.QSBConversationStartEnd, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<int, uint, bool>.RemoveListener(EventNames.QSBConversationStartEnd, Handler);
|
||||
|
||||
private void Handler(int charId, uint playerId, bool state) => SendEvent(CreateMessage(charId, playerId, state));
|
||||
private void Handler(int charId, uint playerId, bool state) => SendEvent(CreateMessage(charId, playerId, state));
|
||||
|
||||
private ConversationStartEndMessage CreateMessage(int charId, uint playerId, bool state) => new ConversationStartEndMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
CharacterId = charId,
|
||||
PlayerId = playerId,
|
||||
State = state
|
||||
};
|
||||
private ConversationStartEndMessage CreateMessage(int charId, uint playerId, bool state) => new ConversationStartEndMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
CharacterId = charId,
|
||||
PlayerId = playerId,
|
||||
State = state
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ConversationStartEndMessage message)
|
||||
{
|
||||
if (message.CharacterId == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Received conv. start/end event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
var dialogueTree = WorldRegistry.OldDialogueTrees[message.CharacterId];
|
||||
var animController = Resources.FindObjectsOfTypeAll<CharacterAnimController>().FirstOrDefault(x => x.GetValue<CharacterDialogueTree>("_dialogueTree") == dialogueTree);
|
||||
public override void OnReceiveRemote(ConversationStartEndMessage message)
|
||||
{
|
||||
if (message.CharacterId == -1)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Received conv. start/end event with char id -1.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
var dialogueTree = WorldRegistry.OldDialogueTrees[message.CharacterId];
|
||||
var animController = Resources.FindObjectsOfTypeAll<CharacterAnimController>().FirstOrDefault(x => x.GetValue<CharacterDialogueTree>("_dialogueTree") == dialogueTree);
|
||||
|
||||
// Make character face player and talk
|
||||
if (animController != default(CharacterAnimController))
|
||||
{
|
||||
if (message.State)
|
||||
{
|
||||
// Start talking
|
||||
QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = message.CharacterId;
|
||||
animController.SetValue("_inConversation", true);
|
||||
animController.SetValue("_playerInHeadZone", true);
|
||||
if (animController.GetValue<bool>("_hasTalkAnimation"))
|
||||
{
|
||||
animController.GetValue<Animator>("_animator").SetTrigger("Talking");
|
||||
}
|
||||
dialogueTree.GetComponent<InteractVolume>().DisableInteraction();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stop talking
|
||||
QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = -1;
|
||||
animController.SetValue("_inConversation", false);
|
||||
animController.SetValue("_playerInHeadZone", false);
|
||||
if (animController.GetValue<bool>("_hasTalkAnimation"))
|
||||
{
|
||||
animController.GetValue<Animator>("_animator").SetTrigger("Idle");
|
||||
}
|
||||
dialogueTree.GetComponent<InteractVolume>().EnableInteraction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make character face player and talk
|
||||
if (animController != default(CharacterAnimController))
|
||||
{
|
||||
if (message.State)
|
||||
{
|
||||
// Start talking
|
||||
QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = message.CharacterId;
|
||||
animController.SetValue("_inConversation", true);
|
||||
animController.SetValue("_playerInHeadZone", true);
|
||||
if (animController.GetValue<bool>("_hasTalkAnimation"))
|
||||
{
|
||||
animController.GetValue<Animator>("_animator").SetTrigger("Talking");
|
||||
}
|
||||
dialogueTree.GetComponent<InteractVolume>().DisableInteraction();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stop talking
|
||||
QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = -1;
|
||||
animController.SetValue("_inConversation", false);
|
||||
animController.SetValue("_playerInHeadZone", false);
|
||||
if (animController.GetValue<bool>("_hasTalkAnimation"))
|
||||
{
|
||||
animController.GetValue<Animator>("_animator").SetTrigger("Idle");
|
||||
}
|
||||
dialogueTree.GetComponent<InteractVolume>().EnableInteraction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,26 +3,26 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.ConversationSync.Events
|
||||
{
|
||||
public class ConversationStartEndMessage : PlayerMessage
|
||||
{
|
||||
public int CharacterId { get; set; }
|
||||
public uint PlayerId { get; set; }
|
||||
public bool State { get; set; }
|
||||
public class ConversationStartEndMessage : PlayerMessage
|
||||
{
|
||||
public int CharacterId { get; set; }
|
||||
public uint PlayerId { get; set; }
|
||||
public bool State { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
CharacterId = reader.ReadInt32();
|
||||
PlayerId = reader.ReadUInt32();
|
||||
State = reader.ReadBoolean();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
CharacterId = reader.ReadInt32();
|
||||
PlayerId = reader.ReadUInt32();
|
||||
State = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(CharacterId);
|
||||
writer.Write(PlayerId);
|
||||
writer.Write(State);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(CharacterId);
|
||||
writer.Write(PlayerId);
|
||||
writer.Write(State);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,31 +3,31 @@ using System.Linq;
|
||||
|
||||
namespace QSB.DeathSync
|
||||
{
|
||||
public class DeathPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
||||
public class DeathPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
||||
|
||||
public static bool PreFinishDeathSequence(DeathType deathType)
|
||||
{
|
||||
if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
|
||||
{
|
||||
// Allow real death
|
||||
return true;
|
||||
}
|
||||
public static bool PreFinishDeathSequence(DeathType deathType)
|
||||
{
|
||||
if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
|
||||
{
|
||||
// Allow real death
|
||||
return true;
|
||||
}
|
||||
|
||||
RespawnOnDeath.Instance.ResetShip();
|
||||
RespawnOnDeath.Instance.ResetPlayer();
|
||||
RespawnOnDeath.Instance.ResetShip();
|
||||
RespawnOnDeath.Instance.ResetPlayer();
|
||||
|
||||
// Prevent original death method from running.
|
||||
return false;
|
||||
}
|
||||
// Prevent original death method from running.
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void BroadcastDeath(DeathType deathType) => GlobalMessenger<DeathType>.FireEvent(EventNames.QSBPlayerDeath, deathType);
|
||||
public static void BroadcastDeath(DeathType deathType) => GlobalMessenger<DeathType>.FireEvent(EventNames.QSBPlayerDeath, deathType);
|
||||
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
|
||||
}
|
||||
}
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,29 +5,29 @@ using QSB.Utility;
|
||||
|
||||
namespace QSB.DeathSync.Events
|
||||
{
|
||||
public class PlayerDeathEvent : QSBEvent<EnumMessage<DeathType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerDeath;
|
||||
public class PlayerDeathEvent : QSBEvent<EnumMessage<DeathType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerDeath;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<DeathType>.RemoveListener(EventNames.QSBPlayerDeath, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<DeathType>.RemoveListener(EventNames.QSBPlayerDeath, Handler);
|
||||
|
||||
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
|
||||
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
|
||||
|
||||
private EnumMessage<DeathType> CreateMessage(DeathType type) => new EnumMessage<DeathType>
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = type
|
||||
};
|
||||
private EnumMessage<DeathType> CreateMessage(DeathType type) => new EnumMessage<DeathType>
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = type
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(EnumMessage<DeathType> message)
|
||||
{
|
||||
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
|
||||
var deathMessage = Necronomicon.GetPhrase(message.Value);
|
||||
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
||||
}
|
||||
public override void OnReceiveRemote(EnumMessage<DeathType> message)
|
||||
{
|
||||
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
|
||||
var deathMessage = Necronomicon.GetPhrase(message.Value);
|
||||
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(EnumMessage<DeathType> message) => OnReceiveRemote(message);
|
||||
}
|
||||
public override void OnReceiveLocal(EnumMessage<DeathType> message) => OnReceiveRemote(message);
|
||||
}
|
||||
}
|
||||
|
@ -4,102 +4,102 @@ using System.Linq;
|
||||
|
||||
namespace QSB.DeathSync
|
||||
{
|
||||
public static class Necronomicon
|
||||
{
|
||||
public static class Necronomicon
|
||||
{
|
||||
|
||||
private static readonly Dictionary<DeathType, string[]> DeathDictionary = new Dictionary<DeathType, string[]>
|
||||
{
|
||||
{ DeathType.Default, new[]
|
||||
{
|
||||
"{0} died"
|
||||
} },
|
||||
{ DeathType.Impact, new[]
|
||||
{
|
||||
"{0} forgot to use retro-rockets",
|
||||
"{0} bonked into the ground too hard",
|
||||
"{0} went splat"
|
||||
} },
|
||||
{ DeathType.Asphyxiation, new[]
|
||||
{
|
||||
"{0} forgot to breathe",
|
||||
"{0} forgot how to breathe",
|
||||
"{0} forgot to check their oxygen meter",
|
||||
"{0} lacked oxygen",
|
||||
"{0} didn't need air anyway"
|
||||
} },
|
||||
{ DeathType.Energy, new[]
|
||||
{
|
||||
"{0} was cooked",
|
||||
"{0} failed the Hotshot achievement",
|
||||
"{0} forgot to install an AC unit",
|
||||
"{0} got too hot"
|
||||
} },
|
||||
{ DeathType.Supernova, new[]
|
||||
{
|
||||
"{0} ran out of time",
|
||||
"{0} got vaporized",
|
||||
"{0} lost track of time",
|
||||
"{0} got front row seats to the supernova",
|
||||
"{0} heard the End of Times music",
|
||||
"{0} watched the sun go kaboom",
|
||||
"{0} became cosmic marshmallow",
|
||||
"{0} photosynthesized too much"
|
||||
} },
|
||||
{ DeathType.Digestion, new[]
|
||||
{
|
||||
"{0} was eaten",
|
||||
"{0} found a fish",
|
||||
"{0} encountered an evil creature",
|
||||
"{0} followed the light, then was followed by it",
|
||||
"{0} messed with the wrong species of fish"
|
||||
} },
|
||||
{ DeathType.BigBang, new[]
|
||||
{
|
||||
"{0} sacrificed themself for the universe",
|
||||
"{0} knows the true meaning of sacrifice",
|
||||
"{0} won at the cost of their life"
|
||||
} },
|
||||
{ DeathType.Crushed, new[]
|
||||
{
|
||||
"{0} went through the tunnel too slow",
|
||||
"{0} didn't make it out in time",
|
||||
"{0} was squished",
|
||||
"{0} thought the Sunless City was safe",
|
||||
"{0} was buried"
|
||||
} },
|
||||
{ DeathType.Meditation, new[]
|
||||
{
|
||||
"{0} took a deep breath and died",
|
||||
"{0} fell asleep",
|
||||
"{0} got killed by Gabbro's advice"
|
||||
} },
|
||||
{ DeathType.TimeLoop, new[]
|
||||
{
|
||||
"{0} ran out of time",
|
||||
"{0} was caught by a statue",
|
||||
"{0}'s memories were pilfered",
|
||||
"{0}'s memories fell into a black hole",
|
||||
"{0}'s universe was eaten by Grobletombus"
|
||||
} },
|
||||
{ DeathType.Lava, new[]
|
||||
{
|
||||
"{0} tried to swim in lava",
|
||||
"{0} didn't know what the glowy orange liquid was",
|
||||
"{0} slipped in lava",
|
||||
"{0} became one with the glowing gooey rock"
|
||||
} },
|
||||
{ DeathType.BlackHole, new[]
|
||||
{
|
||||
"{0} should visit the Ash Twin Project again",
|
||||
"{0} waited inside the Ash Twin Project",
|
||||
"{0} chased their memories"
|
||||
} }
|
||||
};
|
||||
private static readonly Dictionary<DeathType, string[]> DeathDictionary = new Dictionary<DeathType, string[]>
|
||||
{
|
||||
{ DeathType.Default, new[]
|
||||
{
|
||||
"{0} died"
|
||||
} },
|
||||
{ DeathType.Impact, new[]
|
||||
{
|
||||
"{0} forgot to use retro-rockets",
|
||||
"{0} bonked into the ground too hard",
|
||||
"{0} went splat"
|
||||
} },
|
||||
{ DeathType.Asphyxiation, new[]
|
||||
{
|
||||
"{0} forgot to breathe",
|
||||
"{0} forgot how to breathe",
|
||||
"{0} forgot to check their oxygen meter",
|
||||
"{0} lacked oxygen",
|
||||
"{0} didn't need air anyway"
|
||||
} },
|
||||
{ DeathType.Energy, new[]
|
||||
{
|
||||
"{0} was cooked",
|
||||
"{0} failed the Hotshot achievement",
|
||||
"{0} forgot to install an AC unit",
|
||||
"{0} got too hot"
|
||||
} },
|
||||
{ DeathType.Supernova, new[]
|
||||
{
|
||||
"{0} ran out of time",
|
||||
"{0} got vaporized",
|
||||
"{0} lost track of time",
|
||||
"{0} got front row seats to the supernova",
|
||||
"{0} heard the End of Times music",
|
||||
"{0} watched the sun go kaboom",
|
||||
"{0} became cosmic marshmallow",
|
||||
"{0} photosynthesized too much"
|
||||
} },
|
||||
{ DeathType.Digestion, new[]
|
||||
{
|
||||
"{0} was eaten",
|
||||
"{0} found a fish",
|
||||
"{0} encountered an evil creature",
|
||||
"{0} followed the light, then was followed by it",
|
||||
"{0} messed with the wrong species of fish"
|
||||
} },
|
||||
{ DeathType.BigBang, new[]
|
||||
{
|
||||
"{0} sacrificed themself for the universe",
|
||||
"{0} knows the true meaning of sacrifice",
|
||||
"{0} won at the cost of their life"
|
||||
} },
|
||||
{ DeathType.Crushed, new[]
|
||||
{
|
||||
"{0} went through the tunnel too slow",
|
||||
"{0} didn't make it out in time",
|
||||
"{0} was squished",
|
||||
"{0} thought the Sunless City was safe",
|
||||
"{0} was buried"
|
||||
} },
|
||||
{ DeathType.Meditation, new[]
|
||||
{
|
||||
"{0} took a deep breath and died",
|
||||
"{0} fell asleep",
|
||||
"{0} got killed by Gabbro's advice"
|
||||
} },
|
||||
{ DeathType.TimeLoop, new[]
|
||||
{
|
||||
"{0} ran out of time",
|
||||
"{0} was caught by a statue",
|
||||
"{0}'s memories were pilfered",
|
||||
"{0}'s memories fell into a black hole",
|
||||
"{0}'s universe was eaten by Grobletombus"
|
||||
} },
|
||||
{ DeathType.Lava, new[]
|
||||
{
|
||||
"{0} tried to swim in lava",
|
||||
"{0} didn't know what the glowy orange liquid was",
|
||||
"{0} slipped in lava",
|
||||
"{0} became one with the glowing gooey rock"
|
||||
} },
|
||||
{ DeathType.BlackHole, new[]
|
||||
{
|
||||
"{0} should visit the Ash Twin Project again",
|
||||
"{0} waited inside the Ash Twin Project",
|
||||
"{0} chased their memories"
|
||||
} }
|
||||
};
|
||||
|
||||
public static string GetPhrase(DeathType deathType)
|
||||
{
|
||||
return DeathDictionary[deathType].OrderBy(x => Guid.NewGuid()).First();
|
||||
}
|
||||
public static string GetPhrase(DeathType deathType)
|
||||
{
|
||||
return DeathDictionary[deathType].OrderBy(x => Guid.NewGuid()).First();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,38 +6,38 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.DeathSync
|
||||
{
|
||||
public class PreventShipDestruction : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
|
||||
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
|
||||
public class PreventShipDestruction : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
|
||||
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
|
||||
|
||||
QSB.Helper.HarmonyHelper.EmptyMethod<ShipEjectionSystem>("OnPressInteract");
|
||||
QSB.Helper.HarmonyHelper.EmptyMethod<ShipEjectionSystem>("OnPressInteract");
|
||||
|
||||
QSB.Helper.Events.Subscribe<ShipDamageController>(OWML.Common.Events.AfterAwake);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
QSB.Helper.Events.Subscribe<ShipDamageController>(OWML.Common.Events.AfterAwake);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
|
||||
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is ShipDamageController shipDamageController &&
|
||||
ev == OWML.Common.Events.AfterAwake)
|
||||
{
|
||||
shipDamageController.SetValue("_exploded", true);
|
||||
}
|
||||
}
|
||||
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is ShipDamageController shipDamageController &&
|
||||
ev == OWML.Common.Events.AfterAwake)
|
||||
{
|
||||
shipDamageController.SetValue("_exploded", true);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Patch
|
||||
{
|
||||
public static IEnumerable<CodeInstruction> ReturnNull(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
return new List<CodeInstruction>
|
||||
{
|
||||
new CodeInstruction(OpCodes.Ldnull),
|
||||
new CodeInstruction(OpCodes.Ret)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
private static class Patch
|
||||
{
|
||||
public static IEnumerable<CodeInstruction> ReturnNull(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
return new List<CodeInstruction>
|
||||
{
|
||||
new CodeInstruction(OpCodes.Ldnull),
|
||||
new CodeInstruction(OpCodes.Ret)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,133 +7,133 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.DeathSync
|
||||
{
|
||||
/// <summary>
|
||||
/// Client-only-side component for managing respawning after death.
|
||||
/// </summary>
|
||||
public class RespawnOnDeath : MonoBehaviour
|
||||
{
|
||||
public static RespawnOnDeath Instance;
|
||||
/// <summary>
|
||||
/// Client-only-side component for managing respawning after death.
|
||||
/// </summary>
|
||||
public class RespawnOnDeath : MonoBehaviour
|
||||
{
|
||||
public static RespawnOnDeath Instance;
|
||||
|
||||
public readonly DeathType[] AllowedDeathTypes = {
|
||||
DeathType.BigBang,
|
||||
DeathType.Supernova,
|
||||
DeathType.TimeLoop
|
||||
};
|
||||
public readonly DeathType[] AllowedDeathTypes = {
|
||||
DeathType.BigBang,
|
||||
DeathType.Supernova,
|
||||
DeathType.TimeLoop
|
||||
};
|
||||
|
||||
private SpawnPoint _shipSpawnPoint;
|
||||
private SpawnPoint _playerSpawnPoint;
|
||||
private OWRigidbody _shipBody;
|
||||
private PlayerSpawner _playerSpawner;
|
||||
private FluidDetector _fluidDetector;
|
||||
private PlayerResources _playerResources;
|
||||
private ShipComponent[] _shipComponents;
|
||||
private HatchController _hatchController;
|
||||
private ShipCockpitController _cockpitController;
|
||||
private PlayerSpacesuit _spaceSuit;
|
||||
private SpawnPoint _shipSpawnPoint;
|
||||
private SpawnPoint _playerSpawnPoint;
|
||||
private OWRigidbody _shipBody;
|
||||
private PlayerSpawner _playerSpawner;
|
||||
private FluidDetector _fluidDetector;
|
||||
private PlayerResources _playerResources;
|
||||
private ShipComponent[] _shipComponents;
|
||||
private HatchController _hatchController;
|
||||
private ShipCockpitController _cockpitController;
|
||||
private PlayerSpacesuit _spaceSuit;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
QSB.Helper.Events.Subscribe<PlayerResources>(OWML.Common.Events.AfterStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
QSB.Helper.Events.Subscribe<PlayerResources>(OWML.Common.Events.AfterStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
|
||||
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerResources && ev == OWML.Common.Events.AfterStart)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
}
|
||||
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerResources && ev == OWML.Common.Events.AfterStart)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var playerTransform = Locator.GetPlayerTransform();
|
||||
_playerResources = playerTransform.GetComponent<PlayerResources>();
|
||||
_spaceSuit = playerTransform.GetComponentInChildren<PlayerSpacesuit>(true);
|
||||
_playerSpawner = FindObjectOfType<PlayerSpawner>();
|
||||
_fluidDetector = Locator.GetPlayerCamera().GetComponentInChildren<FluidDetector>();
|
||||
public void Init()
|
||||
{
|
||||
var playerTransform = Locator.GetPlayerTransform();
|
||||
_playerResources = playerTransform.GetComponent<PlayerResources>();
|
||||
_spaceSuit = playerTransform.GetComponentInChildren<PlayerSpacesuit>(true);
|
||||
_playerSpawner = FindObjectOfType<PlayerSpawner>();
|
||||
_fluidDetector = Locator.GetPlayerCamera().GetComponentInChildren<FluidDetector>();
|
||||
|
||||
var shipTransform = Locator.GetShipTransform();
|
||||
if (shipTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_shipComponents = shipTransform.GetComponentsInChildren<ShipComponent>();
|
||||
_hatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
_cockpitController = shipTransform.GetComponentInChildren<ShipCockpitController>();
|
||||
_shipBody = Locator.GetShipBody();
|
||||
_shipSpawnPoint = GetSpawnPoint(true);
|
||||
var shipTransform = Locator.GetShipTransform();
|
||||
if (shipTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_shipComponents = shipTransform.GetComponentsInChildren<ShipComponent>();
|
||||
_hatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
_cockpitController = shipTransform.GetComponentInChildren<ShipCockpitController>();
|
||||
_shipBody = Locator.GetShipBody();
|
||||
_shipSpawnPoint = GetSpawnPoint(true);
|
||||
|
||||
// Move debug spawn point to initial ship position.
|
||||
_playerSpawnPoint = GetSpawnPoint();
|
||||
_shipSpawnPoint.transform.position = shipTransform.position;
|
||||
_shipSpawnPoint.transform.rotation = shipTransform.rotation;
|
||||
}
|
||||
// Move debug spawn point to initial ship position.
|
||||
_playerSpawnPoint = GetSpawnPoint();
|
||||
_shipSpawnPoint.transform.position = shipTransform.position;
|
||||
_shipSpawnPoint.transform.rotation = shipTransform.rotation;
|
||||
}
|
||||
|
||||
public void ResetShip()
|
||||
{
|
||||
if (_shipBody == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void ResetShip()
|
||||
{
|
||||
if (_shipBody == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset ship position.
|
||||
if (_shipSpawnPoint == null)
|
||||
{
|
||||
DebugLog.ToConsole("_shipSpawnPoint is null!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
_shipBody.SetVelocity(_shipSpawnPoint.GetPointVelocity());
|
||||
_shipBody.WarpToPositionRotation(_shipSpawnPoint.transform.position, _shipSpawnPoint.transform.rotation);
|
||||
// Reset ship position.
|
||||
if (_shipSpawnPoint == null)
|
||||
{
|
||||
DebugLog.ToConsole("_shipSpawnPoint is null!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
_shipBody.SetVelocity(_shipSpawnPoint.GetPointVelocity());
|
||||
_shipBody.WarpToPositionRotation(_shipSpawnPoint.transform.position, _shipSpawnPoint.transform.rotation);
|
||||
|
||||
// Reset ship damage.
|
||||
if (Locator.GetShipTransform())
|
||||
{
|
||||
foreach (var shipComponent in _shipComponents)
|
||||
{
|
||||
shipComponent.SetDamaged(false);
|
||||
}
|
||||
}
|
||||
// Reset ship damage.
|
||||
if (Locator.GetShipTransform())
|
||||
{
|
||||
foreach (var shipComponent in _shipComponents)
|
||||
{
|
||||
shipComponent.SetDamaged(false);
|
||||
}
|
||||
}
|
||||
|
||||
Invoke(nameof(ExitShip), 0.01f);
|
||||
}
|
||||
Invoke(nameof(ExitShip), 0.01f);
|
||||
}
|
||||
|
||||
private void ExitShip()
|
||||
{
|
||||
_cockpitController.Invoke("ExitFlightConsole");
|
||||
_cockpitController.Invoke("CompleteExitFlightConsole");
|
||||
_hatchController.SetValue("_isPlayerInShip", false);
|
||||
_hatchController.Invoke("OpenHatch");
|
||||
GlobalMessenger.FireEvent(EventNames.ExitShip);
|
||||
}
|
||||
private void ExitShip()
|
||||
{
|
||||
_cockpitController.Invoke("ExitFlightConsole");
|
||||
_cockpitController.Invoke("CompleteExitFlightConsole");
|
||||
_hatchController.SetValue("_isPlayerInShip", false);
|
||||
_hatchController.Invoke("OpenHatch");
|
||||
GlobalMessenger.FireEvent(EventNames.ExitShip);
|
||||
}
|
||||
|
||||
public void ResetPlayer()
|
||||
{
|
||||
// Reset player position.
|
||||
var playerBody = Locator.GetPlayerBody();
|
||||
playerBody.WarpToPositionRotation(_playerSpawnPoint.transform.position, _playerSpawnPoint.transform.rotation);
|
||||
playerBody.SetVelocity(_playerSpawnPoint.GetPointVelocity());
|
||||
_playerSpawnPoint.AddObjectToTriggerVolumes(Locator.GetPlayerDetector().gameObject);
|
||||
_playerSpawnPoint.AddObjectToTriggerVolumes(_fluidDetector.gameObject);
|
||||
_playerSpawnPoint.OnSpawnPlayer();
|
||||
public void ResetPlayer()
|
||||
{
|
||||
// Reset player position.
|
||||
var playerBody = Locator.GetPlayerBody();
|
||||
playerBody.WarpToPositionRotation(_playerSpawnPoint.transform.position, _playerSpawnPoint.transform.rotation);
|
||||
playerBody.SetVelocity(_playerSpawnPoint.GetPointVelocity());
|
||||
_playerSpawnPoint.AddObjectToTriggerVolumes(Locator.GetPlayerDetector().gameObject);
|
||||
_playerSpawnPoint.AddObjectToTriggerVolumes(_fluidDetector.gameObject);
|
||||
_playerSpawnPoint.OnSpawnPlayer();
|
||||
|
||||
// Stop suffocation sound effect.
|
||||
_playerResources.SetValue("_isSuffocating", false);
|
||||
// Stop suffocation sound effect.
|
||||
_playerResources.SetValue("_isSuffocating", false);
|
||||
|
||||
// Reset player health and resources.
|
||||
_playerResources.DebugRefillResources();
|
||||
// Reset player health and resources.
|
||||
_playerResources.DebugRefillResources();
|
||||
|
||||
// Remove space suit.
|
||||
_spaceSuit.RemoveSuit(true);
|
||||
}
|
||||
// Remove space suit.
|
||||
_spaceSuit.RemoveSuit(true);
|
||||
}
|
||||
|
||||
private SpawnPoint GetSpawnPoint(bool isShip = false)
|
||||
{
|
||||
return _playerSpawner
|
||||
.GetValue<SpawnPoint[]>("_spawnList")
|
||||
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
|
||||
}
|
||||
}
|
||||
private SpawnPoint GetSpawnPoint(bool isShip = false)
|
||||
{
|
||||
return _playerSpawner
|
||||
.GetValue<SpawnPoint[]>("_spawnList")
|
||||
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,34 +5,34 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ElevatorSync
|
||||
{
|
||||
public class ElevatorManager : MonoBehaviour
|
||||
{
|
||||
public static ElevatorManager Instance { get; private set; }
|
||||
public class ElevatorManager : MonoBehaviour
|
||||
{
|
||||
public static ElevatorManager Instance { get; private set; }
|
||||
|
||||
private List<Elevator> _elevators;
|
||||
private List<Elevator> _elevators;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
|
||||
for (var id = 0; id < _elevators.Count; id++)
|
||||
{
|
||||
var qsbElevator = WorldRegistry.GetObject<QSBElevator>(id) ?? new QSBElevator();
|
||||
qsbElevator.Init(_elevators[id], id);
|
||||
WorldRegistry.AddObject(qsbElevator);
|
||||
}
|
||||
}
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
|
||||
for (var id = 0; id < _elevators.Count; id++)
|
||||
{
|
||||
var qsbElevator = WorldRegistry.GetObject<QSBElevator>(id) ?? new QSBElevator();
|
||||
qsbElevator.Init(_elevators[id], id);
|
||||
WorldRegistry.AddObject(qsbElevator);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetId(Elevator elevator) => _elevators.IndexOf(elevator);
|
||||
}
|
||||
public int GetId(Elevator elevator) => _elevators.IndexOf(elevator);
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,20 @@ using QSB.EventsCore;
|
||||
|
||||
namespace QSB.ElevatorSync
|
||||
{
|
||||
public class ElevatorPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
||||
public class ElevatorPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
||||
|
||||
public static void StartLift(Elevator __instance)
|
||||
{
|
||||
var isGoingUp = __instance.GetValue<bool>("_goingToTheEnd");
|
||||
var id = ElevatorManager.Instance.GetId(__instance);
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBStartLift, id, isGoingUp);
|
||||
}
|
||||
public static void StartLift(Elevator __instance)
|
||||
{
|
||||
var isGoingUp = __instance.GetValue<bool>("_goingToTheEnd");
|
||||
var id = ElevatorManager.Instance.GetId(__instance);
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBStartLift, id, isGoingUp);
|
||||
}
|
||||
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<Elevator>("StartLift", typeof(ElevatorPatches), nameof(StartLift));
|
||||
}
|
||||
}
|
||||
public override void DoPatches()
|
||||
{
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<Elevator>("StartLift", typeof(ElevatorPatches), nameof(StartLift));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,26 +4,26 @@ using QSB.WorldSync.Events;
|
||||
|
||||
namespace QSB.ElevatorSync.Events
|
||||
{
|
||||
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Elevator;
|
||||
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Elevator;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
|
||||
|
||||
private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp));
|
||||
private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new BoolWorldObjectMessage
|
||||
{
|
||||
State = isGoingUp,
|
||||
ObjectId = id
|
||||
};
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new BoolWorldObjectMessage
|
||||
{
|
||||
State = isGoingUp,
|
||||
ObjectId = id
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var elevator = WorldRegistry.GetObject<QSBElevator>(message.ObjectId);
|
||||
elevator?.RemoteCall(message.State);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var elevator = WorldRegistry.GetObject<QSBElevator>(message.ObjectId);
|
||||
elevator?.RemoteCall(message.State);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,54 +4,54 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ElevatorSync
|
||||
{
|
||||
public class QSBElevator : WorldObject
|
||||
{
|
||||
private Elevator _elevator;
|
||||
private Vector3 _startLocalPos;
|
||||
private Vector3 _endLocalPos;
|
||||
public class QSBElevator : WorldObject
|
||||
{
|
||||
private Elevator _elevator;
|
||||
private Vector3 _startLocalPos;
|
||||
private Vector3 _endLocalPos;
|
||||
|
||||
private SingleInteractionVolume _interactVolume;
|
||||
private OWAudioSource _owAudioSourceOneShot;
|
||||
private OWAudioSource _owAudioSourceLP;
|
||||
private SingleInteractionVolume _interactVolume;
|
||||
private OWAudioSource _owAudioSourceOneShot;
|
||||
private OWAudioSource _owAudioSourceLP;
|
||||
|
||||
public void Init(Elevator elevator, int id)
|
||||
{
|
||||
_elevator = elevator;
|
||||
ObjectId = id;
|
||||
QSB.Helper.Events.Unity.RunWhen(() => _elevator.GetValue<SingleInteractionVolume>("_interactVolume") != null, InitValues);
|
||||
}
|
||||
public void Init(Elevator elevator, int id)
|
||||
{
|
||||
_elevator = elevator;
|
||||
ObjectId = id;
|
||||
QSB.Helper.Events.Unity.RunWhen(() => _elevator.GetValue<SingleInteractionVolume>("_interactVolume") != null, InitValues);
|
||||
}
|
||||
|
||||
private void InitValues()
|
||||
{
|
||||
_startLocalPos = _elevator.GetValue<Vector3>("_startLocalPos");
|
||||
_endLocalPos = _elevator.GetValue<Vector3>("_endLocalPos");
|
||||
_interactVolume = _elevator.GetValue<SingleInteractionVolume>("_interactVolume");
|
||||
_owAudioSourceOneShot = _elevator.GetValue<OWAudioSource>("_owAudioSourceOneShot");
|
||||
_owAudioSourceLP = _elevator.GetValue<OWAudioSource>("_owAudioSourceLP");
|
||||
}
|
||||
private void InitValues()
|
||||
{
|
||||
_startLocalPos = _elevator.GetValue<Vector3>("_startLocalPos");
|
||||
_endLocalPos = _elevator.GetValue<Vector3>("_endLocalPos");
|
||||
_interactVolume = _elevator.GetValue<SingleInteractionVolume>("_interactVolume");
|
||||
_owAudioSourceOneShot = _elevator.GetValue<OWAudioSource>("_owAudioSourceOneShot");
|
||||
_owAudioSourceLP = _elevator.GetValue<OWAudioSource>("_owAudioSourceLP");
|
||||
}
|
||||
|
||||
public void RemoteCall(bool isGoingUp)
|
||||
{
|
||||
SetDirection(isGoingUp);
|
||||
RemoteStartLift();
|
||||
}
|
||||
public void RemoteCall(bool isGoingUp)
|
||||
{
|
||||
SetDirection(isGoingUp);
|
||||
RemoteStartLift();
|
||||
}
|
||||
|
||||
private void SetDirection(bool isGoingUp)
|
||||
{
|
||||
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
|
||||
_elevator.SetValue("_goingToTheEnd", isGoingUp);
|
||||
_elevator.SetValue("_targetLocalPos", targetPos);
|
||||
_interactVolume.transform.Rotate(0f, 180f, 0f);
|
||||
}
|
||||
private void SetDirection(bool isGoingUp)
|
||||
{
|
||||
var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;
|
||||
_elevator.SetValue("_goingToTheEnd", isGoingUp);
|
||||
_elevator.SetValue("_targetLocalPos", targetPos);
|
||||
_interactVolume.transform.Rotate(0f, 180f, 0f);
|
||||
}
|
||||
|
||||
private void RemoteStartLift()
|
||||
{
|
||||
_elevator.enabled = true;
|
||||
_elevator.SetValue("_initLocalPos", _elevator.transform.localPosition);
|
||||
_elevator.SetValue("_initLiftTime", Time.time);
|
||||
_owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate);
|
||||
_owAudioSourceLP.FadeIn(0.5f);
|
||||
_interactVolume.DisableInteraction();
|
||||
}
|
||||
}
|
||||
private void RemoteStartLift()
|
||||
{
|
||||
_elevator.enabled = true;
|
||||
_elevator.SetValue("_initLocalPos", _elevator.transform.localPosition);
|
||||
_elevator.SetValue("_initLiftTime", Time.time);
|
||||
_owAudioSourceOneShot.PlayOneShot(AudioType.TH_LiftActivate);
|
||||
_owAudioSourceLP.FadeIn(0.5f);
|
||||
_interactVolume.DisableInteraction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
namespace QSB.EventsCore
|
||||
{
|
||||
public static class EventNames
|
||||
{
|
||||
public static string TurnOnFlashlight = "TurnOnFlashlight";
|
||||
public static string TurnOffFlashlight = "TurnOffFlashlight";
|
||||
public static string LaunchProbe = "LaunchProbe";
|
||||
public static string RetrieveProbe = "RetrieveProbe";
|
||||
public static string ProbeLauncherEquipped = "ProbeLauncherEquipped";
|
||||
public static string ProbeLauncherUnequipped = "ProbeLauncherUnequipped";
|
||||
public static string EquipSignalscope = "EquipSignalscope";
|
||||
public static string UnequipSignalscope = "UnequipSignalscope";
|
||||
public static string SuitUp = "SuitUp";
|
||||
public static string RemoveSuit = "RemoveSuit";
|
||||
public static string EquipTranslator = "EquipTranslator";
|
||||
public static string UnequipTranslator = "UnequipTranslator";
|
||||
public static string ExitShip = "ExitShip";
|
||||
public static string RestartTimeLoop = "RestartTimeLoop";
|
||||
public static string WakeUp = "WakeUp";
|
||||
public static class EventNames
|
||||
{
|
||||
public static string TurnOnFlashlight = "TurnOnFlashlight";
|
||||
public static string TurnOffFlashlight = "TurnOffFlashlight";
|
||||
public static string LaunchProbe = "LaunchProbe";
|
||||
public static string RetrieveProbe = "RetrieveProbe";
|
||||
public static string ProbeLauncherEquipped = "ProbeLauncherEquipped";
|
||||
public static string ProbeLauncherUnequipped = "ProbeLauncherUnequipped";
|
||||
public static string EquipSignalscope = "EquipSignalscope";
|
||||
public static string UnequipSignalscope = "UnequipSignalscope";
|
||||
public static string SuitUp = "SuitUp";
|
||||
public static string RemoveSuit = "RemoveSuit";
|
||||
public static string EquipTranslator = "EquipTranslator";
|
||||
public static string UnequipTranslator = "UnequipTranslator";
|
||||
public static string ExitShip = "ExitShip";
|
||||
public static string RestartTimeLoop = "RestartTimeLoop";
|
||||
public static string WakeUp = "WakeUp";
|
||||
|
||||
public static string QSBPlayerDeath = "QSBPlayerDeath";
|
||||
public static string QSBPlayerJoin = "QSBPlayerJoin";
|
||||
public static string QSBPlayerLeave = "QSBPlayerLeave";
|
||||
public static string QSBPlayerReady = "QSBPlayerReady";
|
||||
public static string QSBSectorChange = "QSBSectorChange";
|
||||
public static string QSBPlayerStatesRequest = "QSBPlayerStatesRequest";
|
||||
public static string QSBServerTime = "QSBServerTime";
|
||||
public static string QSBOnProbeAnchor = "QSBOnProbeAnchor";
|
||||
public static string QSBOnProbeWarp = "QSBOnProbeWarp";
|
||||
public static string QSBStartLift = "QSBStartLift";
|
||||
public static string QSBGeyserState = "QSBGeyserState";
|
||||
public static string QSBCrouch = "QSBAnimTrigger";
|
||||
public static string QSBOrbSlot = "QSBOrbSlot";
|
||||
public static string QSBOrbUser = "QSBOrbUser";
|
||||
public static string QSBConversation = "QSBConversation";
|
||||
public static string QSBConversationStartEnd = "QSBConversationStartEnd";
|
||||
public static string QSBChangeAnimType = "QSBPlayInstrument";
|
||||
public static string QSBServerSendPlayerStates = "QSBServerSendPlayerStates";
|
||||
}
|
||||
public static string QSBPlayerDeath = "QSBPlayerDeath";
|
||||
public static string QSBPlayerJoin = "QSBPlayerJoin";
|
||||
public static string QSBPlayerLeave = "QSBPlayerLeave";
|
||||
public static string QSBPlayerReady = "QSBPlayerReady";
|
||||
public static string QSBSectorChange = "QSBSectorChange";
|
||||
public static string QSBPlayerStatesRequest = "QSBPlayerStatesRequest";
|
||||
public static string QSBServerTime = "QSBServerTime";
|
||||
public static string QSBOnProbeAnchor = "QSBOnProbeAnchor";
|
||||
public static string QSBOnProbeWarp = "QSBOnProbeWarp";
|
||||
public static string QSBStartLift = "QSBStartLift";
|
||||
public static string QSBGeyserState = "QSBGeyserState";
|
||||
public static string QSBCrouch = "QSBAnimTrigger";
|
||||
public static string QSBOrbSlot = "QSBOrbSlot";
|
||||
public static string QSBOrbUser = "QSBOrbUser";
|
||||
public static string QSBConversation = "QSBConversation";
|
||||
public static string QSBConversationStartEnd = "QSBConversationStartEnd";
|
||||
public static string QSBChangeAnimType = "QSBPlayInstrument";
|
||||
public static string QSBServerSendPlayerStates = "QSBServerSendPlayerStates";
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
namespace QSB.EventsCore
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
Sector,
|
||||
ServerTime,
|
||||
AnimTrigger,
|
||||
PlayerState,
|
||||
PlayerStatesRequest,
|
||||
FlashlightActiveChange,
|
||||
SignalscopeActiveChange,
|
||||
TranslatorActiveChange,
|
||||
ProbeLauncherActiveChange,
|
||||
SuitActiveChange,
|
||||
PlayerJoin,
|
||||
PlayerLeave,
|
||||
PlayerDeath,
|
||||
PlayerSectorChange,
|
||||
PlayerReady,
|
||||
ProbeActiveChange,
|
||||
Elevator,
|
||||
Geyser,
|
||||
OrbSlot,
|
||||
OrbUser,
|
||||
Conversation,
|
||||
ConversationStartEnd,
|
||||
PlayInstrument
|
||||
}
|
||||
public enum EventType
|
||||
{
|
||||
Sector,
|
||||
ServerTime,
|
||||
AnimTrigger,
|
||||
PlayerState,
|
||||
PlayerStatesRequest,
|
||||
FlashlightActiveChange,
|
||||
SignalscopeActiveChange,
|
||||
TranslatorActiveChange,
|
||||
ProbeLauncherActiveChange,
|
||||
SuitActiveChange,
|
||||
PlayerJoin,
|
||||
PlayerLeave,
|
||||
PlayerDeath,
|
||||
PlayerSectorChange,
|
||||
PlayerReady,
|
||||
ProbeActiveChange,
|
||||
Elevator,
|
||||
Geyser,
|
||||
OrbSlot,
|
||||
OrbUser,
|
||||
Conversation,
|
||||
ConversationStartEnd,
|
||||
PlayInstrument
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace QSB.EventsCore
|
||||
{
|
||||
public interface IQSBEvent
|
||||
{
|
||||
void SetupListener();
|
||||
void CloseListener();
|
||||
}
|
||||
public interface IQSBEvent
|
||||
{
|
||||
void SetupListener();
|
||||
void CloseListener();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
using QSB.Player;
|
||||
using QSB.QuantumUNET;
|
||||
using QSB.TransformSync;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.EventsCore
|
||||
{
|
||||
|
@ -14,54 +14,54 @@ using System.Collections.Generic;
|
||||
|
||||
namespace QSB.EventsCore
|
||||
{
|
||||
public static class QSBEventManager
|
||||
{
|
||||
public static bool Ready { get; private set; }
|
||||
public static class QSBEventManager
|
||||
{
|
||||
public static bool Ready { get; private set; }
|
||||
|
||||
private static List<IQSBEvent> _eventList = new List<IQSBEvent>();
|
||||
private static List<IQSBEvent> _eventList = new List<IQSBEvent>();
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_eventList = new List<IQSBEvent>
|
||||
{
|
||||
new PlayerReadyEvent(),
|
||||
new PlayerJoinEvent(),
|
||||
new PlayerSuitEvent(),
|
||||
new PlayerFlashlightEvent(),
|
||||
new PlayerSignalscopeEvent(),
|
||||
new PlayerTranslatorEvent(),
|
||||
new PlayerProbeLauncherEvent(),
|
||||
new PlayerProbeEvent(),
|
||||
new PlayerSectorEvent(),
|
||||
new PlayerLeaveEvent(),
|
||||
new PlayerDeathEvent(),
|
||||
new PlayerStatesRequestEvent(),
|
||||
new ElevatorEvent(),
|
||||
new GeyserEvent(),
|
||||
new ServerTimeEvent(),
|
||||
new CrouchEvent(),
|
||||
new OrbSlotEvent(),
|
||||
new OrbUserEvent(),
|
||||
new ConversationEvent(),
|
||||
new ConversationStartEndEvent(),
|
||||
new ChangeAnimTypeEvent(),
|
||||
new ServerSendPlayerStatesEvent()
|
||||
};
|
||||
public static void Init()
|
||||
{
|
||||
_eventList = new List<IQSBEvent>
|
||||
{
|
||||
new PlayerReadyEvent(),
|
||||
new PlayerJoinEvent(),
|
||||
new PlayerSuitEvent(),
|
||||
new PlayerFlashlightEvent(),
|
||||
new PlayerSignalscopeEvent(),
|
||||
new PlayerTranslatorEvent(),
|
||||
new PlayerProbeLauncherEvent(),
|
||||
new PlayerProbeEvent(),
|
||||
new PlayerSectorEvent(),
|
||||
new PlayerLeaveEvent(),
|
||||
new PlayerDeathEvent(),
|
||||
new PlayerStatesRequestEvent(),
|
||||
new ElevatorEvent(),
|
||||
new GeyserEvent(),
|
||||
new ServerTimeEvent(),
|
||||
new CrouchEvent(),
|
||||
new OrbSlotEvent(),
|
||||
new OrbUserEvent(),
|
||||
new ConversationEvent(),
|
||||
new ConversationStartEndEvent(),
|
||||
new ChangeAnimTypeEvent(),
|
||||
new ServerSendPlayerStatesEvent()
|
||||
};
|
||||
|
||||
_eventList.ForEach(ev => ev.SetupListener());
|
||||
_eventList.ForEach(ev => ev.SetupListener());
|
||||
|
||||
Ready = true;
|
||||
Ready = true;
|
||||
|
||||
DebugLog.DebugWrite("Event Manager ready.", MessageType.Success);
|
||||
}
|
||||
DebugLog.DebugWrite("Event Manager ready.", MessageType.Success);
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
Ready = false;
|
||||
public static void Reset()
|
||||
{
|
||||
Ready = false;
|
||||
|
||||
_eventList.ForEach(ev => ev.CloseListener());
|
||||
_eventList.ForEach(ev => ev.CloseListener());
|
||||
|
||||
_eventList = new List<IQSBEvent>();
|
||||
}
|
||||
}
|
||||
_eventList = new List<IQSBEvent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,33 @@ using QSB.WorldSync.Events;
|
||||
|
||||
namespace QSB.GeyserSync.Events
|
||||
{
|
||||
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Geyser;
|
||||
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Geyser;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
|
||||
}
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
|
||||
}
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
|
||||
}
|
||||
|
||||
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
||||
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id,
|
||||
State = state
|
||||
};
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id,
|
||||
State = state
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
|
||||
geyser?.SetState(message.State);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
|
||||
geyser?.SetState(message.State);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,41 +4,41 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.GeyserSync
|
||||
{
|
||||
public class GeyserManager : MonoBehaviour
|
||||
{
|
||||
public static GeyserManager Instance { get; private set; }
|
||||
public class GeyserManager : MonoBehaviour
|
||||
{
|
||||
public static GeyserManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
QSBPatchManager.OnPatchType += OnPatchType;
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
QSBPatchManager.OnPatchType += OnPatchType;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
QSBPatchManager.OnPatchType -= OnPatchType;
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
QSBPatchManager.OnPatchType -= OnPatchType;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
var geyserControllers = Resources.FindObjectsOfTypeAll<GeyserController>();
|
||||
for (var id = 0; id < geyserControllers.Length; id++)
|
||||
{
|
||||
var qsbGeyser = WorldRegistry.GetObject<QSBGeyser>(id) ?? new QSBGeyser();
|
||||
qsbGeyser.Init(geyserControllers[id], id);
|
||||
WorldRegistry.AddObject(qsbGeyser);
|
||||
}
|
||||
}
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
var geyserControllers = Resources.FindObjectsOfTypeAll<GeyserController>();
|
||||
for (var id = 0; id < geyserControllers.Length; id++)
|
||||
{
|
||||
var qsbGeyser = WorldRegistry.GetObject<QSBGeyser>(id) ?? new QSBGeyser();
|
||||
qsbGeyser.Init(geyserControllers[id], id);
|
||||
WorldRegistry.AddObject(qsbGeyser);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPatchType(QSBPatchTypes type)
|
||||
{
|
||||
if (type != QSBPatchTypes.OnNonServerClientConnect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSB.Helper.HarmonyHelper.EmptyMethod<GeyserController>("Update");
|
||||
}
|
||||
}
|
||||
public void OnPatchType(QSBPatchTypes type)
|
||||
{
|
||||
if (type != QSBPatchTypes.OnNonServerClientConnect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSB.Helper.HarmonyHelper.EmptyMethod<GeyserController>("Update");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using QSB.EventsCore;
|
||||
using QSB.QuantumUNET;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.GeyserSync
|
||||
{
|
||||
|
@ -8,121 +8,121 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Instruments
|
||||
{
|
||||
public class InstrumentsManager : PlayerSyncObject
|
||||
{
|
||||
private Transform rootObj;
|
||||
private AnimationType _savedType;
|
||||
private GameObject ChertDrum;
|
||||
public class InstrumentsManager : PlayerSyncObject
|
||||
{
|
||||
private Transform rootObj;
|
||||
private AnimationType _savedType;
|
||||
private GameObject ChertDrum;
|
||||
|
||||
public void InitLocal(Transform root)
|
||||
{
|
||||
rootObj = root;
|
||||
gameObject.AddComponent<CameraManager>();
|
||||
public void InitLocal(Transform root)
|
||||
{
|
||||
rootObj = root;
|
||||
gameObject.AddComponent<CameraManager>();
|
||||
|
||||
QSBInputManager.ChertTaunt += () => StartInstrument(AnimationType.Chert);
|
||||
QSBInputManager.EskerTaunt += () => StartInstrument(AnimationType.Esker);
|
||||
QSBInputManager.FeldsparTaunt += () => StartInstrument(AnimationType.Feldspar);
|
||||
QSBInputManager.GabbroTaunt += () => StartInstrument(AnimationType.Gabbro);
|
||||
QSBInputManager.RiebeckTaunt += () => StartInstrument(AnimationType.Riebeck);
|
||||
QSBInputManager.ExitTaunt += () => ReturnToPlayer();
|
||||
QSBInputManager.ChertTaunt += () => StartInstrument(AnimationType.Chert);
|
||||
QSBInputManager.EskerTaunt += () => StartInstrument(AnimationType.Esker);
|
||||
QSBInputManager.FeldsparTaunt += () => StartInstrument(AnimationType.Feldspar);
|
||||
QSBInputManager.GabbroTaunt += () => StartInstrument(AnimationType.Gabbro);
|
||||
QSBInputManager.RiebeckTaunt += () => StartInstrument(AnimationType.Riebeck);
|
||||
QSBInputManager.ExitTaunt += () => ReturnToPlayer();
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
||||
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
}
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
}
|
||||
|
||||
public void InitRemote(Transform root)
|
||||
{
|
||||
rootObj = root;
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
||||
public void InitRemote(Transform root)
|
||||
{
|
||||
rootObj = root;
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
||||
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
}
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (!IsLocalPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DebugLog.DebugWrite($"OnDestroy {PlayerId}");
|
||||
QSBInputManager.ChertTaunt -= () => StartInstrument(AnimationType.Chert);
|
||||
QSBInputManager.EskerTaunt -= () => StartInstrument(AnimationType.Esker);
|
||||
QSBInputManager.FeldsparTaunt -= () => StartInstrument(AnimationType.Feldspar);
|
||||
QSBInputManager.GabbroTaunt -= () => StartInstrument(AnimationType.Gabbro);
|
||||
QSBInputManager.RiebeckTaunt -= () => StartInstrument(AnimationType.Riebeck);
|
||||
QSBInputManager.ExitTaunt -= () => ReturnToPlayer();
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (!IsLocalPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DebugLog.DebugWrite($"OnDestroy {PlayerId}");
|
||||
QSBInputManager.ChertTaunt -= () => StartInstrument(AnimationType.Chert);
|
||||
QSBInputManager.EskerTaunt -= () => StartInstrument(AnimationType.Esker);
|
||||
QSBInputManager.FeldsparTaunt -= () => StartInstrument(AnimationType.Feldspar);
|
||||
QSBInputManager.GabbroTaunt -= () => StartInstrument(AnimationType.Gabbro);
|
||||
QSBInputManager.RiebeckTaunt -= () => StartInstrument(AnimationType.Riebeck);
|
||||
QSBInputManager.ExitTaunt -= () => ReturnToPlayer();
|
||||
}
|
||||
|
||||
private void SetupInstruments()
|
||||
{
|
||||
var bundle = QSB.InstrumentAssetBundle;
|
||||
ChertDrum = MakeChertDrum(bundle);
|
||||
}
|
||||
private void SetupInstruments()
|
||||
{
|
||||
var bundle = QSB.InstrumentAssetBundle;
|
||||
ChertDrum = MakeChertDrum(bundle);
|
||||
}
|
||||
|
||||
// EyeCompatibility : Need to find right object.
|
||||
private GameObject MakeChertDrum(AssetBundle bundle)
|
||||
{
|
||||
var drum = new GameObject();
|
||||
var mf = drum.AddComponent<MeshFilter>();
|
||||
mf.sharedMesh = bundle.LoadAsset("assets/Chert/hourglasstwinsmeshescharacters2.asset") as Mesh;
|
||||
var mr = drum.AddComponent<MeshRenderer>();
|
||||
mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent<MeshRenderer>().material;
|
||||
drum.transform.parent = rootObj;
|
||||
drum.transform.rotation = rootObj.rotation;
|
||||
drum.transform.localPosition = Vector3.zero;
|
||||
drum.transform.localScale = new Vector3(16.0f, 16.5f, 16.0f);
|
||||
drum.SetActive(false);
|
||||
// EyeCompatibility : Need to find right object.
|
||||
private GameObject MakeChertDrum(AssetBundle bundle)
|
||||
{
|
||||
var drum = new GameObject();
|
||||
var mf = drum.AddComponent<MeshFilter>();
|
||||
mf.sharedMesh = bundle.LoadAsset("assets/Chert/hourglasstwinsmeshescharacters2.asset") as Mesh;
|
||||
var mr = drum.AddComponent<MeshRenderer>();
|
||||
mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent<MeshRenderer>().material;
|
||||
drum.transform.parent = rootObj;
|
||||
drum.transform.rotation = rootObj.rotation;
|
||||
drum.transform.localPosition = Vector3.zero;
|
||||
drum.transform.localScale = new Vector3(16.0f, 16.5f, 16.0f);
|
||||
drum.SetActive(false);
|
||||
|
||||
return drum;
|
||||
}
|
||||
return drum;
|
||||
}
|
||||
|
||||
public void StartInstrument(AnimationType type)
|
||||
{
|
||||
if (!IsLocalPlayer)
|
||||
{
|
||||
DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (Player.PlayingInstrument || !Locator.GetPlayerController().IsGrounded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_savedType = Player.AnimationSync.CurrentType;
|
||||
CameraManager.Instance.SwitchTo3rdPerson();
|
||||
SwitchToType(type);
|
||||
}
|
||||
public void StartInstrument(AnimationType type)
|
||||
{
|
||||
if (!IsLocalPlayer)
|
||||
{
|
||||
DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
if (Player.PlayingInstrument || !Locator.GetPlayerController().IsGrounded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_savedType = Player.AnimationSync.CurrentType;
|
||||
CameraManager.Instance.SwitchTo3rdPerson();
|
||||
SwitchToType(type);
|
||||
}
|
||||
|
||||
public void ReturnToPlayer()
|
||||
{
|
||||
if (!Player.PlayingInstrument)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CameraManager.Instance.SwitchTo1stPerson();
|
||||
SwitchToType(_savedType);
|
||||
}
|
||||
public void ReturnToPlayer()
|
||||
{
|
||||
if (!Player.PlayingInstrument)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CameraManager.Instance.SwitchTo1stPerson();
|
||||
SwitchToType(_savedType);
|
||||
}
|
||||
|
||||
public void SwitchToType(AnimationType type)
|
||||
{
|
||||
DebugLog.DebugWrite($"switch to type {type} player {PlayerId}");
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type);
|
||||
QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type);
|
||||
CheckInstrumentProps(type);
|
||||
}
|
||||
public void SwitchToType(AnimationType type)
|
||||
{
|
||||
DebugLog.DebugWrite($"switch to type {type} player {PlayerId}");
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type);
|
||||
QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type);
|
||||
CheckInstrumentProps(type);
|
||||
}
|
||||
|
||||
public void CheckInstrumentProps(AnimationType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AnimationType.Chert:
|
||||
ChertDrum.SetActive(true);
|
||||
break;
|
||||
case AnimationType.PlayerSuited:
|
||||
case AnimationType.PlayerUnsuited:
|
||||
ChertDrum.SetActive(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void CheckInstrumentProps(AnimationType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AnimationType.Chert:
|
||||
ChertDrum.SetActive(true);
|
||||
break;
|
||||
case AnimationType.PlayerSuited:
|
||||
case AnimationType.PlayerUnsuited:
|
||||
ChertDrum.SetActive(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,78 +2,78 @@
|
||||
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
class CameraController : MonoBehaviour
|
||||
{
|
||||
private float _degreesX;
|
||||
private float _degreesY;
|
||||
private Quaternion _rotationX;
|
||||
private Quaternion _rotationY;
|
||||
class CameraController : MonoBehaviour
|
||||
{
|
||||
private float _degreesX;
|
||||
private float _degreesY;
|
||||
private Quaternion _rotationX;
|
||||
private Quaternion _rotationY;
|
||||
|
||||
// How far along the ray to move the camera. Avoids clipping into the walls.
|
||||
private const float PercentToMove = 0.80f;
|
||||
// Maximum distance for camera clipping
|
||||
private const float RayLength = 5f;
|
||||
// How far along the ray to move the camera. Avoids clipping into the walls.
|
||||
private const float PercentToMove = 0.80f;
|
||||
// Maximum distance for camera clipping
|
||||
private const float RayLength = 5f;
|
||||
|
||||
public GameObject CameraObject;
|
||||
public GameObject CameraObject;
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (CameraManager.Instance.Mode != CameraMode.ThirdPerson)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdatePosition();
|
||||
UpdateInput();
|
||||
UpdateRotation();
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (CameraManager.Instance.Mode != CameraMode.ThirdPerson)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdatePosition();
|
||||
UpdateInput();
|
||||
UpdateRotation();
|
||||
}
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var origin = transform.position;
|
||||
var localDirection = CameraObject.transform.localPosition.normalized;
|
||||
Vector3 localTargetPoint;
|
||||
if (Physics.Raycast(origin, transform.TransformDirection(localDirection), out var outRay, RayLength, LayerMask.GetMask("Default")))
|
||||
{
|
||||
// Raycast hit collider, get target from hitpoint.
|
||||
localTargetPoint = transform.InverseTransformPoint(outRay.point) * PercentToMove;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Raycast didn't hit collider, get target from camera direction
|
||||
localTargetPoint = localDirection * RayLength * PercentToMove;
|
||||
}
|
||||
var targetDistance = Vector3.Distance(origin, transform.TransformPoint(localTargetPoint));
|
||||
var currentDistance = Vector3.Distance(origin, CameraObject.transform.position);
|
||||
Vector3 movement;
|
||||
if (targetDistance < currentDistance)
|
||||
{
|
||||
// Snap to target to avoid clipping
|
||||
movement = localTargetPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move camera out slowly
|
||||
movement = Vector3.MoveTowards(CameraObject.transform.localPosition, localTargetPoint, Time.fixedDeltaTime * 2f);
|
||||
}
|
||||
CameraObject.transform.localPosition = movement;
|
||||
}
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var origin = transform.position;
|
||||
var localDirection = CameraObject.transform.localPosition.normalized;
|
||||
Vector3 localTargetPoint;
|
||||
if (Physics.Raycast(origin, transform.TransformDirection(localDirection), out var outRay, RayLength, LayerMask.GetMask("Default")))
|
||||
{
|
||||
// Raycast hit collider, get target from hitpoint.
|
||||
localTargetPoint = transform.InverseTransformPoint(outRay.point) * PercentToMove;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Raycast didn't hit collider, get target from camera direction
|
||||
localTargetPoint = localDirection * RayLength * PercentToMove;
|
||||
}
|
||||
var targetDistance = Vector3.Distance(origin, transform.TransformPoint(localTargetPoint));
|
||||
var currentDistance = Vector3.Distance(origin, CameraObject.transform.position);
|
||||
Vector3 movement;
|
||||
if (targetDistance < currentDistance)
|
||||
{
|
||||
// Snap to target to avoid clipping
|
||||
movement = localTargetPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move camera out slowly
|
||||
movement = Vector3.MoveTowards(CameraObject.transform.localPosition, localTargetPoint, Time.fixedDeltaTime * 2f);
|
||||
}
|
||||
CameraObject.transform.localPosition = movement;
|
||||
}
|
||||
|
||||
private void UpdateInput()
|
||||
{
|
||||
var input = OWInput.GetValue(InputLibrary.look, false, InputMode.All);
|
||||
_degreesX += input.x * 180f * Time.fixedDeltaTime;
|
||||
_degreesY += input.y * 180f * Time.fixedDeltaTime;
|
||||
}
|
||||
private void UpdateInput()
|
||||
{
|
||||
var input = OWInput.GetValue(InputLibrary.look, false, InputMode.All);
|
||||
_degreesX += input.x * 180f * Time.fixedDeltaTime;
|
||||
_degreesY += input.y * 180f * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
private void UpdateRotation()
|
||||
{
|
||||
_degreesX %= 360f;
|
||||
_degreesY %= 360f;
|
||||
_degreesY = Mathf.Clamp(_degreesY, -80f, 80f);
|
||||
_rotationX = Quaternion.AngleAxis(_degreesX, Vector3.up);
|
||||
_rotationY = Quaternion.AngleAxis(_degreesY, Vector3.left);
|
||||
var localRotation = _rotationX * _rotationY * Quaternion.identity;
|
||||
transform.localRotation = localRotation;
|
||||
}
|
||||
}
|
||||
private void UpdateRotation()
|
||||
{
|
||||
_degreesX %= 360f;
|
||||
_degreesY %= 360f;
|
||||
_degreesY = Mathf.Clamp(_degreesY, -80f, 80f);
|
||||
_rotationX = Quaternion.AngleAxis(_degreesX, Vector3.up);
|
||||
_rotationY = Quaternion.AngleAxis(_degreesY, Vector3.left);
|
||||
var localRotation = _rotationX * _rotationY * Quaternion.identity;
|
||||
transform.localRotation = localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,110 +5,110 @@ using UnityEngine.PostProcessing;
|
||||
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
public static CameraManager Instance;
|
||||
private GameObject CameraBase;
|
||||
private GameObject CameraObj;
|
||||
private Camera Camera;
|
||||
private OWCamera OWCamera;
|
||||
public bool IsSetUp { get; private set; }
|
||||
public CameraMode Mode { get; private set; }
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
public static CameraManager Instance;
|
||||
private GameObject CameraBase;
|
||||
private GameObject CameraObj;
|
||||
private Camera Camera;
|
||||
private OWCamera OWCamera;
|
||||
public bool IsSetUp { get; private set; }
|
||||
public CameraMode Mode { get; private set; }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Instance = this;
|
||||
SetupCamera();
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
Instance = this;
|
||||
SetupCamera();
|
||||
}
|
||||
|
||||
private void SetupCamera()
|
||||
{
|
||||
CameraBase = new GameObject();
|
||||
CameraBase.SetActive(false);
|
||||
CameraBase.AddComponent<Transform>();
|
||||
CameraBase.transform.parent = Locator.GetPlayerTransform();
|
||||
CameraBase.transform.localPosition = Vector3.zero;
|
||||
CameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
private void SetupCamera()
|
||||
{
|
||||
CameraBase = new GameObject();
|
||||
CameraBase.SetActive(false);
|
||||
CameraBase.AddComponent<Transform>();
|
||||
CameraBase.transform.parent = Locator.GetPlayerTransform();
|
||||
CameraBase.transform.localPosition = Vector3.zero;
|
||||
CameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
|
||||
CameraObj = new GameObject();
|
||||
CameraObj.transform.parent = CameraBase.transform;
|
||||
CameraObj.transform.localPosition = new Vector3(0, 0, -5f);
|
||||
CameraObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
Camera = CameraObj.AddComponent<Camera>();
|
||||
Camera.cullingMask = Locator.GetPlayerCamera().mainCamera.cullingMask & ~(1 << 27) | (1 << 22);
|
||||
Camera.clearFlags = CameraClearFlags.Color;
|
||||
Camera.backgroundColor = Color.black;
|
||||
Camera.fieldOfView = 90f;
|
||||
Camera.nearClipPlane = 0.1f;
|
||||
Camera.farClipPlane = 40000f;
|
||||
Camera.depth = 0f;
|
||||
Camera.enabled = false;
|
||||
OWCamera = CameraObj.AddComponent<OWCamera>();
|
||||
OWCamera.renderSkybox = true;
|
||||
CameraObj = new GameObject();
|
||||
CameraObj.transform.parent = CameraBase.transform;
|
||||
CameraObj.transform.localPosition = new Vector3(0, 0, -5f);
|
||||
CameraObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
Camera = CameraObj.AddComponent<Camera>();
|
||||
Camera.cullingMask = Locator.GetPlayerCamera().mainCamera.cullingMask & ~(1 << 27) | (1 << 22);
|
||||
Camera.clearFlags = CameraClearFlags.Color;
|
||||
Camera.backgroundColor = Color.black;
|
||||
Camera.fieldOfView = 90f;
|
||||
Camera.nearClipPlane = 0.1f;
|
||||
Camera.farClipPlane = 40000f;
|
||||
Camera.depth = 0f;
|
||||
Camera.enabled = false;
|
||||
OWCamera = CameraObj.AddComponent<OWCamera>();
|
||||
OWCamera.renderSkybox = true;
|
||||
|
||||
CameraBase.AddComponent<CameraController>().CameraObject = CameraObj;
|
||||
CameraBase.AddComponent<CameraController>().CameraObject = CameraObj;
|
||||
|
||||
var screenGrab = CameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
|
||||
screenGrab._downsampleShader = Locator.GetPlayerCamera().gameObject.GetComponent<FlashbackScreenGrabImageEffect>()._downsampleShader;
|
||||
var screenGrab = CameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
|
||||
screenGrab._downsampleShader = Locator.GetPlayerCamera().gameObject.GetComponent<FlashbackScreenGrabImageEffect>()._downsampleShader;
|
||||
|
||||
var fogImage = CameraObj.AddComponent<PlanetaryFogImageEffect>();
|
||||
fogImage.fogShader = Locator.GetPlayerCamera().gameObject.GetComponent<PlanetaryFogImageEffect>().fogShader;
|
||||
var fogImage = CameraObj.AddComponent<PlanetaryFogImageEffect>();
|
||||
fogImage.fogShader = Locator.GetPlayerCamera().gameObject.GetComponent<PlanetaryFogImageEffect>().fogShader;
|
||||
|
||||
CameraBase.SetActive(true);
|
||||
CameraBase.SetActive(true);
|
||||
|
||||
IsSetUp = true;
|
||||
}
|
||||
IsSetUp = true;
|
||||
}
|
||||
|
||||
public void SwitchTo3rdPerson()
|
||||
{
|
||||
if (!IsSetUp)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Camera not set up!", MessageType.Warning);
|
||||
OWInput.ChangeInputMode(InputMode.None);
|
||||
Mode = CameraMode.ThirdPerson;
|
||||
return;
|
||||
}
|
||||
if (Mode == CameraMode.ThirdPerson)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Already in 3rd person!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
if (OWInput.GetInputMode() != InputMode.Character)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Cannot change to 3rd person while not in Character inputmode!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
OWInput.ChangeInputMode(InputMode.None);
|
||||
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", OWCamera);
|
||||
Locator.GetPlayerCamera().mainCamera.enabled = false;
|
||||
if (CameraObj.GetComponent<PostProcessingBehaviour>() == null)
|
||||
{
|
||||
var postProcessing = CameraObj.AddComponent<PostProcessingBehaviour>();
|
||||
postProcessing.profile = Locator.GetPlayerCamera().gameObject.GetComponent<PostProcessingBehaviour>().profile;
|
||||
}
|
||||
Camera.enabled = true;
|
||||
Mode = CameraMode.ThirdPerson;
|
||||
}
|
||||
public void SwitchTo3rdPerson()
|
||||
{
|
||||
if (!IsSetUp)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Camera not set up!", MessageType.Warning);
|
||||
OWInput.ChangeInputMode(InputMode.None);
|
||||
Mode = CameraMode.ThirdPerson;
|
||||
return;
|
||||
}
|
||||
if (Mode == CameraMode.ThirdPerson)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Already in 3rd person!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
if (OWInput.GetInputMode() != InputMode.Character)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Cannot change to 3rd person while not in Character inputmode!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
OWInput.ChangeInputMode(InputMode.None);
|
||||
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", OWCamera);
|
||||
Locator.GetPlayerCamera().mainCamera.enabled = false;
|
||||
if (CameraObj.GetComponent<PostProcessingBehaviour>() == null)
|
||||
{
|
||||
var postProcessing = CameraObj.AddComponent<PostProcessingBehaviour>();
|
||||
postProcessing.profile = Locator.GetPlayerCamera().gameObject.GetComponent<PostProcessingBehaviour>().profile;
|
||||
}
|
||||
Camera.enabled = true;
|
||||
Mode = CameraMode.ThirdPerson;
|
||||
}
|
||||
|
||||
public void SwitchTo1stPerson()
|
||||
{
|
||||
if (!IsSetUp)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Camera not set up!", MessageType.Warning);
|
||||
OWInput.ChangeInputMode(InputMode.Character);
|
||||
Mode = CameraMode.FirstPerson;
|
||||
return;
|
||||
}
|
||||
if (Mode == CameraMode.FirstPerson)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Already in 1st person!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
OWInput.ChangeInputMode(InputMode.Character);
|
||||
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", Locator.GetPlayerCamera());
|
||||
Locator.GetActiveCamera().mainCamera.enabled = true;
|
||||
Camera.enabled = false;
|
||||
Mode = CameraMode.FirstPerson;
|
||||
}
|
||||
}
|
||||
public void SwitchTo1stPerson()
|
||||
{
|
||||
if (!IsSetUp)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Camera not set up!", MessageType.Warning);
|
||||
OWInput.ChangeInputMode(InputMode.Character);
|
||||
Mode = CameraMode.FirstPerson;
|
||||
return;
|
||||
}
|
||||
if (Mode == CameraMode.FirstPerson)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Already in 1st person!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
OWInput.ChangeInputMode(InputMode.Character);
|
||||
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", Locator.GetPlayerCamera());
|
||||
Locator.GetActiveCamera().mainCamera.enabled = true;
|
||||
Camera.enabled = false;
|
||||
Mode = CameraMode.FirstPerson;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
public enum CameraMode
|
||||
{
|
||||
FirstPerson,
|
||||
ThirdPerson
|
||||
}
|
||||
public enum CameraMode
|
||||
{
|
||||
FirstPerson,
|
||||
ThirdPerson
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,20 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.MessagesCore
|
||||
{
|
||||
public class EnumMessage<T> : PlayerMessage
|
||||
{
|
||||
public T Value;
|
||||
public class EnumMessage<T> : PlayerMessage
|
||||
{
|
||||
public T Value;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = (T)(object)reader.ReadInt32();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = (T)(object)reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)(object)Value);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)(object)Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,20 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.MessagesCore
|
||||
{
|
||||
public class FloatMessage : PlayerMessage
|
||||
{
|
||||
public float Value;
|
||||
public class FloatMessage : PlayerMessage
|
||||
{
|
||||
public float Value;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = reader.ReadSingle();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Value = reader.ReadSingle();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Value);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,21 +2,21 @@
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public class PlayerMessage : MessageBase
|
||||
{
|
||||
public uint FromId { get; set; }
|
||||
public uint AboutId { get; set; }
|
||||
public class PlayerMessage : MessageBase
|
||||
{
|
||||
public uint FromId { get; set; }
|
||||
public uint AboutId { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
FromId = reader.ReadUInt32();
|
||||
AboutId = reader.ReadUInt32();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
FromId = reader.ReadUInt32();
|
||||
AboutId = reader.ReadUInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(FromId);
|
||||
writer.Write(AboutId);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(FromId);
|
||||
writer.Write(AboutId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public class ToggleMessage : PlayerMessage
|
||||
{
|
||||
public bool ToggleValue { get; set; }
|
||||
public class ToggleMessage : PlayerMessage
|
||||
{
|
||||
public bool ToggleValue { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ToggleValue = reader.ReadBoolean();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ToggleValue = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ToggleValue);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ToggleValue);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
using OWML.Common;
|
||||
using QSB.EventsCore;
|
||||
using QSB.QuantumUNET;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync.Events;
|
||||
using System.Linq;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.OrbSync.Events
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
|
@ -3,36 +3,36 @@ using QSB.WorldSync;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class QSBOrbSlot : WorldObject
|
||||
{
|
||||
public NomaiInterfaceSlot InterfaceSlot { get; private set; }
|
||||
public class QSBOrbSlot : WorldObject
|
||||
{
|
||||
public NomaiInterfaceSlot InterfaceSlot { get; private set; }
|
||||
|
||||
private bool _initialized;
|
||||
private bool _initialized;
|
||||
|
||||
public void Init(NomaiInterfaceSlot slot, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
InterfaceSlot = slot;
|
||||
_initialized = true;
|
||||
WorldRegistry.AddObject(this);
|
||||
}
|
||||
public void Init(NomaiInterfaceSlot slot, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
InterfaceSlot = slot;
|
||||
_initialized = true;
|
||||
WorldRegistry.AddObject(this);
|
||||
}
|
||||
|
||||
public void HandleEvent(bool state)
|
||||
{
|
||||
if (QSB.HasWokenUp)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state);
|
||||
}
|
||||
}
|
||||
public void HandleEvent(bool state)
|
||||
{
|
||||
if (QSB.HasWokenUp)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(bool state)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var ev = state ? "OnSlotActivated" : "OnSlotDeactivated";
|
||||
WorldRegistry.RaiseEvent(InterfaceSlot, ev);
|
||||
}
|
||||
}
|
||||
public void SetState(bool state)
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var ev = state ? "OnSlotActivated" : "OnSlotDeactivated";
|
||||
WorldRegistry.RaiseEvent(InterfaceSlot, ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
namespace QSB
|
||||
{
|
||||
public abstract class QSBPatch
|
||||
{
|
||||
public abstract QSBPatchTypes Type { get; }
|
||||
public abstract class QSBPatch
|
||||
{
|
||||
public abstract QSBPatchTypes Type { get; }
|
||||
|
||||
public abstract void DoPatches();
|
||||
}
|
||||
public abstract void DoPatches();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
namespace QSB
|
||||
{
|
||||
public enum QSBPatchTypes
|
||||
{
|
||||
OnModStart,
|
||||
OnClientConnect,
|
||||
OnNonServerClientConnect
|
||||
}
|
||||
public enum QSBPatchTypes
|
||||
{
|
||||
OnModStart,
|
||||
OnClientConnect,
|
||||
OnNonServerClientConnect
|
||||
}
|
||||
}
|
||||
|
@ -4,36 +4,36 @@ using QSB.Utility;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerJoin;
|
||||
public class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerJoin;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<string>.AddListener(EventNames.QSBPlayerJoin, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<string>.AddListener(EventNames.QSBPlayerJoin, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<string>.RemoveListener(EventNames.QSBPlayerJoin, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<string>.RemoveListener(EventNames.QSBPlayerJoin, Handler);
|
||||
|
||||
private void Handler(string name) => SendEvent(CreateMessage(name));
|
||||
private void Handler(string name) => SendEvent(CreateMessage(name));
|
||||
|
||||
private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
PlayerName = name
|
||||
};
|
||||
private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
PlayerName = name
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(PlayerJoinMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player.Name = message.PlayerName;
|
||||
DebugLog.ToHud($"{player.Name} joined!");
|
||||
DebugLog.DebugWrite($"{player.Name} joined as id {player.PlayerId}", MessageType.Info);
|
||||
}
|
||||
public override void OnReceiveRemote(PlayerJoinMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player.Name = message.PlayerName;
|
||||
DebugLog.ToHud($"{player.Name} joined!");
|
||||
DebugLog.DebugWrite($"{player.Name} joined as id {player.PlayerId}", MessageType.Info);
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(PlayerJoinMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(QSBPlayerManager.LocalPlayerId);
|
||||
player.Name = message.PlayerName;
|
||||
var text = $"Connected to server as {player.Name}.";
|
||||
DebugLog.ToAll(text, MessageType.Info);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveLocal(PlayerJoinMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(QSBPlayerManager.LocalPlayerId);
|
||||
player.Name = message.PlayerName;
|
||||
var text = $"Connected to server as {player.Name}.";
|
||||
DebugLog.ToAll(text, MessageType.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,20 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerJoinMessage : PlayerMessage
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
public class PlayerJoinMessage : PlayerMessage
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,29 +5,29 @@ using System.Linq;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerLeaveEvent : QSBEvent<PlayerLeaveMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerLeave;
|
||||
public class PlayerLeaveEvent : QSBEvent<PlayerLeaveMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerLeave;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<uint, uint[]>.AddListener(EventNames.QSBPlayerLeave, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<uint, uint[]>.AddListener(EventNames.QSBPlayerLeave, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<uint, uint[]>.RemoveListener(EventNames.QSBPlayerLeave, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<uint, uint[]>.RemoveListener(EventNames.QSBPlayerLeave, Handler);
|
||||
|
||||
private void Handler(uint playerId, uint[] netIds) => SendEvent(CreateMessage(playerId, netIds));
|
||||
private void Handler(uint playerId, uint[] netIds) => SendEvent(CreateMessage(playerId, netIds));
|
||||
|
||||
private PlayerLeaveMessage CreateMessage(uint playerId, uint[] netIds) => new PlayerLeaveMessage
|
||||
{
|
||||
AboutId = playerId,
|
||||
NetIds = netIds
|
||||
};
|
||||
private PlayerLeaveMessage CreateMessage(uint playerId, uint[] netIds) => new PlayerLeaveMessage
|
||||
{
|
||||
AboutId = playerId,
|
||||
NetIds = netIds
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(PlayerLeaveMessage message)
|
||||
{
|
||||
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
|
||||
DebugLog.ToAll($"{playerName} disconnected.", MessageType.Info);
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).HudMarker?.Remove();
|
||||
QSBPlayerManager.RemovePlayer(message.AboutId);
|
||||
message.NetIds.ToList().ForEach(netId => QSBNetworkManager.Instance.CleanupNetworkBehaviour(netId));
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(PlayerLeaveMessage message)
|
||||
{
|
||||
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
|
||||
DebugLog.ToAll($"{playerName} disconnected.", MessageType.Info);
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).HudMarker?.Remove();
|
||||
QSBPlayerManager.RemovePlayer(message.AboutId);
|
||||
message.NetIds.ToList().ForEach(netId => QSBNetworkManager.Instance.CleanupNetworkBehaviour(netId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,20 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerLeaveMessage : PlayerMessage
|
||||
{
|
||||
public uint[] NetIds { get; set; }
|
||||
public class PlayerLeaveMessage : PlayerMessage
|
||||
{
|
||||
public uint[] NetIds { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
NetIds = reader.ReadString().Split(',').Select(x => Convert.ToUInt32(x)).ToArray();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
NetIds = reader.ReadString().Split(',').Select(x => Convert.ToUInt32(x)).ToArray();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(string.Join(",", NetIds.Select(x => x.ToString()).ToArray()));
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(string.Join(",", NetIds.Select(x => x.ToString()).ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
@ -7,46 +7,46 @@ using System.Linq;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerReadyEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerReady;
|
||||
public class PlayerReadyEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerReady;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<bool>.AddListener(EventNames.QSBPlayerReady, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<bool>.AddListener(EventNames.QSBPlayerReady, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<bool>.RemoveListener(EventNames.QSBPlayerReady, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<bool>.RemoveListener(EventNames.QSBPlayerReady, Handler);
|
||||
|
||||
private void Handler(bool ready) => SendEvent(CreateMessage(ready));
|
||||
private void Handler(bool ready) => SendEvent(CreateMessage(ready));
|
||||
|
||||
private ToggleMessage CreateMessage(bool ready) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = ready
|
||||
};
|
||||
private ToggleMessage CreateMessage(bool ready) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = ready
|
||||
};
|
||||
|
||||
public override void OnServerReceive(ToggleMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"[S] Get ready event from {message.FromId}", MessageType.Success);
|
||||
if (message.FromId == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue;
|
||||
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
|
||||
}
|
||||
public override void OnServerReceive(ToggleMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"[S] Get ready event from {message.FromId}", MessageType.Success);
|
||||
if (message.FromId == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue;
|
||||
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
|
||||
}
|
||||
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
|
||||
if (!QSBPlayerManager.PlayerExists(message.FromId))
|
||||
{
|
||||
DebugLog.ToConsole("Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
|
||||
if (!QSBPlayerManager.PlayerExists(message.FromId))
|
||||
{
|
||||
DebugLog.ToConsole("Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,47 +7,47 @@ using QSB.WorldSync.Events;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerSectorChange;
|
||||
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerSectorChange;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
|
||||
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
||||
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
||||
|
||||
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
||||
{
|
||||
AboutId = netId,
|
||||
ObjectId = sector.ObjectId
|
||||
};
|
||||
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
||||
{
|
||||
AboutId = netId,
|
||||
ObjectId = sector.ObjectId
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(WorldObjectMessage message)
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
||||
public override void OnReceiveRemote(WorldObjectMessage message)
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
||||
|
||||
if (sector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
if (sector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var transformSync = QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId);
|
||||
var transformSync = QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId);
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => transformSync?.SyncedTransform != null,
|
||||
() => transformSync?.SetReferenceSector(sector));
|
||||
}
|
||||
QSB.Helper.Events.Unity.RunWhen(() => transformSync?.SyncedTransform != null,
|
||||
() => transformSync?.SetReferenceSector(sector));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,32 +3,32 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerStateMessage : PlayerMessage
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
public bool PlayerReady { get; set; }
|
||||
public State PlayerState { get; set; }
|
||||
public Sector.Name SectorID { get; set; }
|
||||
public string SectorName { get; set; }
|
||||
public class PlayerStateMessage : PlayerMessage
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
public bool PlayerReady { get; set; }
|
||||
public State PlayerState { get; set; }
|
||||
public Sector.Name SectorID { get; set; }
|
||||
public string SectorName { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
PlayerReady = reader.ReadBoolean();
|
||||
PlayerState = (State)reader.ReadInt32();
|
||||
SectorID = (Sector.Name)reader.ReadInt32();
|
||||
SectorName = reader.ReadString();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerName = reader.ReadString();
|
||||
PlayerReady = reader.ReadBoolean();
|
||||
PlayerState = (State)reader.ReadInt32();
|
||||
SectorID = (Sector.Name)reader.ReadInt32();
|
||||
SectorName = reader.ReadString();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
writer.Write(PlayerReady);
|
||||
writer.Write((int)PlayerState);
|
||||
writer.Write((int)SectorID);
|
||||
writer.Write(SectorName);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerName);
|
||||
writer.Write(PlayerReady);
|
||||
writer.Write((int)PlayerState);
|
||||
writer.Write((int)SectorID);
|
||||
writer.Write(SectorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,30 @@ using System.Linq;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerStatesRequest;
|
||||
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerStatesRequest;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
|
||||
private void Handler() => SendEvent(CreateMessage());
|
||||
private void Handler() => SendEvent(CreateMessage());
|
||||
|
||||
private PlayerMessage CreateMessage() => new PlayerMessage
|
||||
{
|
||||
AboutId = LocalPlayerId
|
||||
};
|
||||
private PlayerMessage CreateMessage() => new PlayerMessage
|
||||
{
|
||||
AboutId = LocalPlayerId
|
||||
};
|
||||
|
||||
public override void OnServerReceive(PlayerMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"[S] Get state request from {message.FromId}");
|
||||
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
|
||||
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void OnServerReceive(PlayerMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"[S] Get state request from {message.FromId}");
|
||||
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
|
||||
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,37 +4,37 @@ using QSB.Utility;
|
||||
|
||||
namespace QSB.Player.Events
|
||||
{
|
||||
public class ServerSendPlayerStatesEvent : QSBEvent<PlayerStateMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerState;
|
||||
public class ServerSendPlayerStatesEvent : QSBEvent<PlayerStateMessage>
|
||||
{
|
||||
public override EventType Type => EventType.PlayerState;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBServerSendPlayerStates, Handler);
|
||||
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBServerSendPlayerStates, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBServerSendPlayerStates, Handler);
|
||||
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBServerSendPlayerStates, Handler);
|
||||
|
||||
private void Handler()
|
||||
{
|
||||
foreach (var player in QSBPlayerManager.PlayerList)
|
||||
{
|
||||
DebugLog.DebugWrite($" - Sending playerstate of player ID {player.PlayerId}", MessageType.Info);
|
||||
SendEvent(CreateMessage(player));
|
||||
}
|
||||
}
|
||||
private void Handler()
|
||||
{
|
||||
foreach (var player in QSBPlayerManager.PlayerList)
|
||||
{
|
||||
DebugLog.DebugWrite($" - Sending playerstate of player ID {player.PlayerId}", MessageType.Info);
|
||||
SendEvent(CreateMessage(player));
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerStateMessage CreateMessage(PlayerInfo player) => new PlayerStateMessage
|
||||
{
|
||||
AboutId = player.PlayerId,
|
||||
PlayerName = player.Name,
|
||||
PlayerReady = player.IsReady,
|
||||
PlayerState = player.State
|
||||
};
|
||||
private PlayerStateMessage CreateMessage(PlayerInfo player) => new PlayerStateMessage
|
||||
{
|
||||
AboutId = player.PlayerId,
|
||||
PlayerName = player.Name,
|
||||
PlayerReady = player.IsReady,
|
||||
PlayerState = player.State
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(PlayerStateMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info);
|
||||
QSB.Helper.Events.Unity.RunWhen(
|
||||
() => QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null,
|
||||
() => QSBPlayerManager.HandleFullStateMessage(message));
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(PlayerStateMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info);
|
||||
QSB.Helper.Events.Unity.RunWhen(
|
||||
() => QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null,
|
||||
() => QSBPlayerManager.HandleFullStateMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,58 +2,58 @@
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
public class PlayerHUDMarker : HUDDistanceMarker
|
||||
{
|
||||
private PlayerInfo _player;
|
||||
private bool _isReady;
|
||||
public class PlayerHUDMarker : HUDDistanceMarker
|
||||
{
|
||||
private PlayerInfo _player;
|
||||
private bool _isReady;
|
||||
|
||||
protected override void InitCanvasMarker()
|
||||
{
|
||||
_markerRadius = 2f;
|
||||
protected override void InitCanvasMarker()
|
||||
{
|
||||
_markerRadius = 2f;
|
||||
|
||||
_markerTarget = new GameObject().transform;
|
||||
_markerTarget.parent = transform;
|
||||
_markerTarget = new GameObject().transform;
|
||||
_markerTarget.parent = transform;
|
||||
|
||||
_markerTarget.localPosition = Vector3.up * 2;
|
||||
}
|
||||
_markerTarget.localPosition = Vector3.up * 2;
|
||||
}
|
||||
|
||||
public void Init(PlayerInfo player)
|
||||
{
|
||||
_player = player;
|
||||
_player.HudMarker = this;
|
||||
_isReady = true;
|
||||
}
|
||||
public void Init(PlayerInfo player)
|
||||
{
|
||||
_player = player;
|
||||
_player.HudMarker = this;
|
||||
_isReady = true;
|
||||
}
|
||||
|
||||
protected override void RefreshOwnVisibility()
|
||||
{
|
||||
if (_canvasMarker != null)
|
||||
{
|
||||
_canvasMarker.SetVisibility(true);
|
||||
}
|
||||
}
|
||||
protected override void RefreshOwnVisibility()
|
||||
{
|
||||
if (_canvasMarker != null)
|
||||
{
|
||||
_canvasMarker.SetVisibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isReady || !_player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_markerLabel = _player.Name.ToUpper();
|
||||
_isReady = false;
|
||||
private void Update()
|
||||
{
|
||||
if (!_isReady || !_player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_markerLabel = _player.Name.ToUpper();
|
||||
_isReady = false;
|
||||
|
||||
base.InitCanvasMarker();
|
||||
}
|
||||
base.InitCanvasMarker();
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
// do N O T destroy the parent - it completely breaks the ENTIRE GAME
|
||||
if (_canvasMarker?.gameObject != null)
|
||||
{
|
||||
_canvasMarker.DestroyMarker();
|
||||
}
|
||||
Destroy(_markerTarget.gameObject);
|
||||
Destroy(this);
|
||||
}
|
||||
public void Remove()
|
||||
{
|
||||
// do N O T destroy the parent - it completely breaks the ENTIRE GAME
|
||||
if (_canvasMarker?.gameObject != null)
|
||||
{
|
||||
_canvasMarker.DestroyMarker();
|
||||
}
|
||||
Destroy(_markerTarget.gameObject);
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,78 +6,78 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
public uint PlayerId { get; }
|
||||
public string Name { get; set; }
|
||||
public bool IsReady { get; set; }
|
||||
public PlayerHUDMarker HudMarker { get; set; }
|
||||
public State State { get; set; }
|
||||
public class PlayerInfo
|
||||
{
|
||||
public uint PlayerId { get; }
|
||||
public string Name { get; set; }
|
||||
public bool IsReady { get; set; }
|
||||
public PlayerHUDMarker HudMarker { get; set; }
|
||||
public State State { get; set; }
|
||||
|
||||
// Body Objects
|
||||
public GameObject Camera { get; set; }
|
||||
public GameObject Body { get; set; }
|
||||
// Body Objects
|
||||
public GameObject Camera { get; set; }
|
||||
public GameObject Body { get; set; }
|
||||
|
||||
// Tools
|
||||
public GameObject ProbeBody { get; set; }
|
||||
public QSBProbe Probe { get; set; }
|
||||
public QSBFlashlight FlashLight => Camera?.GetComponentInChildren<QSBFlashlight>();
|
||||
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
|
||||
public QSBTool Translator => GetToolByType(ToolType.Translator);
|
||||
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
|
||||
// Tools
|
||||
public GameObject ProbeBody { get; set; }
|
||||
public QSBProbe Probe { get; set; }
|
||||
public QSBFlashlight FlashLight => Camera?.GetComponentInChildren<QSBFlashlight>();
|
||||
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
|
||||
public QSBTool Translator => GetToolByType(ToolType.Translator);
|
||||
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
|
||||
|
||||
// Conversation
|
||||
public int CurrentDialogueID { get; set; }
|
||||
public GameObject CurrentDialogueBox { get; set; }
|
||||
// Conversation
|
||||
public int CurrentDialogueID { get; set; }
|
||||
public GameObject CurrentDialogueBox { get; set; }
|
||||
|
||||
// Animation
|
||||
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
|
||||
public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited
|
||||
&& AnimationSync.CurrentType != AnimationType.PlayerUnsuited;
|
||||
// Animation
|
||||
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
|
||||
public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited
|
||||
&& AnimationSync.CurrentType != AnimationType.PlayerUnsuited;
|
||||
|
||||
public PlayerInfo(uint id)
|
||||
{
|
||||
PlayerId = id;
|
||||
CurrentDialogueID = -1;
|
||||
}
|
||||
public PlayerInfo(uint id)
|
||||
{
|
||||
PlayerId = id;
|
||||
CurrentDialogueID = -1;
|
||||
}
|
||||
|
||||
public void UpdateState(State state, bool value)
|
||||
{
|
||||
var states = State;
|
||||
if (value)
|
||||
{
|
||||
FlagsHelper.Set(ref states, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
FlagsHelper.Unset(ref states, state);
|
||||
}
|
||||
State = states;
|
||||
}
|
||||
public void UpdateState(State state, bool value)
|
||||
{
|
||||
var states = State;
|
||||
if (value)
|
||||
{
|
||||
FlagsHelper.Set(ref states, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
FlagsHelper.Unset(ref states, state);
|
||||
}
|
||||
State = states;
|
||||
}
|
||||
|
||||
public void UpdateStateObjects()
|
||||
{
|
||||
if (OWInput.GetInputMode() == InputMode.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FlashLight?.UpdateState(FlagsHelper.IsSet(State, State.Flashlight));
|
||||
Translator?.ChangeEquipState(FlagsHelper.IsSet(State, State.Translator));
|
||||
ProbeLauncher?.ChangeEquipState(FlagsHelper.IsSet(State, State.ProbeLauncher));
|
||||
Signalscope?.ChangeEquipState(FlagsHelper.IsSet(State, State.Signalscope));
|
||||
QSB.Helper.Events.Unity.RunWhen(() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId) != null,
|
||||
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(FlagsHelper.IsSet(State, State.Suit)));
|
||||
}
|
||||
public void UpdateStateObjects()
|
||||
{
|
||||
if (OWInput.GetInputMode() == InputMode.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FlashLight?.UpdateState(FlagsHelper.IsSet(State, State.Flashlight));
|
||||
Translator?.ChangeEquipState(FlagsHelper.IsSet(State, State.Translator));
|
||||
ProbeLauncher?.ChangeEquipState(FlagsHelper.IsSet(State, State.ProbeLauncher));
|
||||
Signalscope?.ChangeEquipState(FlagsHelper.IsSet(State, State.Signalscope));
|
||||
QSB.Helper.Events.Unity.RunWhen(() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId) != null,
|
||||
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(FlagsHelper.IsSet(State, State.Suit)));
|
||||
}
|
||||
|
||||
public bool GetState(State state)
|
||||
{
|
||||
return FlagsHelper.IsSet(State, state);
|
||||
}
|
||||
public bool GetState(State state)
|
||||
{
|
||||
return FlagsHelper.IsSet(State, state);
|
||||
}
|
||||
|
||||
private QSBTool GetToolByType(ToolType type)
|
||||
{
|
||||
return Camera?.GetComponentsInChildren<QSBTool>()
|
||||
.FirstOrDefault(x => x.Type == type);
|
||||
}
|
||||
}
|
||||
private QSBTool GetToolByType(ToolType type)
|
||||
{
|
||||
return Camera?.GetComponentsInChildren<QSBTool>()
|
||||
.FirstOrDefault(x => x.Type == type);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using QSB.QuantumUNET;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
[Flags]
|
||||
public enum State
|
||||
{
|
||||
None = 0,
|
||||
Flashlight = 1,
|
||||
Suit = 2,
|
||||
ProbeLauncher = 4,
|
||||
Signalscope = 8,
|
||||
Translator = 16,
|
||||
ProbeActive = 32
|
||||
//Increment these in binary to add more states
|
||||
}
|
||||
[Flags]
|
||||
public enum State
|
||||
{
|
||||
None = 0,
|
||||
Flashlight = 1,
|
||||
Suit = 2,
|
||||
ProbeLauncher = 4,
|
||||
Signalscope = 8,
|
||||
Translator = 16,
|
||||
ProbeActive = 32
|
||||
//Increment these in binary to add more states
|
||||
}
|
||||
}
|
@ -80,7 +80,7 @@ namespace QSB
|
||||
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
|
||||
ident = _probePrefab.AddComponent<QSBNetworkIdentity>();
|
||||
ident.LocalPlayerAuthority = true;
|
||||
ident.SetValue("m_AssetId",_probePrefab.GetComponent<NetworkIdentity>().assetId);
|
||||
ident.SetValue("m_AssetId", _probePrefab.GetComponent<NetworkIdentity>().assetId);
|
||||
ident.SetValue("m_SceneId", _probePrefab.GetComponent<NetworkIdentity>().sceneId);
|
||||
_probePrefab.AddComponent<PlayerProbeSync>();
|
||||
spawnPrefabs.Add(_probePrefab);
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
struct QSBCRCMessageEntry
|
||||
{
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,9 +1,6 @@
|
||||
using QSB.Animation;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.NetworkSystem;
|
||||
|
@ -1,8 +1,4 @@
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Net.Sockets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@ -212,16 +211,16 @@ namespace QSB.QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool GetInvokerForHashCommand(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
internal static bool GetInvokerForHashCommand(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
=> GetInvokerForHash(cmdHash, UNetInvokeType.Command, out invokeClass, out invokeFunction);
|
||||
|
||||
internal static bool GetInvokerForHashClientRpc(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
internal static bool GetInvokerForHashClientRpc(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
=> GetInvokerForHash(cmdHash, UNetInvokeType.ClientRpc, out invokeClass, out invokeFunction);
|
||||
|
||||
internal static bool GetInvokerForHashSyncList(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
internal static bool GetInvokerForHashSyncList(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
=> GetInvokerForHash(cmdHash, UNetInvokeType.SyncList, out invokeClass, out invokeFunction);
|
||||
|
||||
internal static bool GetInvokerForHashSyncEvent(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
internal static bool GetInvokerForHashSyncEvent(int cmdHash, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
=> GetInvokerForHash(cmdHash, UNetInvokeType.SyncEvent, out invokeClass, out invokeFunction);
|
||||
|
||||
private static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Type invokeClass, out CmdDelegate invokeFunction)
|
||||
@ -276,7 +275,7 @@ namespace QSB.QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ContainsCommandDelegate(int cmdHash)
|
||||
internal bool ContainsCommandDelegate(int cmdHash)
|
||||
=> s_CmdHandlerDelegates.ContainsKey(cmdHash);
|
||||
|
||||
internal bool InvokeCommandDelegate(int cmdHash, NetworkReader reader)
|
||||
@ -425,16 +424,16 @@ namespace QSB.QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetCmdHashCmdName(int cmdHash)
|
||||
internal static string GetCmdHashCmdName(int cmdHash)
|
||||
=> GetCmdHashPrefixName(cmdHash, "InvokeCmd");
|
||||
|
||||
internal static string GetCmdHashRpcName(int cmdHash)
|
||||
internal static string GetCmdHashRpcName(int cmdHash)
|
||||
=> GetCmdHashPrefixName(cmdHash, "InvokeRpc");
|
||||
|
||||
internal static string GetCmdHashEventName(int cmdHash)
|
||||
internal static string GetCmdHashEventName(int cmdHash)
|
||||
=> GetCmdHashPrefixName(cmdHash, "InvokeSyncEvent");
|
||||
|
||||
internal static string GetCmdHashListName(int cmdHash)
|
||||
internal static string GetCmdHashListName(int cmdHash)
|
||||
=> GetCmdHashPrefixName(cmdHash, "InvokeSyncList");
|
||||
|
||||
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.Match;
|
||||
|
@ -1,7 +1,5 @@
|
||||
using QSB.QuantumUNET;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.Utility;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
@ -87,7 +86,7 @@ namespace QSB.QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ReadOnlyCollection<QSBNetworkConnection> Observers
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking.Match;
|
||||
|
||||
|
@ -2,9 +2,7 @@
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.Match;
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
public delegate void QSBNetworkMessageDelegate(QSBNetworkMessage netMsg);
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.Match;
|
||||
|
@ -1,8 +1,5 @@
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
@ -4,8 +4,6 @@ using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.Match;
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking.Types;
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.QuantumUNET
|
||||
{
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking.Types;
|
||||
|
||||
|
@ -3,18 +3,18 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.SectorSync
|
||||
{
|
||||
public class QSBSector : WorldObject
|
||||
{
|
||||
public Sector Sector { get; private set; }
|
||||
public Sector.Name Type => Sector.GetName();
|
||||
public string Name => Sector.name;
|
||||
public Transform Transform => Sector.transform;
|
||||
public Vector3 Position => Transform.position;
|
||||
public class QSBSector : WorldObject
|
||||
{
|
||||
public Sector Sector { get; private set; }
|
||||
public Sector.Name Type => Sector.GetName();
|
||||
public string Name => Sector.name;
|
||||
public Transform Transform => Sector.transform;
|
||||
public Vector3 Position => Transform.position;
|
||||
|
||||
public void Init(Sector sector, int id)
|
||||
{
|
||||
Sector = sector;
|
||||
ObjectId = id;
|
||||
}
|
||||
}
|
||||
public void Init(Sector sector, int id)
|
||||
{
|
||||
Sector = sector;
|
||||
ObjectId = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,48 +6,48 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.SectorSync
|
||||
{
|
||||
public class QSBSectorManager : MonoBehaviour
|
||||
{
|
||||
public static QSBSectorManager Instance { get; private set; }
|
||||
public class QSBSectorManager : MonoBehaviour
|
||||
{
|
||||
public static QSBSectorManager Instance { get; private set; }
|
||||
|
||||
public bool IsReady { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
|
||||
private readonly Sector.Name[] _sectorBlacklist =
|
||||
{
|
||||
Sector.Name.Ship
|
||||
};
|
||||
private readonly Sector.Name[] _sectorBlacklist =
|
||||
{
|
||||
Sector.Name.Ship
|
||||
};
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
|
||||
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
|
||||
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
|
||||
}
|
||||
|
||||
public void RebuildSectors()
|
||||
{
|
||||
DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning);
|
||||
WorldRegistry.RemoveObjects<QSBSector>();
|
||||
var sectors = Resources.FindObjectsOfTypeAll<Sector>().ToList();
|
||||
for (var id = 0; id < sectors.Count; id++)
|
||||
{
|
||||
var qsbSector = WorldRegistry.GetObject<QSBSector>(id) ?? new QSBSector();
|
||||
qsbSector.Init(sectors[id], id);
|
||||
WorldRegistry.AddObject(qsbSector);
|
||||
}
|
||||
IsReady = WorldRegistry.GetObjects<QSBSector>().Any();
|
||||
}
|
||||
public void RebuildSectors()
|
||||
{
|
||||
DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning);
|
||||
WorldRegistry.RemoveObjects<QSBSector>();
|
||||
var sectors = Resources.FindObjectsOfTypeAll<Sector>().ToList();
|
||||
for (var id = 0; id < sectors.Count; id++)
|
||||
{
|
||||
var qsbSector = WorldRegistry.GetObject<QSBSector>(id) ?? new QSBSector();
|
||||
qsbSector.Init(sectors[id], id);
|
||||
WorldRegistry.AddObject(qsbSector);
|
||||
}
|
||||
IsReady = WorldRegistry.GetObjects<QSBSector>().Any();
|
||||
}
|
||||
|
||||
public QSBSector GetClosestSector(Transform trans)
|
||||
{
|
||||
return WorldRegistry.GetObjects<QSBSector>()
|
||||
.Where(sector => sector.Sector != null && !_sectorBlacklist.Contains(sector.Type))
|
||||
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))
|
||||
.First();
|
||||
}
|
||||
}
|
||||
public QSBSector GetClosestSector(Transform trans)
|
||||
{
|
||||
return WorldRegistry.GetObjects<QSBSector>()
|
||||
.Where(sector => sector.Sector != null && !_sectorBlacklist.Contains(sector.Type))
|
||||
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))
|
||||
.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,45 +5,45 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.SectorSync
|
||||
{
|
||||
public class SectorSync : MonoBehaviour
|
||||
{
|
||||
private const float CheckInterval = 0.5f;
|
||||
private float _checkTimer = CheckInterval;
|
||||
public class SectorSync : MonoBehaviour
|
||||
{
|
||||
private const float CheckInterval = 0.5f;
|
||||
private float _checkTimer = CheckInterval;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!QSBSectorManager.Instance.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_checkTimer += Time.unscaledDeltaTime;
|
||||
if (_checkTimer < CheckInterval)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
|
||||
_checkTimer = 0;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (!QSBSectorManager.Instance.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_checkTimer += Time.unscaledDeltaTime;
|
||||
if (_checkTimer < CheckInterval)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
|
||||
_checkTimer = 0;
|
||||
}
|
||||
|
||||
private void CheckTransformSyncSector(TransformSync.TransformSync transformSync)
|
||||
{
|
||||
var syncedTransform = transformSync.SyncedTransform;
|
||||
if (syncedTransform == null || syncedTransform.position == Vector3.zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var closestSector = QSBSectorManager.Instance.GetClosestSector(syncedTransform);
|
||||
if (closestSector == transformSync.ReferenceSector)
|
||||
{
|
||||
return;
|
||||
}
|
||||
transformSync.SetReferenceSector(closestSector);
|
||||
SendSector(transformSync.NetId.Value, closestSector);
|
||||
}
|
||||
private void CheckTransformSyncSector(TransformSync.TransformSync transformSync)
|
||||
{
|
||||
var syncedTransform = transformSync.SyncedTransform;
|
||||
if (syncedTransform == null || syncedTransform.position == Vector3.zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var closestSector = QSBSectorManager.Instance.GetClosestSector(syncedTransform);
|
||||
if (closestSector == transformSync.ReferenceSector)
|
||||
{
|
||||
return;
|
||||
}
|
||||
transformSync.SetReferenceSector(closestSector);
|
||||
SendSector(transformSync.NetId.Value, closestSector);
|
||||
}
|
||||
|
||||
private void SendSector(uint id, QSBSector sector)
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
|
||||
}
|
||||
}
|
||||
private void SendSector(uint id, QSBSector sector)
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,26 +2,26 @@
|
||||
|
||||
namespace QSB.TimeSync.Events
|
||||
{
|
||||
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
|
||||
{
|
||||
public override EventType Type => EventType.ServerTime;
|
||||
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
|
||||
{
|
||||
public override EventType Type => EventType.ServerTime;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<float, int>.AddListener(EventNames.QSBServerTime, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<float, int>.AddListener(EventNames.QSBServerTime, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, Handler);
|
||||
|
||||
private void Handler(float time, int count) => SendEvent(CreateMessage(time, count));
|
||||
private void Handler(float time, int count) => SendEvent(CreateMessage(time, count));
|
||||
|
||||
private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ServerTime = time,
|
||||
LoopCount = count
|
||||
};
|
||||
private ServerTimeMessage CreateMessage(float time, int count) => new ServerTimeMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ServerTime = time,
|
||||
LoopCount = count
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ServerTimeMessage message)
|
||||
{
|
||||
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(ServerTimeMessage message)
|
||||
{
|
||||
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,23 +3,23 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.TimeSync.Events
|
||||
{
|
||||
public class ServerTimeMessage : PlayerMessage
|
||||
{
|
||||
public float ServerTime { get; set; }
|
||||
public int LoopCount { get; set; }
|
||||
public class ServerTimeMessage : PlayerMessage
|
||||
{
|
||||
public float ServerTime { get; set; }
|
||||
public int LoopCount { get; set; }
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ServerTime = reader.ReadSingle();
|
||||
LoopCount = reader.ReadInt16();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ServerTime = reader.ReadSingle();
|
||||
LoopCount = reader.ReadInt16();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ServerTime);
|
||||
writer.Write(LoopCount);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ServerTime);
|
||||
writer.Write(LoopCount);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.QuantumUNET;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.TimeSync
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user