Skip to content

Commit

Permalink
fix: fix entry animation not playing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Naraenda committed Jul 5, 2024
1 parent 27e9988 commit 5237074
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ public override void OnInspectorGUI()
var animObject = (SyncedAnimation)anim.boxedValue;
if (animObject.audio.audioType != AudioType.Youtube)
continue;
if (animObject.audio.audioClip != null)
if (animObject.audio.audioClip)
continue;
if (animObject.animationClip == null)
if (!animObject.animationClip)
continue;

anim.FindPropertyRelative("audio").FindPropertyRelative("audioClip").boxedValue = DownloadManager.DownloadYouTubeLink(animObject);
Expand Down Expand Up @@ -541,7 +541,7 @@ private void GenerateSendLayer()
var exitMusicState = _sendLayer.NewState($"Exit Music {currentSyncedAnimation.name}");

// Set the audio clip on the audio source
if (currentSyncedAnimation.entry.audio.audioClip != null)
if (currentSyncedAnimation.entry.audio.audioClip)
{
entryMusicState.Audio(_audioSource, (a) =>
{
Expand All @@ -552,7 +552,7 @@ private void GenerateSendLayer()
a.SetsVolume(0);
});
}
if (currentSyncedAnimation.loop.audio.audioClip != null)
if (currentSyncedAnimation.loop.audio.audioClip)
{
loopMusicState.Audio(_audioSource, (a) =>
{
Expand All @@ -563,7 +563,7 @@ private void GenerateSendLayer()
a.SetsVolume(currentSyncedAnimation.loop.audio.volume);
});
}
if (currentSyncedAnimation.exit.audio.audioClip != null)
if (currentSyncedAnimation.exit.audio.audioClip)
{
exitMusicState.Audio(_audioSource, (a) =>
{
Expand Down Expand Up @@ -598,21 +598,22 @@ void ToggleBits(AacFlEditClip a)
volume.WithUnit(AacFlUnit.Seconds, (AacFlSettingKeyframes key) => {
key.Linear(0.0f, 0.0f);
key.Linear(0.2f, currentSyncedAnimation.entry.audio.volume);
if (currentSyncedAnimation.entry.animationClip)
key.Linear(currentSyncedAnimation.entry.animationClip.length, currentSyncedAnimation.entry.audio.volume);
});
}));
loopMusicState.WithAnimation(toggleClip);
exitMusicState.WithAnimation(toggleClip);

var len = 0f;
if (currentSyncedAnimation.entry.animationClip != null)
len = currentSyncedAnimation.entry.animationClip.length;
entryMusicState.TransitionsTo(loopMusicState).Automatically().WithTransitionDurationSeconds(len);

// anim entry (with early exit)
entryMusicState.TransitionsTo(exitMusicState).When(_paramSendAnimId.IsNotEqualTo(i));
entryMusicState.TransitionsTo(loopMusicState).Automatically();

// anim loop
loopMusicState.TransitionsTo(exitMusicState).When(_paramSendAnimId.IsNotEqualTo(i));

if (currentSyncedAnimation.exit.animationClip != null)
len = currentSyncedAnimation.exit.animationClip.length;
exitMusicState.TransitionsTo(exitState).Automatically().WithTransitionDurationSeconds(len);

// anim exit
exitMusicState.TransitionsTo(exitState).Automatically();
}
}

Expand Down Expand Up @@ -650,6 +651,7 @@ private void GenerateReceiveLayer()
{
var loopState = parent.NewState("loopState");
var exitState = parent.NewState("exitState");
entryState.TransitionsTo(exitState).When(param.ExitCondition);
entryState.TransitionsTo(loopState).Automatically();
loopState.TransitionsTo(exitState).When(param.ExitCondition);
exitState.Exits().Automatically();
Expand All @@ -674,11 +676,11 @@ private void GenerateReceiveLayer()
loopState.State.iKOnFeet = item.loop.animationUseFootIK;
exitState.State.iKOnFeet = item.exit.animationUseFootIK;

if (item.entry.animationClip != null)
if (item.entry.animationClip)
entryState.WithAnimation(item.entry.animationClip);
if (item.loop.animationClip != null)
if (item.loop.animationClip)
loopState.WithAnimation(item.loop.animationClip);
if (item.exit.animationClip != null)
if (item.exit.animationClip)
exitState.WithAnimation(item.exit.animationClip);
}
}
Expand All @@ -688,7 +690,7 @@ private void Generate()
// Destroy children >:)
// TODO: add method to keep certain objects for e.g. props that may be used
var contactContainer = _self.transform.Find("OSD_Contacts")?.gameObject;
while (contactContainer != null) {
while (contactContainer) {
DestroyImmediate(contactContainer);
contactContainer = _self.transform.Find("OSD_Contacts")?.gameObject;
}
Expand Down Expand Up @@ -740,7 +742,7 @@ private T CreateOrLoadAsset<T>(string path)
where T : ScriptableObject
{
var asset = AssetDatabase.LoadAssetAtPath<T>(path);
if (asset != null)
if (asset)
return asset;

asset = CreateInstance<T>();
Expand Down

0 comments on commit 5237074

Please sign in to comment.