示例#1
0
    void Start()
    {
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation            = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }

        // Perception Neuron
        NeuronSource source = CreateConnection(Neuron_address, Neuron_port, Neuron_commandServerPort, Neuron_socketType);

        if (source != null)
        {
            eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron;
            if (source != null)
            {
                source.OnDestroy();
            }
            bCheckedDevices = true;
            if (bDebugLog)
            {
                Debug.Log("Auto Devices Selecter Enabled [Perception Neuron]");
            }
            return;
        }
        // Kinect1
        int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);

        if (hr != 0)
        {
        }
        else
        {
            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();
                _Sensor.IsAvailableChanged += (sender, evt) => {
                    if (!bCheckedDevices)
                    {
                        if (_Sensor.IsAvailable)
                        {
                            eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                            if (_Sensor != null)
                            {
                                if (bDebugLog)
                                {
                                    Debug.Log("[Kinect2] KinectSensor Close");
                                }
                                _Sensor.Close();
                            }
                        }
                        bCheckedDevices = true;
                        if (bDebugLog)
                        {
                            Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                        }
                        return;
                    }
                };
            }
        }
    }
示例#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;
    }
    void Start()
	{
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }

        // Perception Neuron
        NeuronSource source = CreateConnection(Neuron_address, Neuron_port, Neuron_commandServerPort, Neuron_socketType);
		if (source != null)
		{
			eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron;
			if (source != null)
			{
				source.OnDestroy();
			}
			bCheckedDevices = true;
			if (bDebugLog) Debug.Log("Auto Devices Selecter Enabled [Perception Neuron]");
			return;
		}
		// Kinect1
		int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
		if (hr != 0) {
		}
		else
		{
			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();
				_Sensor.IsAvailableChanged += (sender, evt) => {
					if (!bCheckedDevices)
					{
						if(_Sensor.IsAvailable)
						{
							eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
							if (_Sensor != null)
							{
                                if (bDebugLog) Debug.Log("[Kinect2] KinectSensor Close");
                                _Sensor.Close();
							}
						}
                        bCheckedDevices = true;
                        if (bDebugLog) Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
						return;
					}
				};
			}
		}
	}