예제 #1
0
        void Start()
        {
            if (virtualCursor == null)
            {
                try
                {
                    Debug.Log("Looking for Virtual Cursor automatically.");
                    var vCursor = (VirtualCursor)GameObject.FindObjectsOfType(typeof(VirtualCursor))[0];
                    virtualCursor = vCursor;
                }

                catch
                {
                    Debug.LogError("There isn't any Virtual Cursor component in the scene. Add one, otherwise it won't work");
                }
            }
        }
예제 #2
0
        void Start()
        {
            checkerScript = gameObject.GetComponent <GamepadChecker>();

            if (virtualCursor == null)
            {
                try
                {
                    Debug.Log("Looking for Virtual Cursor automatically.");
                    var vCursor = (VirtualCursor)GameObject.FindObjectsOfType(typeof(VirtualCursor))[0];
                    virtualCursor = vCursor;
                }

                catch
                {
                    Debug.LogError("There isn't any Virtual Cursor component in the scene. Add one, otherwise it won't work");
                }
            }

            // We're doing this since unity layout group could be buggy while using content size fitter
            for (int i = 0; i < gamepadObjects.Count; i++)
            {
                gamepadObjects[i].SetActive(true);
            }

            for (int i = 0; i < gamepadObjects.Count; i++)
            {
                gamepadObjects[i].SetActive(false);
            }

            for (int i = 0; i < keyboardObjects.Count; i++)
            {
                keyboardObjects[i].SetActive(true);
            }

            for (int i = 0; i < keyboardObjects.Count; i++)
            {
                keyboardObjects[i].SetActive(false);
            }

            string[] names = Input.GetJoystickNames();

            for (int x = 0; x < names.Length; x++)
            {
                if (names[x].Length >= 1)
                {
                    gamepadConnected = 1;
                }

                else if (names[x].Length == 0)
                {
                    gamepadConnected = 0;
                }
            }

            if (gamepadConnected == 1)
            {
                SwitchToController();
            }

            else if (gamepadConnected == 0)
            {
                SwitchToKeyboard();
            }

            if (alwaysSearch == false)
            {
                checkerScript.enabled = false;
            }

            else
            {
                checkerScript.enabled = true;
                Debug.Log("Always Search is on. Input device will be updated in case of disconnecting/connecting.");
            }
        }