示例#1
0
        protected override void OnEnabledInSimulation()
        {
            if (!Init(0))
            {
                ScreenMessages.Add("Error: init failed");
                this.Dispose();
            }

            PSMoveConnectionType conn = this.ConnectionType;

            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                ScreenMessages.Add("Error: Disconnect USB, only bluetooth");
                this.Dispose();
            }


            InitOrientation();
            ResetOrientation();

            // Start all controllers with a white LED
            SetLED(new Color(0f, 0.9f, 0f));
            SetRumble(0);
            ScreenMessages.Add("init OK");
            initok = true;
            base.OnEnabledInSimulation();
        }
    // 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);
    }
示例#8
0
    private void PairOneController(int id)
    {
        IntPtr controller = psmove_connect_by_id(id);

        if (controller == IntPtr.Zero)
        {
            ErrorText("Error! Controller " + id + " did not connect.");
            return;
        }

        PSMoveConnectionType ctype = psmove_connection_type(controller);

        if (ctype == PSMoveConnectionType.USB)          // This avoids trying to pair any Bluetooth-connected controller objects
        {
            numUSBConnections++;
            if (psmove_pair(controller) == 0)
            {
                ErrorText("Error! Controller " + id + " failed to pair.");
                return;
            }
        }
    }
示例#9
0
    void Start()
    {
        style = new GUIStyle();
        style.normal.textColor = Color.black;

        int count = MoveManager.GetNumConnected();

        for (int i = 0; i < count; i++)
        {
            MoveManager move = gameObject.AddComponent <MoveManager>();

            if (!move.Init(i))
            {
                Destroy(move);
                continue;
            }

            PSMoveConnectionType conn = move.ConnectionType;

            if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
            {
                Destroy(move);
            }
            else
            {
                moves.Add(move);
                move.OnControllerDisconnected += HandleControllerDisconnected;
                move.SetLED(Color.cyan);

                DisplayedPosition = new Vector3(0.0f, 1.0f, 0.0f);
                TransformMatrix   = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);

                // The proposed algorithm’s adjustable parameter, ß, was set to 0.033 for the MARG
                // implementation and 0.041 for the IMU implementation.
                //AHRS = new AHRS.MadgwickAHRS(1f / 75f, 0.1f);
                AHRS = new AHRS.MadgwickAHRS(1f / 75f, 0.033f);
            }
        }
    }
    // 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
    }
示例#11
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.");
        }
    }
示例#12
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);
            }
        }
    }
示例#13
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;
    }