basically perfect

This commit is contained in:
JohnCorby 2022-02-17 02:15:43 -08:00
parent 0e21e6fc3e
commit ccc0e7a0be

View File

@ -11,7 +11,7 @@ namespace QSB.Player
{
public static async UniTaskVoid Create(PlayerInfo player, bool joining)
{
if (!player.IsLocalPlayer)
if (player.IsLocalPlayer)
{
return;
}
@ -21,15 +21,16 @@ namespace QSB.Player
if (PlayerTransformSync.LocalInstance == null ||
player.PlayerId < QSBPlayerManager.LocalPlayerId)
{
// player was here before we joined
return;
}
await UniTask.WaitUntil(() => player.TransformSync.IsValid && player.TransformSync.ReferenceTransform);
await UniTask.WaitUntil(() => player.Body);
player.Body.SetActive(false);
await UniTask.WaitUntil(() => player.TransformSync.ReferenceTransform);
}
DebugLog.DebugWrite($"WARP {player.TransformSync}");
player.SetVisible(false);
DebugLog.DebugWrite($"WARP {player.PlayerId}");
var go = new GameObject(nameof(JoinLeaveSingularity));
go.transform.parent = player.TransformSync.ReferenceTransform;
@ -38,35 +39,48 @@ namespace QSB.Player
#region fake player
player.SetVisible(true);
var fakePlayer = player.Body.transform.Find("REMOTE_Traveller_HEA_Player_v2")
.gameObject.InstantiateInactive();
fakePlayer.transform.SetParent(go.transform, false);
fakePlayer.SetActive(true);
player.SetVisible(false);
GameObject fakePlayer = null;
if (!joining)
{
player.Body.SetActive(false);
fakePlayer = Object.Instantiate(player.Body, go.transform);
foreach (var component in fakePlayer.GetComponentsInChildren<Component>(true))
{
if (component is Behaviour behaviour)
{
behaviour.enabled = false;
}
else if (component is not (Transform or Renderer))
{
Object.Destroy(component);
}
}
fakePlayer.SetActive(true);
}
#endregion
#region effect
var effectGo = QSBWorldSync.GetUnityObjects<GravityCannonController>().First()._warpEffect
.gameObject.InstantiateInactive();
effectGo.transform.parent = go.transform;
effectGo.transform.localPosition = Vector3.zero;
effectGo.transform.localRotation = Quaternion.identity;
effectGo.transform.localScale = Vector3.one;
var effect = QSBWorldSync.GetUnityObjects<GravityCannonController>().First()._warpEffect;
effect = effect.gameObject.InstantiateInactive().GetComponent<SingularityWarpEffect>();
effect.transform.parent = go.transform;
effect.transform.localPosition = Vector3.zero;
effect.transform.localRotation = Quaternion.identity;
effect.transform.localScale = Vector3.one;
var effect = effectGo.GetComponent<SingularityWarpEffect>();
effect.enabled = true;
effect._warpedObjectGeometry = fakePlayer;
effect._warpedObjectGeometry = joining ? player.Body : fakePlayer;
effect._singularity.enabled = true;
effect._singularity._startActive = false;
effect._singularity._muteSingularityEffectAudio = false;
effect._singularity._creationCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
effect._singularity._destructionCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);
var singularity = effect._singularity;
singularity.enabled = true;
singularity._startActive = false;
singularity._muteSingularityEffectAudio = false;
singularity._creationCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
singularity._destructionCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);
var renderer = effectGo.GetComponent<Renderer>();
var renderer = effect.GetComponent<Renderer>();
renderer.material.SetFloat("_DistortFadeDist", 3);
renderer.material.SetFloat("_MassScale", joining ? -1 : 1);
renderer.material.SetFloat("_MaxDistortRadius", 10);
@ -74,30 +88,37 @@ namespace QSB.Player
renderer.material.SetFloat("_Radius", 1);
renderer.material.SetColor("_Color", joining ? Color.white : Color.black);
effectGo.SetActive(true);
effect.gameObject.SetActive(true);
#endregion
await UniTask.WaitForEndOfFrame();
effect.OnWarpComplete += () =>
{
DebugLog.DebugWrite($"WARP DONE {player.TransformSync}");
Object.Destroy(go);
player.SetVisible(true);
};
if (joining)
{
DebugLog.DebugWrite($"WARP IN {player.TransformSync}");
player.Body.SetActive(true);
DebugLog.DebugWrite($"WARP IN {player.PlayerId}");
effect.WarpObjectIn(0);
}
else
{
DebugLog.DebugWrite($"WARP OUT {player.TransformSync}");
DebugLog.DebugWrite($"WARP OUT {player.PlayerId}");
effect.WarpObjectOut(0);
}
var tcs = new UniTaskCompletionSource();
effect.OnWarpComplete += () => tcs.TrySetResult();
await tcs.Task;
DebugLog.DebugWrite($"WARP DONE {player.PlayerId}");
if (!joining)
{
Object.Destroy(fakePlayer);
}
await UniTask.WaitUntil(() => !singularity._owOneShotSource.isPlaying);
Object.Destroy(go);
}
}
}