Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

InputActionMapDrawer.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #if UNITY_EDITOR
  2. using System;
  3. using UnityEditor;
  4. using UnityEditor.IMGUI.Controls;
  5. namespace UnityEngine.InputSystem.Editor
  6. {
  7. /// <summary>
  8. /// Property drawer for <see cref="InputActionMap"/>.
  9. /// </summary>
  10. [CustomPropertyDrawer(typeof(InputActionMap))]
  11. internal class InputActionMapDrawer : InputActionDrawerBase
  12. {
  13. protected override TreeViewItem BuildTree(SerializedProperty property)
  14. {
  15. return InputActionTreeView.BuildWithJustActionsAndBindingsFromMap(property);
  16. }
  17. protected override string GetSuffixToRemoveFromPropertyDisplayName()
  18. {
  19. return " Action Map";
  20. }
  21. protected override bool IsPropertyAClone(SerializedProperty property)
  22. {
  23. // When a new item is added to a collection through the inspector, the default behaviour is
  24. // to create a clone of the previous item. Here we look at all InputActionMaps that appear before
  25. // the current one and compare their Ids to determine if we have a clone. We don't look past
  26. // the current item because Unity will be calling this property drawer for each input action map
  27. // in the collection in turn. If the user just added a new input action map, and it's a clone, as
  28. // we work our way down the list, we'd end up thinking that an existing input action map was a clone
  29. // of the newly added one, instead of the other way around. If we do have a clone, we need to
  30. // clear out some properties of the InputActionMap (id, name, input actions, and bindings) and
  31. // recreate the tree view.
  32. if (property?.GetParentProperty() == null || property.GetParentProperty().isArray == false)
  33. return false;
  34. var array = property.GetArrayPropertyFromElement();
  35. var index = property.GetIndexOfArrayElement();
  36. for (var i = 0; i < index; i++)
  37. {
  38. if (property.FindPropertyRelative(nameof(InputActionMap.m_Id))?.stringValue ==
  39. array.GetArrayElementAtIndex(i)?.FindPropertyRelative(nameof(InputActionMap.m_Id))?.stringValue)
  40. return true;
  41. }
  42. return false;
  43. }
  44. protected override void ResetProperty(SerializedProperty property)
  45. {
  46. if (property == null) return;
  47. property.SetStringValue(nameof(InputActionMap.m_Id), Guid.NewGuid().ToString());
  48. property.SetStringValue(nameof(InputActionMap.m_Name), "Input Action Map");
  49. property.FindPropertyRelative(nameof(InputActionMap.m_Actions))?.ClearArray();
  50. property.FindPropertyRelative(nameof(InputActionMap.m_Bindings))?.ClearArray();
  51. property.serializedObject?.ApplyModifiedPropertiesWithoutUndo();
  52. }
  53. }
  54. }
  55. #endif // UNITY_EDITOR