2020-11-20 19:50:31 +00:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Animation;
|
2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-11-01 12:26:09 +00:00
|
|
|
|
using QSB.Instruments.QSBCamera;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-11-20 19:50:31 +00:00
|
|
|
|
using QSB.Utility;
|
2020-10-27 22:59:19 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Instruments
|
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class InstrumentsManager : PlayerSyncObject
|
|
|
|
|
{
|
2020-12-14 20:41:56 +00:00
|
|
|
|
private Transform _rootObj;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private AnimationType _savedType;
|
2020-12-14 20:41:56 +00:00
|
|
|
|
private GameObject _chertDrum;
|
2020-10-27 22:59:19 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public void InitLocal(Transform root)
|
|
|
|
|
{
|
2020-12-14 20:41:56 +00:00
|
|
|
|
_rootObj = root;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
gameObject.AddComponent<CameraManager>();
|
2020-11-11 08:31:20 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
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);
|
2020-12-14 20:41:56 +00:00
|
|
|
|
QSBInputManager.ExitTaunt += ReturnToPlayer;
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-14 16:24:52 +00:00
|
|
|
|
QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public void InitRemote(Transform root)
|
|
|
|
|
{
|
2020-12-14 20:41:56 +00:00
|
|
|
|
_rootObj = root;
|
2020-12-14 16:24:52 +00:00
|
|
|
|
QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-11-11 08:31:20 +00:00
|
|
|
|
|
2020-12-14 16:04:16 +00:00
|
|
|
|
protected override void OnDestroy()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-14 19:23:24 +00:00
|
|
|
|
base.OnDestroy();
|
2020-12-02 21:23:01 +00:00
|
|
|
|
if (!IsLocalPlayer)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-14 20:41:56 +00:00
|
|
|
|
QSBInputManager.ChertTaunt -= OnChertTaunt;
|
|
|
|
|
QSBInputManager.EskerTaunt -= OnEskerTaunt;
|
|
|
|
|
QSBInputManager.FeldsparTaunt -= OnFeldsparTaunt;
|
|
|
|
|
QSBInputManager.GabbroTaunt -= OnGabbroTaunt;
|
|
|
|
|
QSBInputManager.RiebeckTaunt -= OnRiebeckTaunt;
|
|
|
|
|
QSBInputManager.ExitTaunt -= ReturnToPlayer;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-11-11 08:31:20 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private void OnChertTaunt() => StartInstrument(AnimationType.Chert);
|
|
|
|
|
private void OnEskerTaunt() => StartInstrument(AnimationType.Esker);
|
|
|
|
|
private void OnFeldsparTaunt() => StartInstrument(AnimationType.Feldspar);
|
|
|
|
|
private void OnGabbroTaunt() => StartInstrument(AnimationType.Gabbro);
|
|
|
|
|
private void OnRiebeckTaunt() => StartInstrument(AnimationType.Riebeck);
|
|
|
|
|
|
|
|
|
|
private void SetupInstruments()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-14 16:24:52 +00:00
|
|
|
|
var bundle = QSBCore.InstrumentAssetBundle;
|
2020-12-14 20:41:56 +00:00
|
|
|
|
_chertDrum = MakeChertDrum(bundle);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
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>();
|
2020-12-06 23:39:25 +00:00
|
|
|
|
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
|
|
|
|
|
{
|
|
|
|
|
mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent<MeshRenderer>().material;
|
|
|
|
|
}
|
|
|
|
|
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
|
|
|
|
|
{
|
|
|
|
|
//mr.sharedMaterial = GameObject.Find("Props_HEA_Drums").GetComponent<MeshRenderer>().material;
|
|
|
|
|
// TODO : fix for instrument release
|
|
|
|
|
mr.sharedMaterial = null;
|
|
|
|
|
}
|
2020-12-14 20:41:56 +00:00
|
|
|
|
drum.transform.parent = _rootObj;
|
|
|
|
|
drum.transform.rotation = _rootObj.rotation;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
drum.transform.localPosition = Vector3.zero;
|
|
|
|
|
drum.transform.localScale = new Vector3(16.0f, 16.5f, 16.0f);
|
|
|
|
|
drum.SetActive(false);
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
return drum;
|
|
|
|
|
}
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2020-10-27 22:59:19 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public void ReturnToPlayer()
|
|
|
|
|
{
|
|
|
|
|
if (!Player.PlayingInstrument)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CameraManager.Instance.SwitchTo1stPerson();
|
|
|
|
|
SwitchToType(_savedType);
|
|
|
|
|
}
|
2020-11-01 15:56:48 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2020-11-20 19:50:31 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public void CheckInstrumentProps(AnimationType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case AnimationType.Chert:
|
2020-12-14 20:48:41 +00:00
|
|
|
|
_chertDrum?.SetActive(true);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
break;
|
|
|
|
|
case AnimationType.PlayerSuited:
|
|
|
|
|
case AnimationType.PlayerUnsuited:
|
2020-12-14 20:48:41 +00:00
|
|
|
|
_chertDrum?.SetActive(false);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|