Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        switch (GameProcess)
        {
        case 0:
            //Get Connection Status
            GameObject.Find("ConnectCanvas/ConnectStation").GetComponent <Text>().text = "Connecting ";    //Show Connect station
            Device.ConnectionStatus status = dev.device.getConnectionStatus();

            //Connected
            if (status == Device.ConnectionStatus.Connected)
            {
                dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_RAW | gf.DataNotifFlags.DNF_QUATERNION));

                StartButton.SetActive(true);                                                                     //Show Start Button
                GameObject.Find("ConnectCanvas/ConnectStation").GetComponent <Text>().text = "Connected       "; //Show Connect station
                Debug.LogFormat("ConnectionStatus: {0}", status);
            }
            break;

        case 1:

            //Arm shows
            if (IsRight)
            {
                //Show right hand
                Hand_left.SetActive(false);
                Hand_right.SetActive(true);
            }
            else
            {
                //Show left hand
                Hand_right.SetActive(false);
                Hand_left.SetActive(true);
            }

            ChangeLightButton();            //Show green button
            ConnectCanvas.SetActive(false); //close ConnectCanvas
            GameCanvas.SetActive(true);     //Show game canvas
            AddProcess();
            break;

        case 2:

            //Game  Control
            ArmControl.Armcontrol.ArmQuaterControl(IsRight);     //Arm rotation control
            PointsAndTimes.instance.PointsAndTimesControl();     //Game time and score control
            break;

        case 3:
            GameCanvas.SetActive(false);              //Close game canvas
            ScoreUICanvas.SetActive(true);            //Show score
            PointsAndTimes.instance.CalculateScore(); //Score analysis
            PointsAndTimes.instance.canDrawLine = true;
            break;
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (notifSwitchSet)
        {
            Device.ConnectionStatus status = dev.device.getConnectionStatus();

            if (status == Device.ConnectionStatus.Connected)
            {
                dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_RAW | gf.DataNotifFlags.DNF_QUATERNION));
                notifSwitchSet = true;
            }
        }

        GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>();

        quater = gforceDevice.quater;

        // Check if the gesture has changed since last update.
        if (gforceDevice.gesture != lastGesture)
        {
            lastGesture = gforceDevice.gesture;

            switch (lastGesture)
            {
            case Gesture.Relax:
                // seems Relax is always coming fast, so setup a delay timer,
                // only when Relax keeps for a while, then render relaxMaterial.
                //GetComponent<Renderer>().material = relaxMaterial;
                relaxStart = DateTime.Now;
                break;

            case Gesture.Shoot:
                GetComponent <Renderer>().material = shootMaterial;
                break;

            case Gesture.Undefined:
                GetComponent <Renderer>().material = undefinedMaterial;
                break;

            default:
                GetComponent <Renderer>().material = otherMaterial;
                break;
            }
        }
        else
        {
            if (Gesture.Relax == lastGesture &&
                GetComponent <Renderer>().material != relaxMaterial)
            {
                TimeSpan ts = DateTime.Now - relaxStart;
                if (ts.Milliseconds > RelaxDelay)
                {
                    GetComponent <Renderer>().material = relaxMaterial;
                }
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        switch (GameProcess)
        {
        case 0:
            //Get Connection Status
            GameObject.Find("ConnectCanvas/ConnectStation").GetComponent <Text>().text = "Connecting ";    //Show Gesture Name
            Device.ConnectionStatus status = dev.device.getConnectionStatus();

            if (status == Device.ConnectionStatus.Connected)
            {
                dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_GESTURE | gf.DataNotifFlags.DNF_QUATERNION));

                StartButton.SetActive(true);
                GameObject.Find("ConnectCanvas/ConnectStation").GetComponent <Text>().text = "Connected       ";    //Show Gesture Name
                Debug.LogFormat("ConnectionStatus: {0}", status);
            }
            break;

        case 1:

            //Arm shows
            if (IsRight)
            {
                Hand_left.SetActive(false);
                Hand_right.SetActive(true);
            }
            else
            {
                Hand_right.SetActive(false);
                Hand_left.SetActive(true);
            }

            ConnectCanvas.SetActive(false);     //close ConnectCanvas
            GameCanvas.SetActive(true);
            AddProcess();
            break;

        case 2:

            //Arm  Control

            GestureControler.gesturecontroler.GestureControl(IsRight);
            GestureControler.gesturecontroler.ArmQuaterControl(IsRight);
            break;

        case 3:
            //Quit the game
            dev.device.disconnect();
                #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
                #else
            Application.Quit();
                #endif
            break;
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (!notifSwitchSet)
        {
            Device.ConnectionStatus status = dev.device.getConnectionStatus();

            if (status == Device.ConnectionStatus.Connected)
            {
                dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_RAW | gf.DataNotifFlags.DNF_QUATERNION));
                notifSwitchSet = true;
            }
        }

        GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>();

        quater  = gforceDevice.quater;     //Get gForce quater
        Rawdata = gforceDevice.EMGRawdata; //Get gForce Rawdata
    }
