75 lines
1.5 KiB
C#
75 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
|
|
public class JoystickView : MonoBehaviour {
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
}
|
|
|
|
void OnGUI(){
|
|
|
|
DoGui ();
|
|
}
|
|
|
|
public static List<string> GetInputAxis()
|
|
{
|
|
var allAxis = new List<string>();
|
|
|
|
var serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
|
|
var axesProperty = serializedObject.FindProperty("m_Axes");
|
|
|
|
axesProperty.Next(true);
|
|
axesProperty.Next(true);
|
|
while (axesProperty.Next(false))
|
|
{
|
|
SerializedProperty axis = axesProperty.Copy();
|
|
axis.Next(true);
|
|
allAxis.Add(axis.stringValue);
|
|
}
|
|
|
|
return allAxis;
|
|
}
|
|
|
|
void DoGui(){
|
|
var joysticks = Input.GetJoystickNames ();
|
|
|
|
#if UNITY_EDITOR
|
|
Handles.BeginGUI ();
|
|
#endif
|
|
|
|
var axes = GetInputAxis ();
|
|
|
|
float height = 20;
|
|
for (int i = 0; i < axes.Count; ++i) {
|
|
GUI.Label(new Rect(10,i * height + 10, 300,height), string.Format("Axis {0}: {1}", axes[i], Input.GetAxis(axes[i])));
|
|
}
|
|
|
|
for (int i = 0; i < 20; ++i) {
|
|
GUI.Label(new Rect(410,i * height + 10, 300,height), string.Format("Button {0}: {1}", i, Input.GetKey (KeyCode.Joystick1Button0 + i)));
|
|
}
|
|
|
|
|
|
/*foreach(var j in joysticks){
|
|
|
|
//EditorGUILayout.TextField(j);
|
|
}*/
|
|
#if UNITY_EDITOR
|
|
Handles.EndGUI ();
|
|
#endif
|
|
}
|
|
|
|
void OnDrawGizmos(){
|
|
DoGui ();
|
|
}
|
|
}
|