Skip to content

Commit

Permalink
Merge pull request #657 from anatawa12/split-util-for-vrcsdk
Browse files Browse the repository at this point in the history
refactor: split utils for components of VRCSDK
  • Loading branch information
anatawa12 authored Oct 30, 2023
2 parents 3fbcacb + f69e4e9 commit fb7b34c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
29 changes: 29 additions & 0 deletions Editor/Utils/Utils.VRCSDK.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using UnityEngine;
using VRC.Dynamics;

namespace Anatawa12.AvatarOptimizer
{
partial class Utils
{
public static Transform GetTarget(this VRCPhysBoneBase physBoneBase) =>
physBoneBase.rootTransform ? physBoneBase.rootTransform : physBoneBase.transform;

public static IEnumerable<Transform> GetAffectedTransforms(this VRCPhysBoneBase physBoneBase)
{
var ignores = new HashSet<Transform>(physBoneBase.ignoreTransforms);
var queue = new Queue<Transform>();
queue.Enqueue(physBoneBase.GetTarget());

while (queue.Count != 0)
{
var transform = queue.Dequeue();
yield return transform;

foreach (var child in transform.DirectChildrenEnumerable())
if (!ignores.Contains(child))
queue.Enqueue(child);
}
}
}
}
3 changes: 3 additions & 0 deletions Editor/Utils/Utils.VRCSDK.cs.meta

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

22 changes: 0 additions & 22 deletions Editor/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ public static T GetOrAddComponent<T>(this GameObject go) where T : Component
return component;
}

#if AAO_VRCSDK3_AVATARS
public static Transform GetTarget(this VRC.Dynamics.VRCPhysBoneBase physBoneBase) =>
physBoneBase.rootTransform ? physBoneBase.rootTransform : physBoneBase.transform;

public static IEnumerable<Transform> GetAffectedTransforms(this VRC.Dynamics.VRCPhysBoneBase physBoneBase)
{
var ignores = new HashSet<Transform>(physBoneBase.ignoreTransforms);
var queue = new Queue<Transform>();
queue.Enqueue(physBoneBase.GetTarget());

while (queue.Count != 0)
{
var transform = queue.Dequeue();
yield return transform;

foreach (var child in transform.DirectChildrenEnumerable())
if (!ignores.Contains(child))
queue.Enqueue(child);
}
}
#endif

public static GameObject NewGameObject(string name, Transform parent)
{
var rootObject = new GameObject(name);
Expand Down

0 comments on commit fb7b34c

Please sign in to comment.