private bool UpdateKeyCode(SerializedProperty property, InputInfoElement pDrawTarget) { Event pCurrentEvent = Event.current; if (pCurrentEvent == null) { return(false); } if ((pCurrentEvent.type == EventType.KeyDown || pCurrentEvent.type == EventType.MouseDown) == false) { return(false); } KeyCode eKeycode = pCurrentEvent.keyCode; if (eKeycode != KeyCode.None) { pDrawTarget.eKeyCode = eKeycode; property.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(property.serializedObject.targetObject); return(true); } return(false); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { InputInfoElement pDrawTarget = EditorCodeHelper.GetTargetObjectOfProperty(property) as InputInfoElement; position.height = EditorCodeHelper.singleLineHeight; property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, "Input: " + pDrawTarget.IRelateByOther_GetDisplayName()); if (property.isExpanded == false) { return; } position.y += EditorCodeHelper.singleLineHeight; EditorCodeHelper.PropertyField(position, property.FindPropertyRelative(nameof(pDrawTarget.eInputInfoType)), "InputType"); position.y += EditorCodeHelper.singleLineHeight; if (pDrawTarget.eInputInfoType == InputInfoElement.EInputInfoType.GetAxis) { var listInput = InputSetting.GetInput_ValueDropDownList(); pDrawTarget.strInputAxisName = EditorCodeHelper.DrawEnumPopup(position, "Select Input", pDrawTarget.strInputAxisName, listInput); position.y += EditorCodeHelper.singleLineHeight; } else if (pDrawTarget.IsMouseInput()) { EditorCodeHelper.PropertyField(position, property.FindPropertyRelative(nameof(pDrawTarget.eMouseButtonType)), "Mouse"); position.y += EditorCodeHelper.singleLineHeight; } else { float fOriginX = position.x; float fOriginWidth = position.width; position.width *= 0.5f; position.x += position.width; var pKeyCodeProperty = property.FindPropertyRelative(nameof(pDrawTarget.eKeyCode)); if (pKeyCodeProperty.isExpanded) // Is Recording.. { if (UpdateKeyCode(property, pDrawTarget)) { pKeyCodeProperty.isExpanded = false; } if (GUI.Button(position, "Cancel Recording..")) { pKeyCodeProperty.isExpanded = false; } } else { if (GUI.Button(position, "Record KeyCode")) { pKeyCodeProperty.isExpanded = true; } } position.x = fOriginX; position.width = fOriginWidth; position.y += EditorCodeHelper.singleLineHeight; pKeyCodeProperty.intValue = (int)pDrawTarget.eKeyCode; EditorCodeHelper.PropertyField(position, pKeyCodeProperty, "KeyCode"); position.y += EditorCodeHelper.singleLineHeight; } EditorCodeHelper.PropertyField(position, property.FindPropertyRelative(nameof(pDrawTarget.bAlwaysInput)), "Is Always Input"); position.y += EditorCodeHelper.singleLineHeight; }