Assignment for RMIT Mixed Reality in 2020
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.

80 lines
2.6 KiB

  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
  4. the Utilities SDK except in compliance with the License, which is provided at the time of installation
  5. or download, or which otherwise accompanies this software in either electronic or hard copy form.
  6. You may obtain a copy of the License at
  7. https://developer.oculus.com/licenses/utilities-1.31
  8. Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
  9. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  10. ANY KIND, either express or implied. See the License for the specific language governing
  11. permissions and limitations under the License.
  12. ************************************************************************************/
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using UnityEngine;
  16. using UnityEditor;
  17. using UnityEditor.SceneManagement;
  18. using BoneId = OVRSkeleton.BoneId;
  19. [CustomEditor(typeof(OVRCustomSkeleton))]
  20. public class OVRCustomSkeletonEditor : Editor
  21. {
  22. public override void OnInspectorGUI()
  23. {
  24. DrawPropertiesExcluding(serializedObject, new string[] { "_customBones" });
  25. serializedObject.ApplyModifiedProperties();
  26. OVRCustomSkeleton skeleton = (OVRCustomSkeleton)target;
  27. OVRSkeleton.SkeletonType skeletonType = skeleton.GetSkeletonType();
  28. if (skeletonType == OVRSkeleton.SkeletonType.None)
  29. {
  30. EditorGUILayout.HelpBox("Please select a SkeletonType.", MessageType.Warning);
  31. }
  32. else
  33. {
  34. if (GUILayout.Button("Auto Map Bones"))
  35. {
  36. skeleton.TryAutoMapBonesByName();
  37. EditorUtility.SetDirty(skeleton);
  38. EditorSceneManager.MarkSceneDirty(skeleton.gameObject.scene);
  39. }
  40. EditorGUILayout.LabelField("Bones", EditorStyles.boldLabel);
  41. BoneId start = skeleton.GetCurrentStartBoneId();
  42. BoneId end = skeleton.GetCurrentEndBoneId();
  43. if (start != BoneId.Invalid && end != BoneId.Invalid)
  44. {
  45. for (int i = (int)start; i < (int)end; ++i)
  46. {
  47. string boneName = BoneLabelFromBoneId((BoneId)i);
  48. skeleton.CustomBones[i] = (Transform)EditorGUILayout.ObjectField(boneName, skeleton.CustomBones[i], typeof(Transform), true);
  49. }
  50. }
  51. }
  52. }
  53. // force aliased enum values to the more appropriate value
  54. private static string BoneLabelFromBoneId(BoneId boneId)
  55. {
  56. if (boneId == BoneId.Hand_Start)
  57. {
  58. return "Hand_WristRoot";
  59. }
  60. else if (boneId == BoneId.Hand_MaxSkinnable)
  61. {
  62. return "Hand_ThumbTip";
  63. }
  64. else
  65. {
  66. return boneId.ToString();
  67. }
  68. }
  69. }