InputModuleSwitchActiveEditor.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEditor.AnimatedValues;
  4. using Rokid.UXR.Interaction;
  5. namespace Rokid.UXR.Editor
  6. {
  7. [CustomEditor(typeof(InputModuleSwitchActive))]
  8. public class InputModuleSwitchActiveEditor : UnityEditor.Editor
  9. {
  10. SerializedProperty activeModuleType;
  11. SerializedProperty handActiveDetail;
  12. SerializedProperty behaviour;
  13. AnimBool showHandInfo;
  14. private void OnEnable()
  15. {
  16. activeModuleType = serializedObject.FindProperty("activeModuleType");
  17. handActiveDetail = serializedObject.FindProperty("handActiveDetail");
  18. behaviour = serializedObject.FindProperty("behaviour");
  19. showHandInfo = new AnimBool(Repaint);
  20. #if UNITY_2021_3_OR_NEWER
  21. SetAnimBools(true);
  22. #endif
  23. }
  24. void SetAnimBool(AnimBool a, bool value, bool instant)
  25. {
  26. if (instant)
  27. a.value = value;
  28. else
  29. a.target = value;
  30. }
  31. #if UNITY_2021_3_OR_NEWER
  32. void SetAnimBools(bool instant)
  33. {
  34. SetAnimBool(showHandInfo, !activeModuleType.hasMultipleDifferentValues && Contain(activeModuleType.enumValueFlag, (int)ActiveModuleType.Gesture), instant);
  35. }
  36. #endif
  37. private bool Contain(int inData, int targetData)
  38. {
  39. return (inData & targetData) == targetData;
  40. }
  41. public override void OnInspectorGUI()
  42. {
  43. #if UNITY_2021_3_OR_NEWER
  44. SetAnimBools(false);
  45. serializedObject.Update();
  46. EditorGUILayout.PropertyField(activeModuleType);
  47. if (EditorGUILayout.BeginFadeGroup(showHandInfo.faded))
  48. {
  49. EditorGUI.indentLevel++;
  50. EditorGUILayout.PropertyField(handActiveDetail);
  51. EditorGUI.indentLevel--;
  52. }
  53. EditorGUILayout.EndFadeGroup();
  54. EditorGUILayout.PropertyField(behaviour);
  55. EditorGUILayout.Space();
  56. serializedObject.ApplyModifiedProperties();
  57. #else
  58. base.OnInspectorGUI();
  59. #endif
  60. }
  61. }
  62. }