Пример #1
0
        /// <summary>
        /// The character has been attached to the camera. Update the UI reference and initialze the character-related values.
        /// </summary>
        /// <param name="character">The character that the UI is monitoring.</param>
        private void AttachCharacter(GameObject character)
        {
            if (m_Character != character && m_Character != null)
            {
                EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
                EventHandler.UnregisterEvent <bool>(m_Character, "OnAllowGameplayInput", AllowGameplayInput);
                EventHandler.UnregisterEvent <float>(m_Character, "OnCameraUpdateRecoil", UpdateRecoil);
                EventHandler.UnregisterEvent <bool>(m_Character, "OnLaserSightUseableLaserSightActive", DisableCrosshairs);
                EventHandler.UnregisterEvent <bool>(m_Character, "OnItemShowScope", DisableCrosshairs);
                EventHandler.UnregisterEvent(m_Character, "OnDeath", OnDeath);
                if (m_OnlyVisibleOnAim)
                {
                    EventHandler.UnregisterEvent <bool>(m_Character, "OnControllerAim", OnAim);
                }
            }

            if (m_Character == character)
            {
                return;
            }

            m_Character = character;
            if (m_Character == null || !m_GameObject.activeInHierarchy)
            {
                // The object may be destroyed when Unity is ending.
                if (this != null)
                {
                    EnableCrosshairsImage(false);
                }
                return;
            }

            SharedManager.InitializeSharedFields(m_Character, this);
            m_Controller = m_Character.GetComponent <RigidbodyCharacterController>();
            if (m_Camera == null)
            {
                m_Camera                   = Utility.FindCamera(m_Character);
                m_CameraMonitor            = m_Camera.GetComponent <CameraMonitor>();
                m_CameraMonitor.Crosshairs = transform;
                SharedManager.InitializeSharedFields(m_Camera.gameObject, this);
            }

            PrimaryItemChange(m_CurrentPrimaryItem.Get());

            // Register for the events. Do not register within OnEnable because the character may not be known at that time.
            EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
            EventHandler.RegisterEvent <bool>(m_Character, "OnAllowGameplayInput", AllowGameplayInput);
            EventHandler.RegisterEvent <float>(m_Character, "OnCameraUpdateRecoil", UpdateRecoil);
            EventHandler.RegisterEvent <bool>(m_Character, "OnLaserSightUseableLaserSightActive", DisableCrosshairs);
            EventHandler.RegisterEvent <bool>(m_Character, "OnItemShowScope", DisableCrosshairs);
            EventHandler.RegisterEvent(m_Character, "OnDeath", OnDeath);
            if (m_OnlyVisibleOnAim)
            {
                EventHandler.RegisterEvent <bool>(m_Character, "OnControllerAim", OnAim);
            }

            EnableCrosshairsImage(!m_OnlyVisibleOnAim || m_Controller.Aiming);
        }
Пример #2
0
        /// <summary>
        /// The character has been attached to the camera. Update the UI reference and initialze the character-related values.
        /// </summary>
        /// <param name="character">The character that the UI is monitoring.</param>
        private void AttachCharacter(GameObject character)
        {
            if (m_Character == character)
            {
                return;
            }

            if (m_Character != null)
            {
                if (m_MonitorHealth)
                {
                    EventHandler.RegisterEvent <float>(m_Character, "OnHealthAmountChange", HealthAmountChange);
                }
                else
                {
                    EventHandler.RegisterEvent <float>(m_Character, "OnHealthShieldAmountChange", HealthAmountChange);
                }
            }

            m_Character = character;

            if (character == null)
            {
                // The object may be destroyed when Unity is ending.
                if (this != null)
                {
                    gameObject.SetActive(false);
                    enabled = false;
                }
                return;
            }

            SharedManager.InitializeSharedFields(character, this);

            // Register for the events. Do not register within OnEnable because the character may not be known at that time.
            if (m_MonitorHealth)
            {
                EventHandler.RegisterEvent <float>(character, "OnHealthAmountChange", HealthAmountChange);
                HealthAmountChange(m_CurrentHealth.Get());
                if (m_Slider != null)
                {
                    m_Slider.maxValue = m_MaxHealth.Get();
                }
            }
            else
            {
                EventHandler.RegisterEvent <float>(character, "OnHealthShieldAmountChange", HealthAmountChange);
                HealthAmountChange(m_CurrentShield.Get());
                if (m_Slider != null)
                {
                    m_Slider.maxValue = m_MaxShield.Get();
                }
            }

            gameObject.SetActive(true);
        }
