/// <summary> /// Function called on server when PagePacket data is sent to it from a player client /// Can be used to create new pages, destroy old ones, and overrite existing pages /// </summary> /// <param name="packet">Packet sent to build pages on clients</param> public void CmdSendPagePacket(PagePacket packet) { //Override value in list if page name already exists //print("PacketNameAfterSend: " + packet.name); for (int i = 0; i < pageSyncList.Count; i++) { if (pageSyncList[i].name.Equals(packet.name)) { if (packet.destroy) { pageSyncList.RemoveAt(i); } else { pageSyncList[i] = packet; } return; } } //If not found in list and wasn't destroyed add to list if (!packet.destroy) { //print("Added Packet: " + packet.name); pageSyncList.Add(packet); } else { //Page set to destroy could not actually be found } return; }
/// <summary> /// Net code to create a page packet for the current page form /// </summary> public void PrepareStatPacket() { if (pageName == "") { return; } print("Prepare stat packet"); PagePacket packet = new PagePacket(); packet.name = pageName; print("PageName: " + pageName); packet.pageType = PagePacket.PageType.StatBlockUI; packet.data = SerializationManager.SerializeObject(this.CreateStatBlockUIData()); packet.destroy = false; //Get the local player and have the object send the data foreach (ClientController cc in GameObject.FindObjectsOfType <ClientController>()) { if (cc.isLocalPlayer) { cc.CmdSendPagePacket(packet); break; } } }
/// <summary> /// Function called on server to destroy a page of a given name /// </summary> /// <param name="name">Name pf the page to be deleted</param> public void CmdDestroyPage(string name) { var packet = new PagePacket(); packet.destroy = true; packet.name = name; CmdSendPagePacket(packet); }
/// <summary> /// Called whenever a client joins the game /// Create a statblock to add to the scene /// </summary> override public void OnStartClient() { base.OnStartClient(); if (isServer) { PagePacket packet = new PagePacket(); packet.name = "statblock"; packet.pageType = PagePacket.PageType.StatBlockUI; StatBlockUIData sbd = new StatBlockUIData(); sbd.name = packet.name; packet.data = SerializationManager.SerializeObject(sbd); packet.destroy = false; CmdSendPagePacket(packet); } }
/// <summary> /// Build a page based on recived page packets /// </summary> /// <param name="packet">Contains all data needed to build a page</param> private void BuildPage(PagePacket packet) { switch (packet.pageType) { case PagePacket.PageType.StatBlockUI: { StatBlockUIData uiData = (StatBlockUIData)SerializationManager.LoadObject(packet.data); //Create statblockui GameObject parent = GameObject.Find("Canvas/Page View/Viewport"); GameObject statBlock = Instantiate(prefabs[0], parent.transform); statBlock.GetComponent <StatBlockForm>().BuildPage(uiData); pages.Add(packet.name, statBlock); break; } default: { Debug.LogError("Received Unsupported PagePacket type: " + packet.pageType); break; } } }
public void CmdSendPagePacket(PagePacket packet) { NetworkHandler.instance.CmdSendPagePacket(packet); }