Ejemplo n.º 1
0
 private void Start()
 {
     if (Connect)
     {
         _instance = NeuronConnection.Connect(IpAddress, Port, -1, NeuronConnection.SocketType.TCP);
     }
 }
 void OnEnable()
 {
     // Connect to target machine
     source = NeuronConnection.Connect(address, port, commandServerPort, socketType);
     // Get first actor from source
     actor = source.AcquireActor(0);
 }
    public bool Connect(string address, int port, int commandServerPort, NeuronConnection.SocketType socketType)
    {
        NeuronSource source = NeuronConnection.Connect(address, port, commandServerPort, socketType);

        if (source != null)
        {
            source.RegisterResumeActorCallback(OnResumeActor);
            source.RegisterSuspendActorCallback(OnSuspendActor);
            sources.Add(source);
        }
        return(true);
    }
    public void DiconnectAll()
    {
        for (int i = 0; i < sources.Count; ++i)
        {
            NeuronSource source = sources[i];
            OnDisconnect(source);
            NeuronConnection.Disconnect(source);
        }
        sources.Clear();

        ClearAllInstances();
    }
    public void OnDisconnect(NeuronSource source)
    {
        NeuronActor[] activeActors = source.GetActiveActors();

        for (int i = 0; i < activeActors.Length; ++i)
        {
            NeuronActor            actor    = activeActors[i];
            NeuronAnimatorInstance instance = null;
            instances.TryGetValue(actor, out instance);
            if (instance != null)
            {
                instancesToDestroy.Add(instance);
            }
        }
    }
    public void Disconnect(string address, int port)
    {
        NeuronSource source = null;

        for (int i = 0; i < sources.Count; ++i)
        {
            if (address == sources[i].address && port == sources[i].port)
            {
                source = sources[i];
                break;
            }
        }

        if (source != null)
        {
            sources.Remove(source);
            OnDisconnect(source);
            NeuronConnection.Disconnect(source);
        }

        ClearAllInstances();
    }
Ejemplo n.º 7
0
    public void AddConnection()
    {
        string address = IPField.text.ToString();
        int    port    = int.Parse(PortField.text);

        NeuronSource source = FindSource(address, port);

        if (source != null)
        {
            if (source.numOfActiveActors == 0)
            {
                Disconnect(source.address, source.port);
            }
            else
            {
                Debug.Log(string.Format("[NeuronDebugViewer] Connection to {0}:{1} already present.", address, port));
                return;
            }
        }

        NeuronConnection.SocketType socketType = UDPToggle.isOn ? NeuronConnection.SocketType.UDP : NeuronConnection.SocketType.TCP;
        Connect(address, port, -1, socketType);
    }
Ejemplo n.º 8
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;
                    }
                };
            }
        }
    }
Ejemplo n.º 9
0
    static NeuronSource CreateConnection(string address, int port, int commandServerPort, NeuronConnection.SocketType socketType)
    {
        NeuronSource source                 = null;
        IntPtr       socketReference        = IntPtr.Zero;
        IntPtr       commandSocketReference = IntPtr.Zero;

        if (socketType == NeuronConnection.SocketType.TCP)
        {
            socketReference = NeuronDataReader.BRConnectTo(address, port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Connected to {0}:{1}.", address, port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Connecting to {0}:{1} failed.", address, port));
                }
            }
        }
        else
        {
            socketReference = NeuronDataReader.BRStartUDPServiceAt(port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Start listening at {0}.", port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Start listening at {0} failed.", port));
                }
            }
        }

        if (socketReference != IntPtr.Zero)
        {
            if (commandServerPort > 0)
            {
                // connect to command server
                commandSocketReference = NeuronDataReader.BRConnectTo(address, commandServerPort);
                if (commandSocketReference != IntPtr.Zero)
                {
                    if (bDebugLog)
                    {
                        Debug.Log(string.Format("[NeuronConnection] Connected to command server {0}:{1}.", address, commandServerPort));
                    }
                }
                else
                {
                    if (bDebugLog)
                    {
                        Debug.LogError(string.Format("[NeuronConnection] Connected to command server {0}:{1} failed.", address, commandServerPort));
                    }
                }
            }

            source = new NeuronSource(address, port, commandServerPort, socketType, socketReference, commandSocketReference);
        }

        return(source);
    }