Пример #3
0
        /// <summary>
        /// The ability has been started.
        /// </summary>
        protected override void AbilityStarted()
        {
            base.AbilityStarted();

            EventHandler.RegisterEvent(gameObject, "OnAnimatorPickupItem", DoItemPickup);

            // Unequip the current item if it exists.
            if (m_UnequipCurrentItem && m_ItemEquipped.Get())
            {
                var item = m_CurrentPrimaryItem.Get();
                m_Unequipped = true;
                // Do not unequip the current item if the character has an item about to be picked up.
                for (int i = 0; i < m_ActiveItemPickup.ItemList.Count; ++i)
                {
                    if (item.ItemType == m_ActiveItemPickup.ItemList[i].ItemType)
                    {
                        m_Unequipped = false;
                        break;
                    }
                }
                if (m_Unequipped)
                {
                    EventHandler.ExecuteEvent(m_GameObject, "OnAbilityToggleEquippedItem");
                }
            }
        }
Пример #4
0
 void OnConsumableItemCountChange(Item item, bool added, bool immediateChange)
 {
     //Only Call OnAmmoChanged If the Item is The Current Primary Item
     if (item == m_CurrentPrimaryItem.Get())
     {
         RequestCallAmmoChangedEvent();
     }
 }
Пример #5
0
        void RequestCallAmmoChangedEvent()
        {
            int _loadedAmmo   = m_PrimaryLoadedCount.Get();
            int _unloadedAmmo = m_PrimaryUnloadedCount.Get();

            if (_loadedAmmo < int.MaxValue && _loadedAmmo >= 0 &&
                _unloadedAmmo < int.MaxValue && _unloadedAmmo >= 0)
            {
                CallOnAmmoChanged(_loadedAmmo, _unloadedAmmo);
            }
        }
