/// <summary>
    /// (Re)initializes <see cref="m_client"/> and connects to the configured streaming server.
    /// </summary>
    void OnEnable()
    {
        IPAddress serverAddr = IPAddress.Parse(ServerAddress);
        IPAddress localAddr  = IPAddress.Parse(LocalAddress);

        NatNetConnectionType connType;

        switch (ConnectionType)
        {
        case ClientConnectionType.Unicast:
            connType = NatNetConnectionType.NatNetConnectionType_Unicast;
            break;

        case ClientConnectionType.Multicast:
        default:
            connType = NatNetConnectionType.NatNetConnectionType_Multicast;
            break;
        }

        try {
            m_client = new NatNetClient();
            m_client.Connect(connType, localAddr, serverAddr);
            UpdateDefinitions();
        }
        catch (Exception ex) {
            Debug.LogException(ex, this);
            Debug.LogError(GetType().FullName + ": Error connecting to server; check your configuration, and make sure the server is currently streaming.", this);
            this.enabled = false;
            return;
        }

        m_client.NativeFrameReceived += OnNatNetFrameReceived;
        m_connectionHealthCoroutine   = StartCoroutine(CheckConnectionHealth());
    }
Exemplo n.º 2
0
    /// <summary>
    /// Disconnects from the streaming server and cleans up <see cref="m_client"/>.
    /// </summary>
    void OnDisable()
    {
        if (m_connectionHealthCoroutine != null)
        {
            StopCoroutine(m_connectionHealthCoroutine);
            m_connectionHealthCoroutine = null;
        }

        m_client.NativeFrameReceived -= OnNatNetFrameReceived;
        m_client.Disconnect();
        m_client.Dispose();
        m_client = null;
    }
Exemplo n.º 3
0
    public void InitializeConnection()
    {
        if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
        {
            LocalAddress = GetLocalIPAddress();
        }
        else
        {
            Debug.LogError("No local network found");
        }
        IPAddress serverAddr = IPAddress.Parse(ServerAddress);
        IPAddress localAddr  = IPAddress.Parse(LocalAddress);

        NatNetConnectionType connType;

        switch (ConnectionType)
        {
        case ClientConnectionType.Unicast:
            connType = NatNetConnectionType.NatNetConnectionType_Unicast;
            break;

        case ClientConnectionType.Multicast:
        default:
            connType = NatNetConnectionType.NatNetConnectionType_Multicast;
            break;

        case ClientConnectionType.Photon:
            return;
        }

        try
        {
            m_client = new NatNetClient(connType);
            m_client.Connect(localAddr, serverAddr);
        }
        catch (Exception ex)
        {
//			Debug.LogException( ex, this );
//			Debug.LogError( GetType().FullName + ": Error connecting to server; check your configuration, and make sure the server is currently streaming.", this );
            //Add Call to fallback, giving an error message
            Fallback.Instance.SendErrorMessage("Couldn't connect to motive. Make sure Motive has started and then relaunch playmode");
            this.enabled = false;
            return;
        }

        m_client.NativeFrameReceived += OnNatNetFrameReceived;
        m_connectionHealthCoroutine   = StartCoroutine(CheckConnectionHealth());
    }
    /// <summary>
    /// (Re)initializes <see cref="m_client"/> and connects to the configured streaming server.
    /// </summary>
    void OnEnable()
    {
        IPAddress serverAddr = IPAddress.Parse(ServerAddress);
        IPAddress localAddr  = IPAddress.Parse(LocalAddress);

        NatNetConnectionType connType;

        switch (ConnectionType)
        {
        case ClientConnectionType.Unicast:
            connType = NatNetConnectionType.NatNetConnectionType_Unicast;
            break;

        case ClientConnectionType.Multicast:
        default:
            connType = NatNetConnectionType.NatNetConnectionType_Multicast;
            break;
        }

        try
        {
            m_client = new NatNetClient();
            m_client.Connect(connType, localAddr, serverAddr);

            UpdateDefinitions();

            // clear all subscriptions
            if (ConnectionType == ClientConnectionType.Unicast)
            {
                ResetStreamingSubscriptions();
            }

            if (ConnectionType == ClientConnectionType.Unicast)
            {
                // Re-subscribe to rigid bodies and/or skeletons in which the streaming client has data
                foreach (KeyValuePair <Int32, MonoBehaviour> rb in m_rigidBodies)
                {
                    SubscribeRigidBody(rb.Value, rb.Key);
                }
                foreach (KeyValuePair <string, MonoBehaviour> skel in m_skeletons)
                {
                    SubscribeSkeleton(skel.Value, skel.Key);
                }
            }



            // Set the Skeleton Coordinates to Global.
            m_client.RequestCommand("SetProperty,,Skeleton Coordinates,false");



            if (RecordOnPlay == true)
            {
                StartRecording();
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex, this);
            Debug.LogError(GetType().FullName + ": Error connecting to server; check your configuration, and make sure the server is currently streaming.", this);
            this.enabled = false;
            return;
        }

        m_client.NativeFrameReceived += OnNatNetFrameReceived;
        m_connectionHealthCoroutine   = StartCoroutine(CheckConnectionHealth());
    }