Skip to content

Commit

Permalink
AnimatePhysBonesの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
pandrabox committed Sep 16, 2024
1 parent 07b1d75 commit dc472a1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Editor/AnimatePhysBones.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <copyright file="AnimatePhysBones.cs"></copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using com.github.pandrabox.emoteprefab.editor;
using com.github.pandrabox.emoteprefab.runtime;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
using nadena.dev.ndmf;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDKBase;
using static com.github.pandrabox.emoteprefab.runtime.Generic;

namespace com.github.pandrabox.emoteprefab.editor
{
/// <summary>
/// PhysBoneのIsAnimatedを必要に応じtrueにする
/// </summary>
public class AnimatePhysBones
{
public AnimatePhysBones()
{
VRCPhysBone[] targetPhysBones;
if (EmoteManager.HasAnimateAllPhysBones)
{
targetPhysBones = Avatar.RootTransform.GetComponentsInChildren<VRCPhysBone>(true);
}
else
{
targetPhysBones = EmoteManager.AnimatePhysBones;
}
foreach(var targetPhysBone in targetPhysBones)
{
targetPhysBone.isAnimated= true;
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/AnimatePhysBones.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Editor/EmoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Dynamics.PhysBone.Components;
using static com.github.pandrabox.emoteprefab.runtime.Generic;

namespace com.github.pandrabox.emoteprefab.editor
Expand Down Expand Up @@ -242,6 +243,26 @@ public static int AFKCount
}
}

public static bool HasAnimateAllPhysBones
{
get
{
return EmotePrefabs.Where(emote => emote.AnimateAllPhysBones).Any();
}
}

public static VRCPhysBone[] AnimatePhysBones
{
get
{
return EmotePrefabs
.Where(prefab => prefab.AnimatePhysBones != null) // nullチェック
.SelectMany(prefab => prefab.AnimatePhysBones.Where(bone => bone != null))
.Distinct()
.ToArray();
}
}

/// <summary>
/// 有効性確認
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Editor/EmotePrefabPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void Run(VRCAvatarDescriptor avatarDescriptor)
new LayerCreater();
new ExpressionCreater();
new AFKLayer();
new AnimatePhysBones();
}
}
}
Expand Down

1 comment on commit dc472a1

@pandrabox
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close #8

Please sign in to comment.