mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 16:14:45 +00:00
join/leave singularity
This commit is contained in:
parent
a3ab23395f
commit
4680911cac
@ -2,6 +2,7 @@
|
|||||||
using Mirror;
|
using Mirror;
|
||||||
using QSB.Messaging;
|
using QSB.Messaging;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
|
using QSB.Player.Messages;
|
||||||
using QSB.Player.TransformSync;
|
using QSB.Player.TransformSync;
|
||||||
using QSB.SaveSync.Messages;
|
using QSB.SaveSync.Messages;
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
@ -301,6 +302,11 @@ namespace QSB.Menus
|
|||||||
{
|
{
|
||||||
_intentionalDisconnect = true;
|
_intentionalDisconnect = true;
|
||||||
|
|
||||||
|
if (!QSBCore.IsHost)
|
||||||
|
{
|
||||||
|
new JoinLeaveSingularityMessage(false).Send();
|
||||||
|
}
|
||||||
|
|
||||||
QSBNetworkManager.singleton.StopHost();
|
QSBNetworkManager.singleton.StopHost();
|
||||||
SetButtonActive(DisconnectButton.gameObject, false);
|
SetButtonActive(DisconnectButton.gameObject, false);
|
||||||
|
|
||||||
@ -373,7 +379,7 @@ namespace QSB.Menus
|
|||||||
QSBNetworkManager.singleton.StartClient();
|
QSBNetworkManager.singleton.StartClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConnected()
|
private static void OnConnected()
|
||||||
{
|
{
|
||||||
if (QSBCore.IsHost || !QSBCore.IsInMultiplayer)
|
if (QSBCore.IsHost || !QSBCore.IsInMultiplayer)
|
||||||
{
|
{
|
||||||
|
80
QSB/Player/JoinLeaveSingularity.cs
Normal file
80
QSB/Player/JoinLeaveSingularity.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using QSB.Utility;
|
||||||
|
using QSB.WorldSync;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace QSB.Player
|
||||||
|
{
|
||||||
|
public static class JoinLeaveSingularity
|
||||||
|
{
|
||||||
|
public static void Create(PlayerInfo player, bool joining)
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"{player.TransformSync} join/leave singularity: (joining = {joining})");
|
||||||
|
|
||||||
|
var go = new GameObject(nameof(JoinLeaveSingularity));
|
||||||
|
|
||||||
|
var playerGo = player.Body;
|
||||||
|
playerGo.SetActive(false);
|
||||||
|
go.transform.parent = playerGo.transform.parent;
|
||||||
|
go.transform.localPosition = playerGo.transform.localPosition;
|
||||||
|
go.transform.localRotation = playerGo.transform.localRotation;
|
||||||
|
go.transform.localScale = playerGo.transform.localScale;
|
||||||
|
|
||||||
|
var fakePlayerGo = playerGo.InstantiateInactive();
|
||||||
|
fakePlayerGo.transform.parent = go.transform;
|
||||||
|
fakePlayerGo.transform.localPosition = Vector3.zero;
|
||||||
|
fakePlayerGo.transform.localRotation = Quaternion.identity;
|
||||||
|
fakePlayerGo.transform.localScale = Vector3.one;
|
||||||
|
|
||||||
|
foreach (var component in fakePlayerGo.GetComponents<Component>())
|
||||||
|
{
|
||||||
|
if (component is not (Transform or Renderer))
|
||||||
|
{
|
||||||
|
Object.Destroy(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fakePlayerGo.SetActive(true);
|
||||||
|
|
||||||
|
var referenceEffect = joining ?
|
||||||
|
QSBWorldSync.GetUnityObjects<ProbeLauncher>()
|
||||||
|
.Select(x => x._probeRetrievalEffect)
|
||||||
|
.First(x => x) :
|
||||||
|
QSBWorldSync.GetUnityObjects<SurveyorProbe>()
|
||||||
|
.Select(x => x._warpEffect)
|
||||||
|
.First(x => x);
|
||||||
|
var effectGo = referenceEffect.gameObject.InstantiateInactive();
|
||||||
|
effectGo.transform.parent = go.transform;
|
||||||
|
effectGo.transform.localPosition = Vector3.zero;
|
||||||
|
effectGo.transform.localRotation = Quaternion.identity;
|
||||||
|
effectGo.transform.localScale = Vector3.one;
|
||||||
|
|
||||||
|
var effect = effectGo.GetComponent<SingularityWarpEffect>();
|
||||||
|
effect._warpedObjectGeometry = fakePlayerGo;
|
||||||
|
effectGo.SetActive(true);
|
||||||
|
|
||||||
|
effect.OnWarpComplete += () =>
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"{player.TransformSync} warp complete");
|
||||||
|
|
||||||
|
Object.Destroy(go);
|
||||||
|
|
||||||
|
if (playerGo)
|
||||||
|
{
|
||||||
|
playerGo.SetActive(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const float length = 3;
|
||||||
|
if (joining)
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"{player.TransformSync} warp in (white hole)");
|
||||||
|
effect.WarpObjectIn(length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"{player.TransformSync} warp out (black hole)");
|
||||||
|
effect.WarpObjectOut(length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
QSB/Player/Messages/JoinLeaveSingularityMessage.cs
Normal file
18
QSB/Player/Messages/JoinLeaveSingularityMessage.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using QSB.Messaging;
|
||||||
|
|
||||||
|
namespace QSB.Player.Messages
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// sent by non-hosts only
|
||||||
|
/// </summary>
|
||||||
|
public class JoinLeaveSingularityMessage : QSBMessage<bool>
|
||||||
|
{
|
||||||
|
public JoinLeaveSingularityMessage(bool joining) => Value = joining;
|
||||||
|
|
||||||
|
public override void OnReceiveRemote()
|
||||||
|
{
|
||||||
|
var player = QSBPlayerManager.GetPlayer(From);
|
||||||
|
JoinLeaveSingularity.Create(player, Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,7 +46,16 @@ namespace QSB.Player.TransformSync
|
|||||||
DebugLog.DebugWrite($"Create Player : id<{Player.PlayerId}>", MessageType.Info);
|
DebugLog.DebugWrite($"Create Player : id<{Player.PlayerId}>", MessageType.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnStartLocalPlayer() => LocalInstance = this;
|
public override void OnStartLocalPlayer()
|
||||||
|
{
|
||||||
|
LocalInstance = this;
|
||||||
|
|
||||||
|
if (!QSBCore.IsHost)
|
||||||
|
{
|
||||||
|
Delay.RunWhen(() => IsValid && ReferenceTransform,
|
||||||
|
() => new JoinLeaveSingularityMessage(true).Send());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnStopClient()
|
public override void OnStopClient()
|
||||||
{
|
{
|
||||||
@ -89,6 +98,10 @@ namespace QSB.Player.TransformSync
|
|||||||
protected override void GetFromAttached()
|
protected override void GetFromAttached()
|
||||||
{
|
{
|
||||||
base.GetFromAttached();
|
base.GetFromAttached();
|
||||||
|
if (!ReferenceTransform)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
GetFromChild(_visibleStickPivot, _networkStickPivot);
|
GetFromChild(_visibleStickPivot, _networkStickPivot);
|
||||||
GetFromChild(_visibleStickTip, _networkStickTip);
|
GetFromChild(_visibleStickTip, _networkStickTip);
|
||||||
@ -99,6 +112,10 @@ namespace QSB.Player.TransformSync
|
|||||||
protected override void ApplyToAttached()
|
protected override void ApplyToAttached()
|
||||||
{
|
{
|
||||||
base.ApplyToAttached();
|
base.ApplyToAttached();
|
||||||
|
if (!ReferenceTransform)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ApplyToChild(_visibleStickPivot, _networkStickPivot, ref _pivotPositionVelocity, ref _pivotRotationVelocity);
|
ApplyToChild(_visibleStickPivot, _networkStickPivot, ref _pivotPositionVelocity, ref _pivotRotationVelocity);
|
||||||
ApplyToChild(_visibleStickTip, _networkStickTip, ref _tipPositionVelocity, ref _tipRotationVelocity);
|
ApplyToChild(_visibleStickTip, _networkStickTip, ref _tipPositionVelocity, ref _tipRotationVelocity);
|
||||||
|
@ -18,6 +18,8 @@ namespace QSB.Utility
|
|||||||
=> transform.rotation * localRotation;
|
=> transform.rotation * localRotation;
|
||||||
|
|
||||||
public static GameObject InstantiateInactive(this GameObject original)
|
public static GameObject InstantiateInactive(this GameObject original)
|
||||||
|
{
|
||||||
|
if (original.activeSelf)
|
||||||
{
|
{
|
||||||
original.SetActive(false);
|
original.SetActive(false);
|
||||||
var copy = Object.Instantiate(original);
|
var copy = Object.Instantiate(original);
|
||||||
@ -25,8 +27,8 @@ namespace QSB.Utility
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Transform InstantiateInactive(this Transform original) =>
|
return Object.Instantiate(original);
|
||||||
original.gameObject.InstantiateInactive().transform;
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user