GetNumConnected() публичный статический Метод

Static function that returns the number of *all* controller connections. This count will tally both USB and Bluetooth connections. Note that one physical controller, then, might register multiple connections. To discern between different connection types, see the ConnectionType property below.
public static GetNumConnected ( ) : int
Результат int
Пример #1
0
    void Start()
    {
        nodes     = new List <Node>();
        attackers = new List <Attacker>();
        targets   = new List <Target>();

        InitSetup();
        setupInited = true;

        int count = UniMoveController.GetNumConnected();

        Debug.Log("Controllers connected: " + count);

        if (count == 0)
        {
            count = 6;             // debug mode
        }

        for (int i = 0; i < count; i++)
        {
            Node node = Instantiate(nodePrefab);
            nodes.Add(node);

            node.transform.SetParent(this.transform);
        }

        phase = Phase.Connecting;
    }
    // Use this for initialization
    void Awake()
    {
        client = new OSCClient(IPAddress.Parse(Host), port + droneIndex);
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        Debug.Log(count);
        // Iterate through all connections (USB and Bluetooth)
        if (moves.Count == 0)
        {
            for (int i = 0; i < count; i++)
            {
                UniMoveController move = gameObject.AddComponent <UniMoveController> ();                 // It's a MonoBehaviour, so we can't just call a constructor

                // Remember to initialize!
                if (!move.Init(i))
                {
                    Destroy(move);                       // If it failed to initialize, destroy and continue on
                    continue;
                }

                // This example program only uses Bluetooth-connected controllers
                PSMoveConnectionType conn = move.ConnectionType;
                if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
                {
                    Destroy(move);
                }
                else
                {
                    moves.Add(move);
                    move.OnControllerDisconnected += HandleControllerDisconnected;
                }
            }
        }
    }
Пример #3
0
    public void Init()
    {
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        Debug.Log(UniMoveController.GetNumConnected() + " controllers connected");

        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;
            }
        }
    }
    void Start()
    {
        this.transform.parent        = GameObject.Find("RightHandMiddle4").transform;
        this.transform.localPosition = Vector3.zero;
        Time.maximumDeltaTime        = 0.1f;
        audioSource      = (AudioSource)gameObject.AddComponent("AudioSource");
        audioSource.clip = audioClip;
        audioSource.loop = false;

        handPoint = GameObject.Find("PSMoveController");
        //handPoint.transform.position = GameObject.Find("23_Hand_Right").transform.position + psmoveVec;
        //handPoint.transform.parent = GameObject.Find("23_Hand_Right").transform;
        //handPoint.rigidbody.isKinematic = true;


        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
                Debug.Log(count);
            }
        }

        orig = handPoint.renderer.material.color;
        moves[0].SetLED(Color.red);
    }
Пример #5
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */

        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        Debug.Log("count = " + count);

        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();  // It's a MonoBehaviour, so we can't just call a constructor
            move.CameraPosition = "Back";


            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);  // If it failed to initialize, destroy and continue on
                continue;
            }


            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;

            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);
                move.ResetOrientation();

                sphere.GetComponent <SphereController>().Move = move;
                sphere.GetComponent <SphereController>().AlternativeStart();
            }
        }
    }
Пример #6
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */
        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
            }
        }
        if (moves.Count <= 0)
        {
            Debug.Log("No Bluetooth-connected controllers found. Make sure one or more are both paired and connected to this computer.");
        }
    }
Пример #7
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */

        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        Debug.Log("count = " + count);

        move = gameObject.AddComponent <UniMoveController>();  // It's a MonoBehaviour, so we can't just call a constructor
        move.CameraPosition = "Front";

        // Remember to initialize!
        if (!move.Init(0))  // <F> 0 es el primer y único mando
        {
            Destroy(move);  // If it failed to initialize, destroy and continue on
        }

        // This example program only uses Bluetooth-connected controllers
        PSMoveConnectionType conn = move.ConnectionType;

        if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
        {
            Destroy(move);
        }
        else
        {
            // Start all controllers with a white LED
            move.SetLED(Color.magenta);

            transform.localRotation = move.Orientation;
            transform.localPosition = move.Position;
        }

        Debug.Log(gameObject.tag);
    }
    // Use this for initialization
    void Start()
    {
        // Keep the updates coming at 10Hz
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                // Start all controllers with a white LED
                move.SetLED(Color.grey);
            }
        }

