示例#1
0
    private void OnApplicationQuit()
    {
        if (bDebugLog)
        {
            Debug.Log("AutoMotionCaptureDevicesSelecter.OnApplicationQuit");
        }
        // Perception Neuron(1-5)
        int i = 0;

        foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
        {
            if (sNeuronConnection.sNeuronSource != null)
            {
                NeuronConnection.DestroyConnection(sNeuronConnection.sNeuronSource);
                if (bDebugLog)
                {
                    Debug.Log("[Perception Neuron_" + (i + 1) + "] DestroyConnection");
                }
            }
            i++;
        }
        // Kinect1
        NativeMethods.NuiShutdown();
        if (bDebugLog)
        {
            Debug.Log("[Kinect1] KinectSensor Shutdown");
        }
        // Kinect2
        Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (_Sensor.IsOpen)
            {
                _Sensor.Close();
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Close");
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Closed");
                }
            }
        }
    }
示例#2
0
    void Start()
    {
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation            = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }
        else
        {
            if (GameObject.Find(strFBXExporterForUnity) != null)
            {
                sFBXExporterForUnity = GameObject.Find(strFBXExporterForUnity).GetComponent <FBXExporterForUnity>();
            }
        }

        switch (eAutoMotionCaptureDevicesSelecter)
        {
        case EAutoMotionCaptureDevicesSelecter.eAuto:
        {
            // Perception Neuron(1-5)
            int iSelect = 0;
            foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
            {
                sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnection.address, sNeuronConnection.port, sNeuronConnection.commandServerPort, sNeuronConnection.socketType);
                if (sNeuronConnections[iSelect].sNeuronSource != null)
                {
                    eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                    NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                    }
                    return;
                }
                iSelect++;
            }

            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }

            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                //if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_2:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_3:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_4:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_5:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_6:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_7:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_8:
        {
            // Perception Neuron(1-5)
            int iSelect = (int)eAutoMotionCaptureDevicesSelecter - (int)EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1;
            sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnections[iSelect].address, sNeuronConnections[iSelect].port, sNeuronConnections[iSelect].commandServerPort, sNeuronConnections[iSelect].socketType);
            if (sNeuronConnections[iSelect].sNeuronSource != null)
            {
                eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect1:
        {
            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect2:
        {
            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
                else
                {
                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Kinect2] -Sensor Opened-");
                    }
                    return;
                }
            }
            break;
        }
        }
        eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eNone;
    }