예제 #1
0
        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);
        }
예제 #2
0
파일: Controls.cs 프로젝트: popcron/input
        public static bool GetButtonUp(string name, int joyStick = 0)
        {
            if (!Enabled)
            {
                return(false);
            }

            return(ControlsManager.GetButtonUp(name, joyStick));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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
        }
예제 #6
0
 private void OnEnable()
 {
     manager = target as ControlsManager;
 }
예제 #7
0
 private void OnEnable()
 {
     Map = map;
     DefaultController = defaultController;
     instance          = this;
 }
예제 #8
0
 private void Awake()
 {
     instance = this;
 }