mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-23 06:40:56 +00:00
add head sync
This commit is contained in:
parent
6732b1aae8
commit
58635f4dd0
@ -29,6 +29,10 @@ namespace QSB.Animation
|
||||
|
||||
public AnimatorMirror Mirror { get; private set; }
|
||||
public AnimationType CurrentType = AnimationType.PlayerUnsuited;
|
||||
public Animator Animator
|
||||
{
|
||||
get { return _bodyAnim; }
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -129,6 +133,9 @@ namespace QSB.Animation
|
||||
body.Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0;
|
||||
|
||||
InitCrouchSync();
|
||||
|
||||
var ikSync = body.gameObject.AddComponent<PlayerHeadRotationSync>();
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Player.Camera != null, () => ikSync.Init(Player.Camera.transform));
|
||||
}
|
||||
|
||||
private void InitCrouchSync()
|
||||
|
@ -23,7 +23,7 @@ namespace QSB.Animation.Events
|
||||
|
||||
public override void OnReceiveRemote(EnumMessage<AnimationType> message)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).Animator.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetSyncObject<InstrumentsManager>(message.AboutId).CheckInstrumentProps(message.Value);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,12 @@ namespace QSB.Animation
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player?.UpdateState(State.Suit, message.ToggleValue);
|
||||
|
||||
var animator = player.Animator;
|
||||
if (!player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var animator = player.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.SetAnimationType(type);
|
||||
}
|
||||
@ -42,7 +47,7 @@ namespace QSB.Animation
|
||||
public override void OnReceiveLocal(ToggleMessage message)
|
||||
{
|
||||
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
|
||||
var animator = QSBPlayerManager.LocalPlayer.Animator;
|
||||
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.CurrentType = type;
|
||||
}
|
||||
|
@ -1,11 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
class PlayerHeadRotationSync
|
||||
public class PlayerHeadRotationSync : MonoBehaviour
|
||||
{
|
||||
private Animator _attachedAnimator;
|
||||
private Transform _lookBase;
|
||||
|
||||
public void Init(Transform lookBase)
|
||||
{
|
||||
_attachedAnimator = GetComponent<Animator>();
|
||||
_lookBase = lookBase;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
|
||||
// Get the camera's local rotation with respect to the head
|
||||
var lookLocalRotation = Quaternion.Inverse(bone.transform.rotation) * _lookBase.rotation;
|
||||
bone.localRotation = Quaternion.Euler(0f, 0f, lookLocalRotation.eulerAngles.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ namespace QSB.Instruments
|
||||
|
||||
private void SetupInstruments()
|
||||
{
|
||||
DebugLog.DebugWrite($"Setup instruments {PlayerId}");
|
||||
var bundle = QSB.InstrumentAssetBundle;
|
||||
ChertDrum = MakeChertDrum(bundle);
|
||||
}
|
||||
@ -69,10 +68,6 @@ namespace QSB.Instruments
|
||||
mf.sharedMesh = bundle.LoadAsset("assets/Chert/hourglasstwinsmeshescharacters2.asset") as Mesh;
|
||||
var mr = drum.AddComponent<MeshRenderer>();
|
||||
mr.sharedMaterial = GameObject.Find("NewDrum:polySurface2").GetComponent<MeshRenderer>().material;
|
||||
foreach (var item in mr.sharedMaterial.shaderKeywords)
|
||||
{
|
||||
DebugLog.DebugWrite(item);
|
||||
}
|
||||
drum.transform.parent = rootObj;
|
||||
drum.transform.rotation = rootObj.rotation;
|
||||
drum.transform.localPosition = Vector3.zero;
|
||||
@ -93,7 +88,7 @@ namespace QSB.Instruments
|
||||
{
|
||||
return;
|
||||
}
|
||||
_savedType = Player.Animator.CurrentType;
|
||||
_savedType = Player.AnimationSync.CurrentType;
|
||||
CameraManager.Instance.SwitchTo3rdPerson();
|
||||
SwitchToType(type);
|
||||
}
|
||||
@ -112,7 +107,7 @@ namespace QSB.Instruments
|
||||
{
|
||||
DebugLog.DebugWrite($"switch to type {type} player {PlayerId}");
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type);
|
||||
QSBPlayerManager.LocalPlayer.Animator.SetAnimationType(type);
|
||||
QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type);
|
||||
CheckInstrumentProps(type);
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,9 @@ namespace QSB.Player
|
||||
public GameObject CurrentDialogueBox { get; set; }
|
||||
|
||||
// Animation
|
||||
public AnimationSync Animator => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
|
||||
public bool PlayingInstrument => Animator.CurrentType != AnimationType.PlayerSuited
|
||||
&& Animator.CurrentType != AnimationType.PlayerUnsuited;
|
||||
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
|
||||
public bool PlayingInstrument => AnimationSync.CurrentType != AnimationType.PlayerSuited
|
||||
&& AnimationSync.CurrentType != AnimationType.PlayerUnsuited;
|
||||
|
||||
public PlayerInfo(uint id)
|
||||
{
|
||||
|
@ -130,6 +130,7 @@
|
||||
<Compile Include="Animation\Events\QSBAnimationMessage.cs" />
|
||||
<Compile Include="Animation\Events\QSBAnimationParametersMessage.cs" />
|
||||
<Compile Include="Animation\Events\QSBAnimationTriggerMessage.cs" />
|
||||
<Compile Include="Animation\PlayerHeadRotationSync.cs" />
|
||||
<Compile Include="Animation\QSBNetworkAnimator.cs" />
|
||||
<Compile Include="ConversationSync\Events\ConversationEvent.cs" />
|
||||
<Compile Include="ConversationSync\Events\ConversationMessage.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user