//		rightSensorFusion = new AHRS.MahonyAHRS(Time.deltaTime); // Assume 60Hz update rate
    }
Пример #9
0
    void Start()
    {
        arrow.transform.position = new Vector3(leftBorder, 0.487829f, 0);

        /* Increase Gravity */
        Physics.gravity = new Vector3(0, -20, 0);
        Player          = GameObject.Find("Player");

        varDifficulty = GameObject.Find("varDifficulty");
        if (varDifficulty != null)
        {
            difficulty = int.Parse(varDifficulty.GetComponent <GUIText> ().text);
        }
        else
        {
            difficulty = 3;
        }

        switch (difficulty)
        {
        case 1: arrowSpeed = 0.001f; break;

        case 2: arrowSpeed = 0.002f; break;

        case 3: arrowSpeed = 0.003f; break;

        case 4: arrowSpeed = 0.004f; break;
        }

        //TimerHUD = GameObject.Find("TimerHUD");
        //timerScript = (TimerScript) TimerHUD.GetComponent(typeof(TimerScript));
        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (!move.Init(i))   // TENTA INICIALIZAR
            {                    // QUANDO RESTARTA O PROGRAMA ELE TENTA INICIALIZAR E NAO CONSEGUE PQ JA ESTA INICIADO
                // ENTAO ELE DESTROI AS CONEXOES ABERTAS
                // E POR ISSO DESLIGA O CONTROLE
                // === EU ACHO... ===
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                // Start all controllers with a white LED
                move.SetLED(Color.white);
                Debug.Log("PSMove conectado.");
            }
        }
        if (moves.Count <= 0)
        {
            Debug.Log("No Bluetooth-connected controllers found. Make sure one or more are both paired and connected to this computer.");
        }
    }
Пример #10
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */
        Time.maximumDeltaTime = 0.1f;

        moveControllerPrefab = GameObject.Find("MoveController");
        Destroy(moveControllerPrefab);
        if (moveControllerPrefab == null || moveControllerPrefab.GetComponent <MoveController>() == null)
        {
            Debug.LogError("GameObject with object named \"MoveController\" with script MoveController is missing from the scene");
        }



        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor


            // Remember to initialize!
            if (!move.Init(i))
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }



            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown)            // || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);

                move.OnControllerDisconnected += HandleControllerDisconnected;

                move.InitOrientation();
                move.ResetOrientation();

                // Start all controllers with a white LED
                move.SetLED(Color.white);

                // adding the MoveController Objects on screen
                GameObject moveController = GameObject.Instantiate(moveControllerPrefab,
                                                                   Vector3.right * count * 2 + Vector3.left * i * 4, Quaternion.identity) as GameObject;
                MoveController moveObj = moveController.GetComponent <MoveController>();
                moveObjs.Add(moveObj);
                moveObj.SetLED(Color.white);
            }
        }
    }
