コード例 #1
0
 private void Update()
 {
     if (_showInformationPanel && _slots[_currentSlotIndex].ItemBehaviour != null)
     {
         _inventoryInformationPanelBehaviour.Show(_slots[_currentSlotIndex].ItemBehaviour);
     }
     else
     {
         _inventoryInformationPanelBehaviour.Hide();
     }
 }
コード例 #2
0
        private void Start()
        {
            _slots = GetComponentsInChildren <InventorySlotBehaviour>();

            _nearbyItems = new List <ItemBehaviour>();

            _inventorySlotIndicatorBehaviour = GetComponentInChildren <InventorySlotIndicatorBehaviour>();

            _inventoryInformationPanelBehaviour = GetComponentInChildren <InventoryInformationPanelBehaviour>();
            _inventoryInformationPanelBehaviour.Hide();

            _inventoryInformationPanelBehaviour.transform.position      =
                _inventoryInformationPanelBehaviour.transform.position += new Vector3(0.0f, 5.0f, 0.0f);

            _player = GameObject.Find("Player");
        }
        private void Update()
        {
            ItemBehaviour itemBehaviour = _inventoryBehaviour.GetNearbyItem();

            if (itemBehaviour != null)
            {
                Vector3 itemPosition = itemBehaviour.transform.position;
                _itemPickerObject.transform.position = itemPosition + new Vector3(0.0f, 0.75f, 0.0f);

                const float spacing = 2.75f, doubleSpacing = spacing * 2.0f, screenSpacing = 250.0f;

                Vector3 informationPanelPosition =
                    itemPosition + new Vector3(_playerObject.transform.position.x > itemPosition.x ? -spacing : spacing,
                                               0.0f, 0.0f);

                Vector3 informationPanelScreenPosition =
                    UnityEngine.Camera.main.WorldToScreenPoint(informationPanelPosition);

                if (informationPanelScreenPosition.x + screenSpacing > Screen.width)
                {
                    informationPanelPosition.x -= doubleSpacing;
                }
                else if (informationPanelScreenPosition.x - screenSpacing < 0.0f)
                {
                    informationPanelPosition.x += doubleSpacing;
                }

                _itemPickerObject.SetActive(true);
                _inventoryInformationPanelBehaviour.Show(itemBehaviour, informationPanelPosition);
            }
            else
            {
                _inventoryInformationPanelBehaviour.Hide();
                _itemPickerObject.SetActive(false);
            }
        }