private void ToolbeltUpdated(NetworkInstanceId toolbeltId) { /* Don't use hooks on host only clients */ if (isServer && isClient) { return; } if (debug) { Debug.Log("PlayerToolbeltManager Client: Our toolbelt ID has been updated "); } /* Get the toolbelt object */ GameObject obj = ClientScene.FindLocalObject(toolbeltId); Debug.Assert(obj != null); /* Get the toolbelt from the object */ toolbelt = obj.GetComponent <PlayerToolbelt>(); Debug.Assert(toolbelt != null); if (debug) { Debug.Log("PlayerToolbeltManager Client: Our toolbelt has spawned!"); } /* Do client callbacks */ eventManager.OnToolbeltEvent(VRInteraction.InteractionEvent.OnToolbeltSpawned, toolbelt.gameObject, null, null); }
private SojournSocket GetSojournSocket(NetworkInstanceId socketManagerId, int socketNumber) { /* Get the socket manager object that the client sent us */ GameObject socketManagerObj = NetworkServer.FindLocalObject(socketManagerId); if (socketManagerObj == null) { Debug.LogError("PlayerToolbeltManager Server: Client has sent us a bad socket manager object!"); return(null); } /* Get the socket manager component from the object */ PlayerToolbelt playerToolbelt = socketManagerObj.GetComponent <PlayerToolbelt>(); if (playerToolbelt == null) { Debug.LogError("PlayerToolbeltManager Server: Client sent us an object that isn't an item socket manager!"); return(null); } /* Make sure the client owns this socket manager */ if (playerToolbelt.GetPlayerId() != netId) { Debug.LogError("PlayerToolbeltManager Server: Client doesn't own this socket manager!"); return(null); } /* Get the item socket from the socket manager */ SojournSocket itemSlot = playerToolbelt.GetSocket(socketNumber); if (itemSlot == null) { Debug.LogError("PlayerToolbeltManager Server: This socket number is invalid: " + socketNumber); return(null); } /* Return the toolbelt item */ return(itemSlot); }
public void SetToolbelt(PlayerToolbelt toolbelt) { this.toolbelt = toolbelt; }
private void SpawnToolbelt() { /* Do we already have a toolbelt? */ if (toolbelt != null) { Debug.LogError("PlayerToolbeltManager: We already have a toolbelt!"); return; } if (debug) { Debug.Log("PlayerToolbeltManager: We are going to spawn this player's toolbelt."); } /* Spawn the toolbelt */ GameObject toolbeltObj = Instantiate(toolbeltPrefab); if (toolbeltObj == null) { throw new System.Exception("Failed to create toolbelt!"); } toolbeltObj.transform.position = transform.position; /* Get the toolbelt component from the object */ toolbelt = toolbeltObj.GetComponent <PlayerToolbelt>(); if (toolbelt == null) { throw new System.Exception("Why does this toolbelt object not have a toolbelt component?"); } /* Set the id of the player */ toolbelt.SetPlayer(playerController); /* Spawn our toolbelt with our authority */ if (!NetworkServer.SpawnWithClientAuthority(toolbeltObj, gameObject)) { throw new System.Exception("Failed to spawn toolbelt!"); } if (debug) { Debug.Log("PlayerToolbeltManager Server: Spawned player's toolbelt: " + playerController.GetEntityName()); } /* Do our toolbelt spawned callback */ eventManager.OnToolbeltEvent(VRInteraction.InteractionEvent.OnToolbeltSpawned, toolbeltObj, null, null); /* Get the custom items for this toolbelt from the database */ Item[] customToolbeltItems = SojournDBM.odbm.GetPlayerToolbeltItems(playerController.GetEntityId()); if (customToolbeltItems == null) { Debug.LogError("PlayerToolbeltManager: Failed to load toolbelt items for player: " + playerController.GetEntityName()); } /* Print custom items in debug mode */ if (debug) { foreach (Item item in customToolbeltItems) { if (item == null) { continue; } Debug.Log("PlayerToolbeltManager: Custom item: " + item.item_name); } } /* Spawn the items in the toolbelt */ toolbelt.SpawnToolbeltItems(customToolbeltItems); /* Save our toolbelt id */ toolbeltId = toolbelt.netId; }