Пример #6
0
        /// <summary>
        /// The amount of consumable ammo has changed. Update the loaded and unloaded count.
        /// </summary>
        /// <param name="item">The item whose consumable ammo has changed.</param>
        /// <param name="added">True if the consumable items were added.</param>
        /// <param name="immediateChange">True if the consumable item count should be changed immediately. This is not used by the ItemMonitor.</param>
        private void ConsumableItemCountChange(Item item, bool added, bool immediateChange)
        {
            var loadedCount   = m_IsPrimaryItem ? (m_MonitorType == MonitorType.ItemExtension ? m_FirstExtensionItemCount.Get() : m_PrimaryLoadedCount.Get()) : m_DualWieldLoadedCount.Get();
            var unloadedCount = m_IsPrimaryItem ? m_PrimaryUnloadedCount.Get() : m_DualWieldUnloadedCount.Get();

            // Don't update if monitoring a hand and the hand doesn't match.
            if ((item.RightItemSprite && m_MonitorType == MonitorType.LeftHand) || (!item.RightItemSprite && m_MonitorType == MonitorType.RightHand))
            {
                if (m_UnloadedCountText != null)
                {
                    if (loadedCount != int.MaxValue && loadedCount != -1)
                    {
                        m_UnloadedCountText.text = unloadedCount.ToString();
                    }
                    else
                    {
                        m_UnloadedCountText.text = string.Empty;
                    }
                }
                return;
            }

            if (loadedCount != int.MaxValue && loadedCount != -1)
            {
                if (m_MonitorType == MonitorType.ItemExtension)
                {
                    m_LoadedCountText.text = loadedCount.ToString();
                }
                else
                {
                    // If ItemUnloadedCountText is null then the ItemCount should show the loaded and unloaded count.
                    if (m_UnloadedCountText == null)
                    {
                        m_LoadedCountText.text = (loadedCount + unloadedCount).ToString();
                    }
                    else
                    {
                        m_LoadedCountText.text   = loadedCount.ToString();
                        m_UnloadedCountText.text = unloadedCount.ToString();
                    }
                }
            }
            else
            {
                // If the amount is unlimited then show an empty string.
                m_LoadedCountText.text = string.Empty;
                if (m_UnloadedCountText != null)
                {
                    m_UnloadedCountText.text = string.Empty;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// The amount of secondary ammo has changed. Update the count.
        /// </summary>
        private void SecondaryItemCountChange()
        {
            var itemCount = m_SecondaryItemCount.Get();

            if (itemCount != int.MaxValue && itemCount != -1)
            {
                m_LoadedCountText.text = itemCount.ToString();
            }
            else
            {
                m_LoadedCountText.text = string.Empty;
            }
        }
Пример #8
0
        /// <summary>
        /// Starts executing the ability. AbilityStarted may be delayed if the character cannot have an item equipped.
        /// </summary>
        public void StartAbility()
        {
            m_Active = true;
            EventHandler.ExecuteEvent <Ability>(m_GameObject, "OnAbilityStart", this);

            // m_EquipItem may already be true if the ability set it ahead of time.
            if (m_EquipItem || CanHaveItemEquipped() || m_ItemEquipped.Get() == false)
            {
                AbilityStarted();
            }
            else
            {
                m_EquipItem = true;
                EventHandler.RegisterEvent(m_GameObject, "OnAnimatorItemUnequipped", AbilityStarted);
                EventHandler.ExecuteEvent(m_GameObject, "OnAbilityToggleEquippedItem");
            }
        }
Пример #9
0
 /// <summary>
 /// Show or hide the item slice.
 /// </summary>
 /// <param name="visible">Should the item slice be shown?</param>
 private void ToggleVisiblity(bool visible)
 {
     // Set the correct color if the slice is visible.
     if (visible)
     {
         if (m_PrimaryItemType == null || !m_HasItem.Invoke(m_PrimaryItemType))
         {
             m_Image.color = m_DisabledColor;
         }
         else if (m_PrimaryItemType == m_CurrentPrimaryItem.Get().ItemType || (m_CurrentDualWieldItem.Get() != null && m_PrimaryItemType == m_CurrentDualWieldItem.Get().ItemType))
         {
             m_Image.color = m_SelectedColor;
         }
         else
         {
             m_Image.color = m_NotSelectedColor;
         }
         for (int i = 0; i < m_ChildImages.Length; ++i)
         {
             m_ChildImages[i].color = m_Image.color;
         }
     }
     m_GameObject.SetActive(visible);
 }
Пример #10
0
        /// <summary>
        /// The character has been attached to the camera. Update the UI reference and initialze the character-related values.
        /// </summary>
        /// <param name="character">The character that the UI is monitoring.</param>
        private void AttachCharacter(GameObject character)
        {
            if (m_Character == character)
            {
                return;
            }

            if (m_Character != null)
            {
                if (m_MonitorType != MonitorType.Secondary)
                {
                    if (m_MonitorType == MonitorType.LeftHand || m_MonitorType == MonitorType.RightHand)
                    {
                        EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
                        EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange);
                    }
                    else if (m_MonitorType == MonitorType.Primary || m_MonitorType == MonitorType.ItemExtension)
                    {
                        EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
                    }
                    else
                    {
                        EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange);
                    }
                }
                else
                {
                    EventHandler.UnregisterEvent(m_Character, "OnInventorySecondaryItemCountChange", SecondaryItemCountChange);
                }
            }

            m_Character = character;

            if (character == null)
            {
                // The object may be destroyed when Unity is ending.
                if (this != null)
                {
                    gameObject.SetActive(false);
                }
                return;
            }

            SharedManager.InitializeSharedFields(m_Character, this);

            // Register for the events. Do not register within OnEnable because the character may not be known at that time.
            if (m_MonitorType != MonitorType.Secondary)
            {
                if (m_MonitorType == MonitorType.LeftHand || m_MonitorType == MonitorType.RightHand)
                {
                    EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
                    EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange);
                    PrimaryItemChange(m_CurrentPrimaryItem.Get());
                    DualWieldItemChange(m_CurrentDualWieldItem.Get());
                }
                else if (m_MonitorType == MonitorType.Primary || m_MonitorType == MonitorType.ItemExtension)
                {
                    EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);
                    PrimaryItemChange(m_CurrentPrimaryItem.Get());
                }
                else
                {
                    EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange);
                    DualWieldItemChange(m_CurrentDualWieldItem.Get());
                }
                EventHandler.RegisterEvent <Item, bool, bool>(m_Character, "OnInventoryConsumableItemCountChange", ConsumableItemCountChange);
            }
            else
            {
                EventHandler.RegisterEvent(m_Character, "OnInventorySecondaryItemCountChange", SecondaryItemCountChange);

                // Initialize the secondary values.
                SecondaryItemCountChange();
            }

            gameObject.SetActive(true);
        }
