internal void OnTrackerRegistryFinished(NetworkMessage netMsg)
        {
            // parse message
            ViveTrackerRegistryReturnMsg msg = netMsg.ReadMessage <ViveTrackerRegistryReturnMsg>();

            // assign client id
            clientId = msg.clientId;

            // attach sync pose obj to main camera
            ViveShare_SyncIdentity syncId = Camera.main.gameObject.AddComponent <ViveShare_SyncIdentity>();

            syncId.id           = msg.syncObjName;
            syncId.hasAuthority = false;
            syncId.Register();

            ViveShare_SyncPose syncPose = Camera.main.gameObject.AddComponent <ViveShare_SyncPose>();

            ViveShare_Log.LogInfo(logLevel, "[ViveShare_Client] Client id (" + clientId + ") assigned");
            ViveShare_Log.LogInfo(logLevel, "[ViveShare_Client] Tracker registry (" + msg.syncObjName + ") finished");

            state = ViveNetworkState.Wait_Ready;

            // invoke callbacks --  we only think the connection is established at this moment
            ViveShare_Event.client_connectSuccessEvent.Invoke();
        }
        private void DisconnectInternal()
        {
            // detect connection time out
            if (state == ViveNetworkState.Wait_Connect || state == ViveNetworkState.Wait_TrackerRegistry)
            {
                ViveShare_Log.LogError(logLevel, "[ViveShare_Client] Disconnect due to connection timeout");
                ViveShare_Event.client_connectFailedEvent.Invoke();
            }

            ViveShare_Log.LogInfo(logLevel, "[ViveShare_Client] Disconnect");

            // reset and remove resources
            if (needTrackerPose)
            {
                ViveShare_SyncPose syncPose = Camera.main.gameObject.GetComponent <ViveShare_SyncPose>();
                if (syncPose != null)
                {
                    Destroy(syncPose);
                }

                ViveShare_SyncIdentity syncId = Camera.main.gameObject.GetComponent <ViveShare_SyncIdentity>();
                if (syncId != null)
                {
                    Destroy(syncId);
                }
            }

            clientId = -1;

            ViveShare_Event.client_disconnectEvent.Invoke();

            state = ViveNetworkState.Init;
        }
        private void RemoveConnectionData(int id)
        {
            ConnectionData data;

            if (connectionDataMap.TryGetValue(id, out data))
            {
                ViveShare_Log.LogInfo(logLevel, "[ViveShare_Server] RemoveConnectionData for client (" + id + ")");

                // destroy tracker object
                if (data.trackerObject != null)
                {
                    ViveShare_SyncIdentity syncId = data.trackerObject.GetComponent <ViveShare_SyncIdentity>();
                    syncId.UnRegister();

                    Destroy(data.trackerObject);
                }

                // destroy data
                connectionDataList.Remove(data);
                connectionDataMap.Remove(id);
            }
        }
Пример #4
0
 public ViveShare_SyncBase GetSyncObjFromSyncId(ViveShare_SyncIdentity syncId)
 {
     return(syncId.gameObject.GetComponent <ViveShare_SyncBase>());
 }
Пример #5
0
 public void RemoveSyncIdentity(ViveShare_SyncIdentity syncId)
 {
     syncIdList.Remove(syncId);
     syncIdDictionary.Remove(syncId.id);
 }
Пример #6
0
        //-----------------------------------------------------------------------------
        // param sync objects
        //-----------------------------------------------------------------------------

        public void AddSyncIdentity(ViveShare_SyncIdentity syncId)
        {
            syncIdList.Add(syncId);
            syncIdDictionary.Add(syncId.id, syncId);
        }
Пример #7
0
 public virtual void OnEnable()
 {
     identity = GetComponent <ViveShare_SyncIdentity>();
 }
        //-----------------------------------------------------------------------------
        // tracker assignment
        //-----------------------------------------------------------------------------

        internal void OnTrakcerResitryRequest(NetworkMessage netMsg)
        {
            // parse message
            ViveTrackerRegistryRequestMsg msg = netMsg.ReadMessage <ViveTrackerRegistryRequestMsg>();

            // check connectivity
            int            connId   = netMsg.conn.connectionId;
            ConnectionData connData = GetConnectionData(connId);

            if (connData == null)
            {
                return;
            }

            // if need to assign a tracker to client
            string trackerPoseObjName = "";

            if (msg.needTrackerPose)
            {
                TrackerRole trackerRole = TryToBindTracker(msg.serialNumber, msg.trackerNumber);

                // if failed, tell client to disconnect
                if (trackerRole == TrackerRole.Invalid)
                {
                    ViveShare_Log.LogError(logLevel, "[ViveShare_Server] Failed to assign tracker for client (" + netMsg.conn.connectionId + ")");
                    netMsg.conn.Disconnect();
                    return;
                }
                // if succeeded, save assigned role and initialize sync pose object
                else
                {
                    ViveShare_Log.LogInfo(logLevel, "[ViveShare_Server] Assign tracker (" + trackerRole.ToString() + ") to client (" + netMsg.conn.connectionId + ")");

                    connData.trackerRole = trackerRole;
                    trackerPoseObjName   = trackerRole.ToString();

                    // create pose tracker and attach sync param object to it
                    GameObject      trackerObj  = new GameObject(trackerPoseObjName);
                    VivePoseTracker poseTracker = trackerObj.AddComponent <VivePoseTracker>();
                    poseTracker.viveRole.SetEx <TrackerRole>(trackerRole);

                    ViveShare_SyncIdentity syncId = trackerObj.AddComponent <ViveShare_SyncIdentity>();
                    syncId.id           = trackerPoseObjName;
                    syncId.hasAuthority = true;
                    syncId.Register();

                    trackerObj.AddComponent <ViveShare_SyncPose>();

                    if (cameraRig != null)
                    {
                        trackerObj.transform.parent = cameraRig.transform;
                    }

                    connData.trackerObject = trackerObj;
                }
            }

            // return "finished" message
            ViveTrackerRegistryReturnMsg returnMsg = new ViveTrackerRegistryReturnMsg();

            returnMsg.syncObjName = trackerPoseObjName;
            returnMsg.clientId    = connId;

            NetworkServer.SendToClient(netMsg.conn.connectionId, ViveShareMsgType.TrackerRegistryFinished, returnMsg);

            // invoke callbacks -- we only think the connection is established at this moment
            ViveShare_Event.server_clientConnectedEvent.Invoke(netMsg.conn.connectionId);
        }