Skip to content

Commit

Permalink
add runtime setup example.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Jan 2, 2023
1 parent ab288c6 commit b766e29
Show file tree
Hide file tree
Showing 12 changed files with 948 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Assets/uLipSync/Runtime/Core/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using UnityEngine;

namespace uLipSync
{

public static class Util
{
public static Transform FindChildRecursively(Transform tform, string name)
{
if (tform.name == name) return tform;

for (int i = 0; i < tform.childCount; i++)
{
var child = tform.GetChild(i);
var result = FindChildRecursively(child, name);
if (result) return result;
}

return null;
}

public static int GetBlendShapeIndex(SkinnedMeshRenderer smr, string name)
{
var mesh = smr.sharedMesh;
for (int i = 0; i < mesh.blendShapeCount; ++i)
{
var bs = mesh.GetBlendShapeName(i);
if (bs == name) return i;
}
return -1;
}
}

}
11 changes: 11 additions & 0 deletions Assets/uLipSync/Runtime/Core/Util.cs.meta

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

1 change: 1 addition & 0 deletions Assets/uLipSync/Runtime/uLipSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void OnDisable()

void Update()
{
if (!profile) return;
if (!_jobHandle.IsCompleted) return;

UpdateResult();
Expand Down
23 changes: 22 additions & 1 deletion Assets/uLipSync/Runtime/uLipSyncBlendShape.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

namespace uLipSync
Expand Down Expand Up @@ -167,6 +166,28 @@ protected virtual void OnApplyBlendShapes()
}
}

public BlendShapeInfo GetBlendShapeInfo(string phoneme)
{
foreach (var info in blendShapes)
{
if (info.phoneme == phoneme) return info;
}
return null;
}

public BlendShapeInfo AddBlendShape(string phoneme, string blendShape)
{
var bs = GetBlendShapeInfo(phoneme);
if (bs == null) bs = new BlendShapeInfo() { phoneme = phoneme };

blendShapes.Add(bs);

if (!skinnedMeshRenderer) return bs;
bs.index = Util.GetBlendShapeIndex(skinnedMeshRenderer, blendShape);

return bs;
}

#if UNITY_EDITOR
public override GameObject target
{
Expand Down
8 changes: 8 additions & 0 deletions Assets/uLipSync/Samples/10. Runtime Setup.meta

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

Loading

0 comments on commit b766e29

Please sign in to comment.