Пример #11
0
        /// <summary>
        /// The item has changed. Update the UI.
        /// </summary>
        private void ItemChange()
        {
            if (m_Image == null)
            {
                return;
            }

            Item item        = null;
            var  currentItem = m_CurrentPrimaryItem.Get();

            if (currentItem != null && (m_MonitorType != MonitorType.ItemExtension && (currentItem.RightItemSprite == (m_MonitorType == MonitorType.RightHand) || m_MonitorType == MonitorType.Primary) ||
                                        (m_MonitorType == MonitorType.ItemExtension && m_FirstExtensionItemCount.Get() > -1)))
            {
                item            = currentItem;
                m_IsPrimaryItem = true;
            }
            else if ((currentItem = m_CurrentDualWieldItem.Get()) != null && (currentItem.RightItemSprite == (m_MonitorType == MonitorType.RightHand) || m_MonitorType == MonitorType.DualWield))
            {
                item            = currentItem;
                m_IsPrimaryItem = false;
            }

            if (item == null)
            {
                if (m_MonitorType != MonitorType.ItemExtension)
                {
                    // Disable the UI if there is no item or sprite.
                    m_Image.sprite  = null;
                    m_Image.enabled = false;
                }
                m_LoadedCountText.enabled = m_Image.enabled = false;
                if (m_UnloadedCountText != null)
                {
                    m_UnloadedCountText.enabled = false;
                }
                if (m_DisableObjectOnEmpty != null)
                {
                    m_DisableObjectOnEmpty.SetActive(false);
                }
            }
            else
            {
                if (m_MonitorType != MonitorType.ItemExtension)
                {
                    // There is an item so ensure the UI is enabled.
                    if (item.ItemSprite == null)
                    {
                        m_Image.sprite  = null;
                        m_Image.enabled = false;
                    }
                    else
                    {
                        m_Image.sprite  = item.ItemSprite;
                        m_Image.enabled = true;
                    }

                    // Position the sprite in the center.
                    if (m_Image.sprite != null)
                    {
                        var sizeDelta = m_RectTransform.sizeDelta;
                        sizeDelta.x = m_Image.sprite.textureRect.width;
                        sizeDelta.y = m_Image.sprite.textureRect.height;
                        m_RectTransform.sizeDelta = sizeDelta;
                    }
                }
                else
                {
                    m_Image.enabled = true;
                }

                m_LoadedCountText.enabled = true;
                if (m_UnloadedCountText != null)
                {
                    m_UnloadedCountText.enabled = true;
                }
                if (m_DisableObjectOnEmpty != null)
                {
                    m_DisableObjectOnEmpty.SetActive(true);
                }

                // Update the loaded and unloaded count.
                ConsumableItemCountChange(item, false, false);
            }
        }