Example #1
0
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
            Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        }

        createHub ();
    }
Example #2
0
 // Myo game object to connect with.
 // This object must have a ThalmicMyo script attached.
 void Update()
 {
     SoundManager.getInstance().updateSoundManager();
     if (Input.GetKey("escape"))
         Application.Quit();
     thalmicMyo = myo.GetComponent<ThalmicMyo> ();
     hub = ThalmicHub.instance;
     if (Input.GetKeyDown("q"))
     {
         hub.ResetHub();
     }
     //if (
 }
    // Update is called once per frame
    void Update()
    {
        hub = ThalmicHub.instance;

        if(thalmicMyo != null && thalmicMyo.pose.ToString() == "Fist"){
            if(player == null){
                player = GameObject.FindGameObjectWithTag("Player");
            }
                player.animation.Play("punch_hi_left");
        }

        if (Input.GetKeyDown ("q")) {
            hub.ResetHub();
        }
    }
    //private InputMapping;
    // Use this for initialization
    void Start()
    {
        hub = ThalmicHub.instance;
        //myo = GameObject.FindGameObjectWithTag("Player");
        if (myo == null) {
            myo = this.gameObject;
        }

        // Access the ThalmicMyo script attached to the Myo object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        if (thalmicMyo.isPaired) {
            thalmicMyo.Vibrate(Thalmic.Myo.VibrationType.Short);
        }
        Debug.Log (thalmicMyo);
        Debug.Log (myo);
    }
Example #5
0
    // Draw some basic instructions.
    void OnGUI()
    {
        GUI.skin.label.fontSize = 20;

        hub = ThalmicHub.instance;

        // Access the ThalmicMyo script attached to the Myo object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        if (!hub.hubInitialized) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "Cannot contact Myo Connect. Is Myo Connect running?\n" +
                      "Press Q to try again."
                      );
        } else if (!thalmicMyo.isPaired) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "No Myo currently paired."
                      );
        } else if (!thalmicMyo.armSynced) {
            GUI.Label(new Rect (12, 8, Screen.width, Screen.height),
                      "Perform the Sync Gesture."
                      );
        } else {
            myoIsPaired = true;
            /*
            GUI.Label (new Rect (12, 8, Screen.width, Screen.height),

                       "Fist: Vibrate Myo armband\n" +
                       "Wave in: Set box material to blue\n" +
                       "Wave out: Set box material to green\n" +
                       "Double tap: Reset box material\n" +
                       "Fingers spread: Set forward direction"
                       );
            */
        }
    }
Example #6
0
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
        //#if UNITY_EDITOR
        //            EditorUtility.DisplayDialog("Can only have one ThalmicHub",
        //                                        "Your scene contains more than one ThalmicHub. Remove all but one ThalmicHub.",
        //                                        "OK");
        //#endif
            //Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog ("Thalmic Hub has no Myo children", errorMessage, "OK");
        #else
            throw new UnityException (errorMessage);
        #endif
        }

        #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var unityActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
        var applicationContext = unityActivity.Call<AndroidJavaObject>("getApplicationContext");

        // Need to pass the Android Application Context to the Myo Android plugin before initializing the Hub.
        AndroidJavaClass nativeEventsClass = new AndroidJavaClass("com.thalmic.myo.NativeEvents");
        nativeEventsClass.CallStatic("setApplicationContext", applicationContext);

        // The Hub needs to be initialized on the Android UI thread.
        unityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
            createHub ();
        }));
        #else
        createHub ();
        #endif
    }
Example #7
0
    void Awake()
    {
        // Ensure that there is only one ThalmicHub.
        if (_instance != null) {
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog("Can only have one ThalmicHub",
                                        "Your scene contains more than one ThalmicHub. Remove all but one ThalmicHub.",
                                        "OK");
        #endif
            Destroy (this.gameObject);
            return;
        } else {
            _instance = this;
        }

        // Do not destroy this game object. This will ensure that it remains active even when
        // switching scenes.
        DontDestroyOnLoad(this);

        for (int i = 0; i < transform.childCount; ++i) {
            Transform child = transform.GetChild (i);

            var myo = child.gameObject.GetComponent<ThalmicMyo> ();
            if (myo != null) {
                _myos.Add(myo);
            }
        }

        if (_myos.Count < 1) {
            string errorMessage = "The ThalmicHub's GameObject must have at least one child with a ThalmicMyo component.";
        #if UNITY_EDITOR
            EditorUtility.DisplayDialog ("Thalmic Hub has no Myo children", errorMessage, "OK");
        #else
            throw new UnityException (errorMessage);
        #endif
        }

        #if !UNITY_ANDROID || UNITY_EDITOR
        createHub();
        #endif
    }