private Task OnCreateVisContainer(MessageContainer obj) { MessageCreateVisContainer message = MessageCreateVisContainer.Unpack(obj); if (message != null) { CreateViewContainer(message.Container, false); } return(Task.CompletedTask); }
/// <summary> /// Creates a new <see cref="ViewContainer"/> and adds it to the list of containers. /// </summary> /// <param name="container">The <see cref="VisContainer"/> object representing the settings for the new <see cref="ViewContainer"/>.</param> /// <param name="syncWithRemote">Indicates whether the container should also be created on remote clients.</param> public void CreateViewContainer(VisContainer container, bool syncWithRemote = true) { // add to list of containers or update list if (ViewContainers.ContainsKey(container.Id)) { // already in list, update ViewContainers[container.Id].Init(container); } else { // not in list, create and add Transform worldAnchor = GameObject.FindGameObjectWithTag("VisRootAnchor").transform; var placeholder = Instantiate(VisPlaceholderPrefab, worldAnchor); // instantiate placeholder prefab, set the World Anchor as parent, to make sure every client sees the same placeholder.Init(container); ViewContainers.Add(container.Id, placeholder.GetComponent <ViewContainer>()); // add to list } if (syncWithRemote) { var message = new MessageCreateVisContainer(container); Services.NetworkManager().SendMessage(message.Pack()); } }