mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-04 02:47:22 +00:00
add solanum anim sync
This commit is contained in:
parent
7e8b532f70
commit
84d1b856a2
@ -24,7 +24,6 @@ namespace QSB.Animation.NPC.Patches
|
||||
CharacterAnimController __instance,
|
||||
float ___headTrackingWeight,
|
||||
bool ___lookOnlyWhenTalking,
|
||||
bool ____playerInHeadZone,
|
||||
bool ____inConversation,
|
||||
ref float ____currentLookWeight,
|
||||
ref Vector3 ____currentLookTarget,
|
||||
@ -96,6 +95,32 @@ namespace QSB.Animation.NPC.Patches
|
||||
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(SolanumAnimController), nameof(SolanumAnimController.LateUpdate))]
|
||||
public static bool SolanumLateUpdateReplacement(SolanumAnimController __instance)
|
||||
{
|
||||
if (__instance._animatorStateEvents == null)
|
||||
{
|
||||
__instance._animatorStateEvents = __instance._animator.GetBehaviour<AnimatorStateEvents>();
|
||||
__instance._animatorStateEvents.OnEnterState += __instance.OnEnterAnimatorState;
|
||||
}
|
||||
|
||||
var qsbObj = QSBWorldSync.GetWorldFromUnity<QSBSolanumAnimController, SolanumAnimController>(__instance);
|
||||
var playersInHeadZone = qsbObj.GetPlayersInHeadZone();
|
||||
|
||||
Transform targetCamera = playersInHeadZone == null || playersInHeadZone.Count == 0
|
||||
? __instance._playerCameraTransform
|
||||
: QSBPlayerManager.GetClosestPlayerToWorldPoint(playersInHeadZone, __instance.transform.position).CameraBody.transform;
|
||||
|
||||
var targetValue = Quaternion.LookRotation(targetCamera.position - __instance._headBoneTransform.position, __instance.transform.up);
|
||||
__instance._currentLookRotation = __instance._lookSpring.Update(__instance._currentLookRotation, targetValue, Time.deltaTime);
|
||||
|
||||
var position = __instance._headBoneTransform.position + (__instance._currentLookRotation * Vector3.forward);
|
||||
__instance._localLookPosition = __instance.transform.InverseTransformPoint(position);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnZoneExit))]
|
||||
public static bool HeadZoneExit(CharacterAnimController __instance)
|
||||
@ -114,6 +139,24 @@ namespace QSB.Animation.NPC.Patches
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.OnEnterWatchVolume))]
|
||||
public static bool EnterWatchZone(NomaiConversationManager __instance)
|
||||
{
|
||||
var qsbObj = QSBWorldSync.GetWorldFromUnity<QSBSolanumAnimController, SolanumAnimController>(__instance._solanumAnimController);
|
||||
QSBEventManager.FireEvent(EventNames.QSBEnterNomaiHeadZone, qsbObj.ObjectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NomaiConversationManager), nameof(NomaiConversationManager.OnExitWatchVolume))]
|
||||
public static bool ExitWatchZone(NomaiConversationManager __instance)
|
||||
{
|
||||
var qsbObj = QSBWorldSync.GetWorldFromUnity<QSBSolanumAnimController, SolanumAnimController>(__instance._solanumAnimController);
|
||||
QSBEventManager.FireEvent(EventNames.QSBExitNomaiHeadZone, qsbObj.ObjectId);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(FacePlayerWhenTalking), nameof(FacePlayerWhenTalking.OnStartConversation))]
|
||||
public static bool OnStartConversation(FacePlayerWhenTalking __instance)
|
||||
|
40
QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs
Normal file
40
QSB/Animation/NPC/WorldObjects/QSBSolanumAnimController.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using QSB.Player;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Animation.NPC.WorldObjects
|
||||
{
|
||||
class QSBSolanumAnimController : WorldObject<SolanumAnimController>
|
||||
{
|
||||
private readonly List<PlayerInfo> _playersInHeadZone = new List<PlayerInfo>();
|
||||
|
||||
public override void Init(SolanumAnimController controller, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
AttachedObject = controller;
|
||||
}
|
||||
|
||||
public List<PlayerInfo> GetPlayersInHeadZone()
|
||||
=> _playersInHeadZone;
|
||||
|
||||
public void AddPlayerToHeadZone(PlayerInfo player)
|
||||
{
|
||||
if (_playersInHeadZone.Contains(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_playersInHeadZone.Add(player);
|
||||
}
|
||||
|
||||
public void RemovePlayerFromHeadZone(PlayerInfo player)
|
||||
{
|
||||
if (!_playersInHeadZone.Contains(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_playersInHeadZone.Remove(player);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ namespace QSB.Player.Events
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBExitPlatform, (int id) => Handler(EnterLeaveType.ExitPlatform, id));
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBEnterNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.EnterNonNomaiHeadZone, id));
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBExitNonNomaiHeadZone, (int id) => Handler(EnterLeaveType.ExitNonNomaiHeadZone, id));
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBEnterNomaiHeadZone, (int id) => Handler(EnterLeaveType.EnterNomaiHeadZone, id));
|
||||
GlobalMessenger<int>.AddListener(EventNames.QSBExitNomaiHeadZone, (int id) => Handler(EnterLeaveType.ExitNomaiHeadZone, id));
|
||||
GlobalMessenger.AddListener(EventNames.EnterShip, () => Handler(EnterLeaveType.EnterShip));
|
||||
GlobalMessenger.AddListener(EventNames.ExitShip, () => Handler(EnterLeaveType.ExitShip));
|
||||
}
|
||||
@ -83,6 +85,12 @@ namespace QSB.Player.Events
|
||||
case EnterLeaveType.ExitNonNomaiHeadZone:
|
||||
QSBWorldSync.GetWorldFromId<QSBCharacterAnimController>(message.ObjectId).RemovePlayerFromHeadZone(player);
|
||||
break;
|
||||
case EnterLeaveType.EnterNomaiHeadZone:
|
||||
QSBWorldSync.GetWorldFromId<QSBSolanumAnimController>(message.ObjectId).AddPlayerToHeadZone(player);
|
||||
break;
|
||||
case EnterLeaveType.ExitNomaiHeadZone:
|
||||
QSBWorldSync.GetWorldFromId<QSBSolanumAnimController>(message.ObjectId).RemovePlayerFromHeadZone(player);
|
||||
break;
|
||||
case EnterLeaveType.EnterShip:
|
||||
ShipManager.Instance.AddPlayerToShip(player);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user