Exemplo n.º 5
0
 public override void onScanFinished()
 {
     Debug.Log("OnScanFinished");
     if (null == gfrce.mDevice)
     {
         // if no device found, we do scan again
         gfrce.mHub.startScan();
     }
     else
     {
         Debug.LogFormat("number of devices found: {0}", gfrce.mHub.getNumDevices(false));
         // or if there already is a device found and it's not
         //     in connecting or connected state, try to connect it.
         Device.ConnectionStatus status = gfrce.mDevice.getConnectionStatus();
         if (Device.ConnectionStatus.Connected != status &&
             Device.ConnectionStatus.Connecting != status)
         {
             gfrce.mDevice.connect();
         }
     }
 }
Exemplo n.º 6
0
 public override void onScanFinished()
 {
     System.Console.WriteLine("OnScanFinished");
     if (null == gfrce.mDevice)
     {
         // if no device found, we do scan again
         gfrce.mHub.startScan();
     }
     else
     {
         System.Console.WriteLine("number of devices found: {0}", gfrce.mHub.getNumDevices(false));
         // enum devices
         gfrce.mHub.enumDevices(new Hub.deviceEnumFn(gfrce.deviceEnum), false);
         // or if there already is a device found and it's not
         //     in connecting or connected state, try to connect it.
         Device.ConnectionStatus status = gfrce.mDevice.getConnectionStatus();
         if (Device.ConnectionStatus.Connected != status &&
             Device.ConnectionStatus.Connecting != status)
         {
             gfrce.mDevice.connect();
         }
     }
 }
Exemplo n.º 7
0
        public override void onDeviceDisconnected(Device device, int reason)
        {
            System.Console.WriteLine("onDeviceDisconnected, name is \'{0}\', reason is {1}",
                                     device.getName(), reason);

            if (device == gForceHub_.connectedDevice_)
            {
                System.Console.WriteLine("Need connect");
                gForceHub_.connectedDevice_ = null;

                bool ret = gForceHub_.foundDevices.Remove(device);
                System.Console.WriteLine("gForceHub_.foundDevices.Remove: {0} -> {1}", device.getName(), ret);
            }

            if (gForceHub_.connectedDevice_ == null)
            {
                foreach (Device dev in gForceHub_.foundDevices)
                {
                    if (null == dev)
                    {
                        continue;
                    }

                    Device.ConnectionStatus status = dev.getConnectionStatus();

                    if (Device.ConnectionStatus.Connecting == status)
                    {
                        // a device is in connecting state, we will do nothing until
                        // connection finished (succeeded or failed)
                        System.Console.WriteLine("A device is in connecting, wait after it done");
                        return;
                    }
                }

                TryConnect();
            }
        }
Exemplo n.º 8
0
        public override void onDeviceDisconnected(Device device, int reason)
        {
            Debug.LogFormat("onDeviceDisconnected, name is \'{0}\', reason is {1}",
                            device.getName(), reason);
            bool needReconnect = false;

            foreach (GForceDevice dev in hubcomp.mDeviceComps)
            {
                if (device == dev.device)
                {
                    Debug.Log("Need rescan");
                    dev.device    = null;
                    needReconnect = true;
                    break;
                }
            }
            if (needReconnect)
            {
                foreach (GForceDevice dev in hubcomp.mDeviceComps)
                {
                    if (null == dev.device)
                    {
                        continue;
                    }
                    Device.ConnectionStatus status = dev.device.getConnectionStatus();
                    if (Device.ConnectionStatus.Connecting == status)
                    {
                        // a device is in connecting state, we will do nothing until
                        // connection finished (succeeded or failed)
                        Debug.Log("A device is in connecting, wait after it done");
                        return;
                    }
                }
                tryConnecting();
            }
        }