forked from cjacobwade/HelpfulScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlendShapeController.cs
46 lines (40 loc) · 1.26 KB
/
BlendShapeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// File #1
// Put this in BlendShapeController.cs
using UnityEngine;
[RequireComponent(typeof(SkinnedMeshRenderer))]
public class BlendShapeController : MonoBehaviour
{
SkinnedMeshRenderer _skinnedMeshRenderer = null;
public SkinnedMeshRenderer skinnedMeshRenderer
{
get
{
if ( !_skinnedMeshRenderer )
{
_skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
}
return _skinnedMeshRenderer;
}
}
}
// File #2
// Put this in BlendShapeControllerEditor.cs in Assets/Scripts/Editor folder
using UnityEngine;
using UnityEditor;
[CustomEditor( typeof( BlendShapeController ) )]
public class BlendShapeControllerEditor : Editor
{
public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();
BlendShapeController blendShapeController = (BlendShapeController)target;
Mesh blendMesh = blendShapeController.skinnedMeshRenderer.sharedMesh;
int blendShapeCount = blendMesh.blendShapeCount;
for( int i = 0; i < blendShapeCount; i++ )
{
float currentBlendWeight = blendShapeController.skinnedMeshRenderer.GetBlendShapeWeight( i );
float setBlendWeight = EditorGUILayout.Slider( blendMesh.GetBlendShapeName( i ), currentBlendWeight, 0f, 100f );
blendShapeController.skinnedMeshRenderer.SetBlendShapeWeight( i, setBlendWeight );
}
}
}