Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Assets/Script/Venue/Characters/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class CharacterManager : GameplayBehaviour
[SerializeField]
private GameObject _venue;

[SerializeField]
private Vector3 _wind;
private Vector3 _lastUpdatedWind = Vector3.zero;
private bool _lastKnownPausedState = false;

private readonly Dictionary<VenueCharacter.CharacterType, VenueCharacter> _characters = new();
public Dictionary<VenueCharacter.CharacterType, VenueCharacter> Characters => _characters;

Expand Down Expand Up @@ -236,7 +241,20 @@ private void Update()
ProcessDrums(character);
break;
}

if (_lastKnownPausedState != GameManager.Paused && character is VRMCharacter)
{
((VRMCharacter) character).SetSpringPause(GameManager.Paused);
}

if (_wind != _lastUpdatedWind && character is VRMCharacter)
{
((VRMCharacter) character).SetWind(_wind);
}
}

_lastKnownPausedState = GameManager.Paused;
_lastUpdatedWind = _wind;
}

public void ResetTime(double time)
Expand Down
36 changes: 34 additions & 2 deletions Assets/Script/Venue/Characters/VRMCharacter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using DG.Tweening;
using UniGLTF.SpringBoneJobs.Blittables;
using UnityEngine;
using UniVRM10;
using YARG.Core.Chart;
Expand Down Expand Up @@ -36,8 +37,9 @@ public class VRMCharacter : VenueCharacter
[Tooltip("Set to true if you want to use custom animations instead of the default ones.")]
public bool UseCustomAnimations;

private ExpressionKey _lipsyncKey;
private bool _hasVrmInstance;
private ExpressionKey _lipsyncKey;
private bool _hasVrmInstance;
private BlittableModelLevel _modelLevels;

private Vector3 _initialPosition;

Expand Down Expand Up @@ -81,6 +83,7 @@ public override void Initialize(CharacterManager characterManager = null)
_characterManager = characterManager;
VrmInstance = GetComponent<Vrm10Instance>();
_hasVrmInstance = VrmInstance != null;
_modelLevels = new BlittableModelLevel();
_expression = VrmInstance.Runtime.Expression;

if (_characterManager != null)
Expand Down Expand Up @@ -159,6 +162,35 @@ private void SetExpression(LipsyncEvent lipsyncEvent)
_expression.SetWeight(_lipsyncKey, lipsyncEvent.Value);
}

public void SetWind(Vector3 wind)
{
if (!_hasVrmInstance)
{
return;
}

//update external force
_modelLevels = new BlittableModelLevel(externalForce: wind,
stopSpringBoneWriteback: _modelLevels.StopSpringBoneWriteback,
supportsScalingAtRuntime: _modelLevels.SupportsScalingAtRuntime);
//push model level changes to VRM runtime
VrmInstance.Runtime.SpringBone.SetModelLevel(VrmInstance.transform, _modelLevels);
}

public void SetSpringPause(bool paused)
{
if (!_hasVrmInstance)
{
return;
}
//set spring bone paused state
_modelLevels = new BlittableModelLevel(externalForce: _modelLevels.ExternalForce,
stopSpringBoneWriteback: paused,
supportsScalingAtRuntime: _modelLevels.SupportsScalingAtRuntime);
//push model level changes to VRM runtime
VrmInstance.Runtime.SpringBone.SetModelLevel(VrmInstance.transform, _modelLevels);
}

public override void OnChartEvent(ChartEvent e)
{

Expand Down