multiple xr toolkit package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VRCAvatarDescriptorEditor.cs 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. [CustomEditor(typeof(VRCSDK2.VRC_AvatarDescriptor))]
  6. public class AvatarDescriptorEditor : Editor
  7. {
  8. VRCSDK2.VRC_AvatarDescriptor avatarDescriptor;
  9. VRC.Core.PipelineManager pipelineManager;
  10. SkinnedMeshRenderer selectedMesh;
  11. List<string> blendShapeNames = null;
  12. public override void OnInspectorGUI()
  13. {
  14. if (avatarDescriptor == null)
  15. avatarDescriptor = (VRCSDK2.VRC_AvatarDescriptor)target;
  16. if (pipelineManager == null)
  17. {
  18. pipelineManager = avatarDescriptor.GetComponent<VRC.Core.PipelineManager>();
  19. if (pipelineManager == null)
  20. avatarDescriptor.gameObject.AddComponent<VRC.Core.PipelineManager>();
  21. }
  22. // DrawDefaultInspector();
  23. if(VRCSdkControlPanel.window != null)
  24. {
  25. if( GUILayout.Button( "Select this avatar in the SDK control panel" ) )
  26. VRCSdkControlPanel.SelectAvatar(avatarDescriptor);
  27. }
  28. avatarDescriptor.ViewPosition = EditorGUILayout.Vector3Field("View Position", avatarDescriptor.ViewPosition);
  29. //avatarDescriptor.Name = EditorGUILayout.TextField("Avatar Name", avatarDescriptor.Name);
  30. avatarDescriptor.Animations = (VRCSDK2.VRC_AvatarDescriptor.AnimationSet)EditorGUILayout.EnumPopup("Default Animation Set", avatarDescriptor.Animations);
  31. avatarDescriptor.CustomStandingAnims = (AnimatorOverrideController)EditorGUILayout.ObjectField("Custom Standing Anims", avatarDescriptor.CustomStandingAnims, typeof(AnimatorOverrideController), true, null);
  32. avatarDescriptor.CustomSittingAnims = (AnimatorOverrideController)EditorGUILayout.ObjectField("Custom Sitting Anims", avatarDescriptor.CustomSittingAnims, typeof(AnimatorOverrideController), true, null);
  33. avatarDescriptor.ScaleIPD = EditorGUILayout.Toggle("Scale IPD", avatarDescriptor.ScaleIPD);
  34. avatarDescriptor.lipSync = (VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle)EditorGUILayout.EnumPopup("Lip Sync", avatarDescriptor.lipSync);
  35. switch (avatarDescriptor.lipSync)
  36. {
  37. case VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.Default:
  38. if (GUILayout.Button("Auto Detect!"))
  39. AutoDetectLipSync();
  40. break;
  41. case VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.JawFlapBlendShape:
  42. avatarDescriptor.VisemeSkinnedMesh = (SkinnedMeshRenderer)EditorGUILayout.ObjectField("Face Mesh", avatarDescriptor.VisemeSkinnedMesh, typeof(SkinnedMeshRenderer), true);
  43. if (avatarDescriptor.VisemeSkinnedMesh != null)
  44. {
  45. DetermineBlendShapeNames();
  46. int current = -1;
  47. for (int b = 0; b < blendShapeNames.Count; ++b)
  48. if (avatarDescriptor.MouthOpenBlendShapeName == blendShapeNames[b])
  49. current = b;
  50. string title = "Jaw Flap Blend Shape";
  51. int next = EditorGUILayout.Popup(title, current, blendShapeNames.ToArray());
  52. if (next >= 0)
  53. avatarDescriptor.MouthOpenBlendShapeName = blendShapeNames[next];
  54. }
  55. break;
  56. case VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.JawFlapBone:
  57. avatarDescriptor.lipSyncJawBone = (Transform)EditorGUILayout.ObjectField("Jaw Bone", avatarDescriptor.lipSyncJawBone, typeof(Transform), true);
  58. break;
  59. case VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.VisemeBlendShape:
  60. avatarDescriptor.VisemeSkinnedMesh = (SkinnedMeshRenderer)EditorGUILayout.ObjectField("Face Mesh", avatarDescriptor.VisemeSkinnedMesh, typeof(SkinnedMeshRenderer), true);
  61. if (avatarDescriptor.VisemeSkinnedMesh != null)
  62. {
  63. DetermineBlendShapeNames();
  64. if (avatarDescriptor.VisemeBlendShapes == null || avatarDescriptor.VisemeBlendShapes.Length != (int)VRCSDK2.VRC_AvatarDescriptor.Viseme.Count)
  65. avatarDescriptor.VisemeBlendShapes = new string[(int)VRCSDK2.VRC_AvatarDescriptor.Viseme.Count];
  66. for (int i = 0; i < (int)VRCSDK2.VRC_AvatarDescriptor.Viseme.Count; ++i)
  67. {
  68. int current = -1;
  69. for (int b = 0; b < blendShapeNames.Count; ++b)
  70. if (avatarDescriptor.VisemeBlendShapes[i] == blendShapeNames[b])
  71. current = b;
  72. string title = "Viseme: " + ((VRCSDK2.VRC_AvatarDescriptor.Viseme)i).ToString();
  73. int next = EditorGUILayout.Popup(title, current, blendShapeNames.ToArray());
  74. if (next >= 0)
  75. avatarDescriptor.VisemeBlendShapes[i] = blendShapeNames[next];
  76. }
  77. }
  78. break;
  79. }
  80. EditorGUILayout.LabelField("Unity Version", avatarDescriptor.unityVersion);
  81. }
  82. void DetermineBlendShapeNames()
  83. {
  84. if (avatarDescriptor.VisemeSkinnedMesh != null &&
  85. avatarDescriptor.VisemeSkinnedMesh != selectedMesh)
  86. {
  87. blendShapeNames = new List<string>();
  88. blendShapeNames.Add("-none-");
  89. selectedMesh = avatarDescriptor.VisemeSkinnedMesh;
  90. for (int i = 0; i < selectedMesh.sharedMesh.blendShapeCount; ++i)
  91. blendShapeNames.Add(selectedMesh.sharedMesh.GetBlendShapeName(i));
  92. }
  93. }
  94. void AutoDetectLipSync()
  95. {
  96. var smrs = avatarDescriptor.GetComponentsInChildren<SkinnedMeshRenderer>();
  97. foreach (var smr in smrs)
  98. {
  99. if (smr.sharedMesh.blendShapeCount > 0)
  100. {
  101. avatarDescriptor.lipSync = VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.JawFlapBlendShape;
  102. avatarDescriptor.VisemeSkinnedMesh = null;
  103. avatarDescriptor.lipSyncJawBone = null;
  104. return;
  105. }
  106. }
  107. if (avatarDescriptor.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.Jaw) != null)
  108. {
  109. avatarDescriptor.lipSync = VRCSDK2.VRC_AvatarDescriptor.LipSyncStyle.JawFlapBone;
  110. avatarDescriptor.lipSyncJawBone = avatarDescriptor.GetComponent<Animator>().GetBoneTransform(HumanBodyBones.Jaw);
  111. avatarDescriptor.VisemeSkinnedMesh = null;
  112. return;
  113. }
  114. }
  115. }