private Task OnRemoteUserUpdate(MessageContainer obj) { MessageUpdateUser message = MessageUpdateUser.Unpack(obj); if (indicatorList.ContainsKey(message.Id)) { var userIndicator = indicatorList[message.Id]; userIndicator.SetTargetLocalPosition(message.Position); userIndicator.SetTargetLocalRotation(message.Orientation); if (userIndicator.GetComponentInChildren <Renderer>().material.color != message.Color) { userIndicator.GetComponentInChildren <Renderer>().material.color = message.Color; } } else if (UserIndicatorPrefab) { // new user joined, instantiate indicator var userIndicator = Instantiate(UserIndicatorPrefab, worldAnchor); userIndicator.SetTargetLocalPosition(message.Position); userIndicator.SetTargetLocalRotation(message.Orientation); userIndicator.GetComponentInChildren <Renderer>().material.color = message.Color; indicatorList.Add(message.Id, userIndicator); // send position update, so that the new user gets up to speed SendUserUpdate(); } return(Task.CompletedTask); }
// Start is called before the first frame update private void Start() { SetColor(0); worldAnchor = GameObject.FindGameObjectWithTag("RootWorldAnchor").transform; Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.UPDATE_USER, OnRemoteUserUpdate); Services.NetworkManager().RegisterMessageHandler(MessageContainer.MessageType.ACCEPT_CLIENT, OnAcceptedAsClient); Transform cameraTransform = CameraCache.Main ? CameraCache.Main.transform : null; if (cameraTransform != null) { message = new MessageUpdateUser(cameraTransform.position, cameraTransform.rotation, id, Color); Services.NetworkManager().SendMessage(message.Pack()); LocalUserPosition = new GameObject().transform; LocalUserPosition.position = cameraTransform.position; LocalUserPosition.rotation = cameraTransform.rotation; } }