Exemple #1
0
        /// <summary>
        /// A player has entered the room. Ensure the joining player is in sync with the current game state.
        /// </summary>
        /// <param name="player">The Photon Player that entered the room.</param>
        /// <param name="character">The character that the player controls.</param>
        private void OnPlayerEnteredRoom(Player player, GameObject character)
        {
            if (m_Inventory != null)
            {
                // Notify the joining player of the ItemTypes that the player has within their inventory.
                var items = m_Inventory.GetAllItems();
                for (int i = 0; i < items.Count; ++i)
                {
                    var item = items[i];

                    photonView.RPC("PickupItemTypeRPC", player, item.ItemType.ID, m_Inventory.GetItemTypeCount(item.ItemType));

                    if (item.DropPrefab != null)
                    {
                        // Usable Items have a separate ItemType count.
                        var itemActions = item.ItemActions;
                        for (int j = 0; j < itemActions.Length; ++j)
                        {
                            var usableItem = itemActions[j] as IUsableItem;
                            if (usableItem == null)
                            {
                                continue;
                            }

                            var consumableItemTypeCount = usableItem.GetConsumableItemTypeCount();
                            if (consumableItemTypeCount > 0 || consumableItemTypeCount == -1)   // -1 is used by the grenade to indicate that there is only one item.
                            {
                                photonView.RPC("PickupUsableItemActionRPC", player, item.ItemType.ID, item.SlotID, itemActions[j].ID,
                                               m_Inventory.GetItemTypeCount(usableItem.GetConsumableItemType()), usableItem.GetConsumableItemTypeCount());
                            }
                        }
                    }
                }

                // Ensure the correct item is equipped in each slot.
                for (int i = 0; i < m_Inventory.SlotCount; ++i)
                {
                    var item = m_Inventory.GetItem(i);
                    if (item == null)
                    {
                        continue;
                    }

                    photonView.RPC("EquipUnequipItemRPC", player, item.ItemType.ID, i, true);
                }
            }

            // ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER will be defined, but it is required here to allow the addon to be compiled for the first time.
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            // The remote character should have the same abilities active.
            for (int i = 0; i < m_CharacterLocomotion.ActiveAbilityCount; ++i)
            {
                var activeAbility = m_CharacterLocomotion.ActiveAbilities[i];
                photonView.RPC("StartAbilityRPC", player, activeAbility.Index, activeAbility.GetNetworkStartData());
            }
            for (int i = 0; i < m_CharacterLocomotion.ActiveItemAbilityCount; ++i)
            {
                var activeItemAbility = m_CharacterLocomotion.ActiveItemAbilities[i];
                photonView.RPC("StartItemAbilityRPC", player, activeItemAbility.Index, activeItemAbility.GetNetworkStartData());
            }
#endif
        }