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(); }
//----------------------------------------------------------------------------- // 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); }