Beispiel #1
0
        /// <summary>
        /// If there's an item in this slot, draws its icon inside.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="index">Index.</param>
        public virtual void DrawIcon(InventoryItem item, int index)
        {
            if (ParentInventoryDisplay != null)
            {
                if (!InventoryItem.IsNull(item))
                {
                    GameObject itemIcon = new GameObject("Icon", typeof(RectTransform));
                    itemIcon.transform.SetParent(this.transform);
                    UnityEngine.UI.Image itemIconImage = itemIcon.AddComponent <Image>();
                    itemIconImage.sprite = item.Icon;
                    RectTransform itemRectTransform = itemIcon.GetComponent <RectTransform>();
                    itemRectTransform.localPosition = Vector3.zero;
                    itemRectTransform.localScale    = Vector3.one;
                    MMGUI.SetSize(itemRectTransform, ParentInventoryDisplay.IconSize);

                    // if there's more than one of this item in this slot, we draw the associated quantity
                    if (item.Quantity > 1)
                    {
                        GameObject textObject = new GameObject("Slot " + index + " Quantity", typeof(RectTransform));
                        textObject.transform.SetParent(this.transform);
                        Text textComponent = textObject.AddComponent <Text>();
                        textComponent.text      = item.Quantity.ToString();
                        textComponent.font      = ParentInventoryDisplay.QtyFont;
                        textComponent.fontSize  = ParentInventoryDisplay.QtyFontSize;
                        textComponent.color     = ParentInventoryDisplay.QtyColor;
                        textComponent.alignment = ParentInventoryDisplay.QtyAlignment;
                        RectTransform textObjectRectTransform = textObject.GetComponent <RectTransform>();
                        textObjectRectTransform.localPosition = Vector3.zero;
                        textObjectRectTransform.localScale    = Vector3.one;
                        MMGUI.SetSize(textObjectRectTransform, (ParentInventoryDisplay.SlotSize - Vector2.one * ParentInventoryDisplay.QtyPadding));
                    }
                }
            }
        }
Beispiel #2
0
        protected override void DetectMouse()
        {
            if (UIShouldBlockInput && MMGUI.PointOrTouchBlockedByUI())
            {
                return;
            }

            if (Input.GetMouseButtonDown(MouseButtonIndex))
            {
                if (_isDoubleClick)
                {
                    _characterRun.RunStart();
                    StopCoroutine(_doubleClick);
                    _isDoubleClick = false;
                }
                else
                {
                    _characterRun.RunStop();
                    _doubleClick = StartCoroutine(DoubleClick());
                }
            }

            if (!Input.GetMouseButtonDown(MouseButtonIndex) && !Input.GetMouseButton(MouseButtonIndex))
            {
                return;
            }
            var ray = _mainCamera.ScreenPointToRay(Input.mousePosition);

#if UNITY_EDITOR
            Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow);
#endif
            if (Physics.Raycast(ray, out var hitInfo, Mathf.Infinity, TargetLayerMask))
            {
                _brain.Target = hitInfo.transform;
                _characterPathfinder3D.SetNewDestination(_brain.Target);
                return;
            }
            _brain.Target = null;
            if (_brain.CurrentState != _initialState)
            {
                _brain.TransitionToState(_initialState.StateName);
            }
            if (!_playerPlane.Raycast(ray, out var distance))
            {
                return;
            }
            Destination.transform.position = ray.GetPoint(distance);
            _characterPathfinder3D.SetNewDestination(Destination.transform);
            if (Input.GetMouseButtonDown(MouseButtonIndex))
            {
                OnClickFeedbacks?.PlayFeedbacks(Destination.transform.position);
            }
        }