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