/// <summary> /// Initializes the item after it has been added to the Inventory. /// </summary> /// <param name="item">The item that this extension belongs to.</param> /// <param name="inventory">The parent character's inventory.</param> public virtual void Init(Item item, Inventory inventory) { m_ParentItem = item; m_Inventory = inventory; m_Character = inventory.gameObject; #if ENABLE_MULTIPLAYER m_NetworkMonitor = m_Character.GetComponent <NetworkMonitor>(); #endif m_AnimatorMonitor = inventory.GetComponent <AnimatorMonitor>(); m_Controller = inventory.GetComponent <RigidbodyCharacterController>(); SharedManager.InitializeSharedFields(m_Character, this); }
/// <summary> /// Initializes the item after it has been added to the Inventory. /// </summary> /// <param name="inventory">The parent character's inventory.</param> public virtual void Init(Inventory inventory) { m_Inventory = inventory; m_Character = inventory.gameObject; #if ENABLE_MULTIPLAYER m_NetworkMonitor = m_Character.GetComponent <NetworkMonitor>(); #endif m_AnimatorMonitor = inventory.GetComponent <AnimatorMonitor>(); m_Controller = inventory.GetComponent <RigidbodyCharacterController>(); // Initialize the animation states. m_DefaultStates.Initialize(m_ItemType); if (m_CanAim) { m_AimStates.Initialize(m_ItemType); } m_EquipStates.Initialize(m_ItemType); m_UnequipStates.Initialize(m_ItemType); EventHandler.RegisterEvent(gameObject, "OnInventoryItemEquipping", OnItemEquipping); EventHandler.RegisterEvent(gameObject, "OnInventoryItemUnequipping", OnItemUnequipping); EventHandler.RegisterEvent(gameObject, "OnInventoryItemEquipped", OnItemEquipped); EventHandler.RegisterEvent(gameObject, "OnInventoryItemUnequipped", OnItemUnequipped); for (int i = 0; i < m_ItemExtensions.Length; ++i) { m_ItemExtensions[i].Init(this, inventory); } for (int i = 0; i < m_Colliders.Length; ++i) { m_Colliders[i].enabled = false; } SharedManager.InitializeSharedFields(m_Character, this); // Independent look characters do not need to communicate with the camera. Do not initialze the SharedFields on the network to prevent non-local characters from // using the main camera to determine their look direction. The SharedFields have been implemented by the NetworkMonitor component. #if ENABLE_MULTIPLAYER if (!m_IndependentLook.Invoke() && m_IsLocalPlayer.Invoke()) { #else if (!m_IndependentLook.Invoke()) { #endif SharedManager.InitializeSharedFields(Utility.FindCamera(m_Character).gameObject, this); } }