quantum-space-buddies/QSB/StatueSync/StatueManager.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2021-02-28 14:43:05 +00:00
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.Utility;
2021-02-28 14:43:05 +00:00
using System.Collections;
using UnityEngine;
namespace QSB.StatueSync
{
2022-02-01 22:24:21 +00:00
internal class StatueManager : MonoBehaviour, IAddComponentOnStart
2021-02-28 14:43:05 +00:00
{
public static StatueManager Instance { get; private set; }
2021-03-01 09:44:36 +00:00
public bool HasStartedStatueLocally;
2021-02-28 14:43:05 +00:00
2021-02-28 15:29:09 +00:00
private void Awake()
2021-03-07 09:27:23 +00:00
{
2021-02-28 15:38:17 +00:00
Instance = this;
2021-11-21 13:52:29 +00:00
QSBSceneManager.OnUniverseSceneLoaded += OnUniverseSceneLoaded;
2021-03-07 09:27:23 +00:00
}
2021-02-28 15:38:17 +00:00
2021-03-07 09:27:23 +00:00
private void OnDestroy()
2021-11-21 13:52:29 +00:00
=> QSBSceneManager.OnUniverseSceneLoaded -= OnUniverseSceneLoaded;
private void OnUniverseSceneLoaded(OWScene oldScene, OWScene newScene)
{
if (!QSBCore.IsInMultiplayer)
{
return;
}
if (PlayerTransformSync.LocalInstance == null)
{
DebugLog.ToConsole($"Error - Tried to run OnUniverseSceneLoaded when PlayerTransformSync.LocalInstance was null!", OWML.Common.MessageType.Error);
return;
}
2021-11-21 13:52:29 +00:00
QSBPlayerManager.ShowAllPlayers();
QSBPlayerManager.LocalPlayer.UpdateStatesFromObjects();
}
2021-02-28 14:43:05 +00:00
2021-11-25 15:32:34 +00:00
public void BeginSequence(Vector3 position, Quaternion rotation, float cameraDegrees) => StartCoroutine(BeginRemoteUplinkSequence(position, rotation, cameraDegrees));
2021-02-28 14:43:05 +00:00
private IEnumerator BeginRemoteUplinkSequence(Vector3 position, Quaternion rotation, float cameraDegrees)
{
2021-03-01 09:44:36 +00:00
HasStartedStatueLocally = true;
2021-02-28 14:43:05 +00:00
var cameraEffectController = Locator.GetPlayerCamera().GetComponent<PlayerCameraEffectController>();
cameraEffectController.CloseEyes(0.5f);
OWInput.ChangeInputMode(InputMode.None);
Locator.GetPauseCommandListener().AddPauseCommandLock();
Locator.GetToolModeSwapper().UnequipTool();
Locator.GetFlashlight().TurnOff(false);
yield return new WaitForSeconds(0.5f);
// go to position
QSBPlayerManager.HideAllPlayers();
var timberHearth = Locator.GetAstroObject(AstroObject.Name.TimberHearth).GetAttachedOWRigidbody();
Locator.GetPlayerBody().transform.position = timberHearth.transform.TransformPoint(position);
Locator.GetPlayerBody().transform.rotation = timberHearth.transform.rotation * rotation;
Locator.GetPlayerCamera().GetComponent<PlayerCameraController>().SetDegreesY(cameraDegrees);
cameraEffectController.OpenEyes(1f, true);
var uplinkTrigger = FindObjectOfType<MemoryUplinkTrigger>();
uplinkTrigger.StartCoroutine("BeginUplinkSequence");
yield break;
}
}
}