/// <summary> /// デフォルトのEventSystemで扱う入力設定を追加する /// </summary> /// <param name="inputManagerGenerator">Input manager generator.</param> private static void AddStdInputSettings(InputManagerGenerator inputManagerGenerator) { // 横方向 { var name = "Horizontal"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "a", "d", "left", "right")); } // 縦方向 { var name = "Vertical"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "s", "w", "down", "up")); } // 決定 { var name = "Submit"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "", "enter", "", "space")); } // キャンセル { var name = "Cancel"; inputManagerGenerator.AddAxis(InputAxis.CreateKeyAxis(name, "", "escape", "", "joystick button 1")); } }
public void AddAxis(InputAxis axis) { if (axis.axis < 1) { Debug.LogError("Invalid argument value : axis < 1"); } SerializedProperty axesProperty = m_serializedObject.FindProperty("m_Axes"); axesProperty.arraySize++; m_serializedObject.ApplyModifiedProperties(); SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1); GetChildProperty(axisProperty, "m_Name").stringValue = axis.name; GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName; GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; GetChildProperty(axisProperty, "negativeButton").stringValue = axis.negativeButton; GetChildProperty(axisProperty, "positiveButton").stringValue = axis.positiveButton; GetChildProperty(axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; GetChildProperty(axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; GetChildProperty(axisProperty, "gravity").floatValue = axis.gravity; GetChildProperty(axisProperty, "dead").floatValue = axis.dead; GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity; GetChildProperty(axisProperty, "snap").boolValue = axis.snap; GetChildProperty(axisProperty, "invert").boolValue = axis.invert; GetChildProperty(axisProperty, "type").intValue = (int)axis.type; GetChildProperty(axisProperty, "axis").intValue = axis.axis - 1; GetChildProperty(axisProperty, "joyNum").intValue = axis.joyNum; m_serializedObject.ApplyModifiedProperties(); }
/// <summary> /// ゲームパッド用の軸の設定データを作成する /// </summary> public static InputAxis CreatePadAxis(string name, int joystickNum, int axisNum) { var axis = new InputAxis(); axis.name = name; axis.dead = 0.2f; axis.sensitivity = 1; axis.type = AxisType.JoystickAxis; axis.axis = axisNum; axis.joyNum = joystickNum; return(axis); }
/// <summary> /// 押すと1になるキーの設定データを作成する /// </summary> public static InputAxis CreateButton(string name, string positiveButton, string altPositiveButton) { var axis = new InputAxis(); axis.name = name; axis.positiveButton = positiveButton; axis.altPositiveButton = altPositiveButton; axis.gravity = 1000; axis.dead = 0.001f; axis.sensitivity = 1000; axis.type = AxisType.KeyOrMouseButton; return(axis); }
/// <summary> /// プレイヤーごとの入力設定を追加する /// </summary> /// <param name="inputManagerGenerator">Input manager generator.</param> /// <param name="playerIndex">Player index.</param> private static void AddPlayerInputSettingsForXBox(InputManagerGenerator inputManagerGenerator, int playerIndex) { if (playerIndex < 0 || playerIndex > 3) { Debug.LogError("プレイヤーインデックスの値が不正です。"); } int joystickNum = playerIndex + 1; string strIndex = joystickNum.ToString(); // 左スティック { inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.LAxisX + strIndex, joystickNum, 1)); inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.LAxisY + strIndex, joystickNum, 2)); } // 右スティック { inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.RAxisX + strIndex, joystickNum, 4)); inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.RAxisY + strIndex, joystickNum, 5)); } // 十字キー { inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.DPadAxisX + strIndex, joystickNum, 6)); inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.DPadAxisY + strIndex, joystickNum, 7)); } // トリガー { inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.LTrigger + strIndex, joystickNum, 3)); inputManagerGenerator.AddAxis( InputAxis.CreatePadAxis(XVInputConstants.RTrigger + strIndex, joystickNum, 3)); } }