// What should a pawn do in an unloaded chunk? // Lets just load the chunks around pawns! public void Awake() { Health = GetComponent <Health>(); AO = GetComponent <ActiveObject>(); NetPosSync = GetComponent <NetPosSync>(); Path = GetComponent <PawnPathfinding>(); }
private void Server_SetAttachment(GameObject player, AttachmentType type, Attachment a, ItemData itemData) { if (a != null) { Attachment current = GetCurrentAttachment(type); if (current != null) { current.Item.RequestDataUpdate(); itemData = current.Item.Data; string itemDataString = itemData.Serialize(); // Return the current attachment... RpcReturnAttachment(player, current.Item.Prefab, itemDataString); // Destroy the object on the server and all clients. current.transform.parent = null; // Don't ask why, but don't remove either... Destroy(current.gameObject); } // Note that attachment, 'a', is a prefab. string prefab = a.Item.Prefab; // Spawn the attachment... Item spawnedItem = Item.NewInstance(prefab, transform.position, itemData); NetPosSync posSync = spawnedItem.NetPosSync; NetParent parent; Transform mount = GetMountFor(type); if (mount != null) { parent = mount.GetComponent <NetParent>(); } else { Debug.LogError("Invalid mount (null) for attachment {0}, not good at all. Expect wierd bullshittery.".Form(prefab)); Destroy(spawnedItem.gameObject); return; } // Spawn on server and on all client, with player authority assigned to the player who is using the attachment. NetworkServer.SpawnWithClientAuthority(spawnedItem.gameObject, player); // Mount it to the correct NetParent. posSync.SetParent(parent); } else { // Attachment is null, remove any existing attachment from that slot... Attachment current = GetCurrentAttachment(type); if (current != null) { current.Item.RequestDataUpdate(); itemData = current.Item.Data; string itemDataString = itemData.Serialize(); // Return the current attachment... RpcReturnAttachment(player, current.Item.Prefab, itemDataString); // Destroy the object on the server and all clients. Destroy(current.gameObject); } } }