public static void LoadAllControllers() { //find a controls manager in the scene ControlsManager controlsManager = Object.FindObjectOfType <ControlsManager>(); if (!controlsManager) { controlsManager = new GameObject("ControlsManager").AddComponent <ControlsManager>(); //mark scene dirty Scene activeScene = SceneManager.GetActiveScene(); EditorSceneManager.MarkSceneDirty(activeScene); } controlsManager.Controllers.Clear(); string[] guids = AssetDatabase.FindAssets("t:Popcron.Input.ControllerType"); for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); ControllerType controller = AssetDatabase.LoadAssetAtPath <ControllerType>(path); controlsManager.Controllers.Add(controller); } Controls.Types = controlsManager.Controllers; EditorUtility.SetDirty(controlsManager); }
public static bool GetButtonUp(string name, int joyStick = 0) { if (!Enabled) { return(false); } return(ControlsManager.GetButtonUp(name, joyStick)); }
public static bool GetButton(string name, int joyStick) { if (!instance) { instance = FindObjectOfType <ControlsManager>(); } MapBind bind = instance.map.GetBind(name); if (bind == null) { throw new Exception("Bind for " + name + " doesn't exists in the map."); } if (instance.controllers.Count == 0) { return(false); } if (joyStick < 0 || joyStick >= Controls.MaxControllers) { throw new Exception("JoyStick number " + joyStick + " is out of range."); } if (instance.controllers.Count <= joyStick) { return(false); } Controller controller = instance.controllers[joyStick]; for (int b = 0; b < bind.binds.Count; b++) { //controller check if (controller.GetButton(bind.binds[b])) { return(true); } //for interference checking if (!controller.Contains(bind.binds[b])) { //keyboard check if (Input.GetKey(bind.binds[b])) { return(true); } } } return(false); }
public static void AddController(ControllerType controller) { //find a controls manager in the scene ControlsManager controlsManager = Object.FindObjectOfType <ControlsManager>(); if (!controlsManager) { LoadAllControllers(); return; } controlsManager.Controllers.Add(controller); Controls.Types = controlsManager.Controllers; EditorUtility.SetDirty(controlsManager); }
private void CheckInstances() { #if UNITY_EDITOR ControlsManager otherManager = null; ControlsManager[] managers = FindObjectsOfType <ControlsManager>(); for (int i = 0; i < managers.Length; i++) { if (managers[i] != this) { otherManager = managers[i]; break; } } if (otherManager) { Debug.Log("Another Controls manager instance already exists!"); UnityEditor.EditorGUIUtility.PingObject(otherManager); DestroyImmediate(this); } #endif }
private void OnEnable() { manager = target as ControlsManager; }
private void OnEnable() { Map = map; DefaultController = defaultController; instance = this; }
private void Awake() { instance = this; }