Пример #11
0
    void Start()
    {
        /* NOTE! We recommend that you limit the maximum frequency between frames.
         * This is because the controllers use Update() and not FixedUpdate(),
         * and yet need to update often enough to respond sufficiently fast.
         * Unity advises to keep this value "between 1/10th and 1/3th of a second."
         * However, even 100 milliseconds could seem slightly sluggish, so you
         * might want to experiment w/ reducing this value even more.
         * Obviously, this should only be relevant in case your framerare is starting
         * to lag. Most of the time, Update() should be called very regularly.
         */

        // If you have changed these names, please replace below "names"

        /*Left = GameObject.Find("LeftWall");
        *  Right = GameObject.Find("RightWall");
        *  Racket = GameObject.Find("Racket");*/
        try {
            Sword       = GameObject.Find("Sword");
            Light       = GameObject.Find("VolumetricLinePrefab");
            Player      = GameObject.Find("player");
            EnemyMaster = GameObject.Find("EnemyMaster");
            Unitychan   = GameObject.Find("unitychan");
            Cube        = GameObject.Find("Cube");
            Enemy0      = GameObject.Find("Enemy0");
            Enemy1      = GameObject.Find("Enemy1");
            Camera      = GameObject.Find("Main Camera");
            text        = GameObject.Find("Text").GetComponent <Text>();
            animator    = Unitychan.GetComponent <Animator>();
            rb          = Unitychan.GetComponent <Rigidbody>();
            opening     = true;
            countdown   = false;
            playing     = false;
            gameover    = false;
            clear       = false;
        } catch (Exception e) {
            Debug.Log("exception");
        }

        Light.SetActive(false);
        Sword.SetActive(false);
        Player.SetActive(false);
        EnemyMaster.SetActive(false);
        Enemy0.SetActive(false);
        Enemy1.SetActive(false);
        Unitychan.SetActive(false);
        Cube.SetActive(false);


        _Style          = new GUIStyle();
        _Style.fontSize = 20;

        Time.maximumDeltaTime = 0.1f;

        int count = UniMoveController.GetNumConnected();

        // Iterate through all connections (USB and Bluetooth)
        for (int i = 0; i < count; i++)
        {
            UniMoveController move = gameObject.AddComponent <UniMoveController>();             // It's a MonoBehaviour, so we can't just call a constructor

            // Remember to initialize!
            if (move.Init(i) == PSMove_Connect_Status.MoveConnect_NoData)
            {
                Destroy(move);                  // If it failed to initialize, destroy and continue on
                continue;
            }

            // This example program only uses Bluetooth-connected controllers
            PSMoveConnectionType conn = move.ConnectionType;
            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                _Moves.Add(move);
                move.OnControllerDisconnected += HandleControllerDisconnected;

                // 球体LEDの基本セッティング 赤色
                move.SetLED(Color.red);
            }
        }
        _TimeCount = Time.time;
    }
Пример #12
0
    // Update is called once per frame
    void Update()
    {
        if (phase == Phase.Connecting)
        {
            bool allConnected = true;
            for (int i = 0; i < nodes.Count; i++)
            {
                if (UniMoveController.GetNumConnected() > 0)
                {
                    if (nodes[i].controller == null)
                    {
                        UniMoveController controller = nodes[i].gameObject.AddComponent <UniMoveController>();
                        if (controller.Init(i))
                        {
                            controller.InitOrientation();
                            controller.ResetOrientation();
                            nodes[i].Init(controller, this.debugButtons[i]);
                        }
                        else
                        {
                            Destroy(controller);
                            allConnected = false;
                        }
                    }
                }
                else
                {
                    nodes[i].InitDebug(i <= 1?1:2, this.debugButtons[i]);
                }
            }

            if (allConnected)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].type == 1)
                    {
                        Target target = nodes[i].gameObject.AddComponent <Target>();
                        target.HitEvent += OnTargetHit;
                        targets.Add(target);
                    }
                    else
                    {
                        Attacker attacker = nodes[i].gameObject.AddComponent <Attacker>();
                        attacker.HitEvent            += OnAttackerHit;
                        attacker.TimeoutEvent        += OnAttackerTimeout;
                        attacker.TimeoutWarningEvent += OnAttackerTimeoutWarning;
                        attackers.Add(attacker);
                    }
                }

                phase = Phase.Waiting;
            }
        }

        else if (phase == Phase.Waiting)
        {
            // start game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                bool practice = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                StartGame(practice);
            }
        }

        else if (phase == Phase.Playing)
        {
            // stop game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                StopGame();
            }

            // heal
            if (Input.GetKeyDown(KeyCode.H))
            {
                Heal();
            }
        }

        else if (phase == Phase.Ended)
        {
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            //ControllerDebug.Active = !ControllerDebug.Active;
            debugPanel.SetActive(!debugPanel.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            setupPanel.SetActive(!setupPanel.activeSelf);
        }
    }