No Description
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.

SerializedInputAction.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
  2. using System;
  3. using UnityEditor;
  4. namespace UnityEngine.InputSystem.Editor
  5. {
  6. internal readonly struct SerializedInputAction
  7. {
  8. public SerializedInputAction(SerializedProperty serializedProperty)
  9. {
  10. // TODO: check that the passed serialized property actually is an InputAction. Reflect over all
  11. // serialized fields and make sure they're present?
  12. wrappedProperty = serializedProperty ?? throw new ArgumentNullException(nameof(serializedProperty));
  13. id = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Id)).stringValue;
  14. name = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue;
  15. expectedControlType = ReadExpectedControlType(serializedProperty);
  16. type = (InputActionType)serializedProperty.FindPropertyRelative(nameof(InputAction.m_Type)).intValue;
  17. interactions = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Interactions)).stringValue;
  18. processors = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Processors)).stringValue;
  19. propertyPath = wrappedProperty.propertyPath;
  20. initialStateCheck = ReadInitialStateCheck(serializedProperty);
  21. actionTypeTooltip = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Type)).GetTooltip();
  22. expectedControlTypeTooltip = serializedProperty.FindPropertyRelative(nameof(InputAction.m_ExpectedControlType)).GetTooltip();
  23. }
  24. public string id { get; }
  25. public string name { get; }
  26. public string expectedControlType { get; }
  27. public InputActionType type { get; }
  28. public string interactions { get; }
  29. public string processors { get; }
  30. public string propertyPath { get; }
  31. public bool initialStateCheck { get; }
  32. public string actionTypeTooltip { get; }
  33. public string expectedControlTypeTooltip { get; }
  34. public SerializedProperty wrappedProperty { get; }
  35. private static string ReadExpectedControlType(SerializedProperty serializedProperty)
  36. {
  37. var controlType = serializedProperty.FindPropertyRelative(nameof(InputAction.m_ExpectedControlType)).stringValue;
  38. if (!string.IsNullOrEmpty(controlType))
  39. return controlType;
  40. var actionType = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Type)).intValue;
  41. return actionType == (int)InputActionType.Button ? "Button" : null;
  42. }
  43. private static bool ReadInitialStateCheck(SerializedProperty serializedProperty)
  44. {
  45. var actionFlags = serializedProperty.FindPropertyRelative(nameof(InputAction.m_Flags));
  46. return (actionFlags.intValue & (int)InputAction.ActionFlags.WantsInitialStateCheck) != 0;
  47. }
  48. public bool Equals(SerializedInputAction other)
  49. {
  50. return name == other.name
  51. && expectedControlType == other.expectedControlType
  52. && type == other.type
  53. && interactions == other.interactions
  54. && processors == other.processors
  55. && initialStateCheck == other.initialStateCheck
  56. && actionTypeTooltip == other.actionTypeTooltip
  57. && expectedControlTypeTooltip == other.expectedControlTypeTooltip
  58. && propertyPath == other.propertyPath;
  59. }
  60. public override bool Equals(object obj)
  61. {
  62. return obj is SerializedInputAction other && Equals(other);
  63. }
  64. public override int GetHashCode()
  65. {
  66. var hashCode = new HashCode();
  67. hashCode.Add(name);
  68. hashCode.Add(expectedControlType);
  69. hashCode.Add((int)type);
  70. hashCode.Add(interactions);
  71. hashCode.Add(processors);
  72. hashCode.Add(initialStateCheck);
  73. hashCode.Add(actionTypeTooltip);
  74. hashCode.Add(expectedControlTypeTooltip);
  75. hashCode.Add(propertyPath);
  76. return hashCode.ToHashCode();
  77. }
  78. }
  79. }
  80. #endif