예제 #1
0
        private void onCharacterClickHandler(object publishedEvent)
        {
            CharacterClickEvent e = publishedEvent as CharacterClickEvent;
            var        position   = e.ClickedPosition;
            IClickable obj        = e.ClickedObject?.GetComponent <IClickable>();
            Character  character  = e.ClickedObject?.GetComponent <Character>();

            Observer.Publish(new ResetSingleEffectEvent("Character_On_Ground_Click_Effect"));

            if (character == this)
            {
                _status = clickStatus.CHARACTER;
            }
            else if (obj != null)
            {
                if (_status == clickStatus.FRIST_CLICK &&
                    obj.Contains(_fristClickPosition))
                {
                    _status = clickStatus.SECOND_CLICK;
                }
                else if ((_status == clickStatus.FRIST_CLICK &&
                          !obj.Contains(_fristClickPosition)) ||
                         _status == clickStatus.CHARACTER)
                {
                    _fristClickPosition = e.ClickedObject.transform.position;
                    obj.isClicked       = true;
                    _status             = clickStatus.FRIST_CLICK;
                }

                ClickPos = e.ClickedObject.transform.position;
            }
            else if (e.ClickedObject?.tag == "ground") //todo: hardcoded
            {
                if (_status == clickStatus.FRIST_CLICK &&
                    Vector3.Distance(position, _fristClickPosition) < 0.5f)
                {
                    _status = clickStatus.SECOND_CLICK;
                }
                else if ((_status == clickStatus.FRIST_CLICK &&
                          Vector3.Distance(position, _fristClickPosition) > 0.5f) ||
                         _status == clickStatus.CHARACTER)
                {
                    Observer.Publish(new ExecuteEffectEvent(position, "Character_On_Ground_Click_Effect"));
                    _fristClickPosition = position;
                    _status             = clickStatus.FRIST_CLICK;
                }

                ClickPos = position;
            }
            else if (e.ClickedObject == null)
            {
                _status = clickStatus.ESC;
                Observer.Publish(new VoidResetEvent());
                isClicked = false;
            }
        }
예제 #2
0
        public void ProcessMouse(MouseData data)
        {
            ivec2 mouseLocation = data.Location;

            if (hoveredItem != null && !hoveredItem.Contains(mouseLocation))
            {
                hoveredItem.OnUnhover();
                hoveredItem = null;
            }

            foreach (IClickable item in Items)
            {
                if (item != hoveredItem && item.Contains(mouseLocation))
                {
                    // It's possible for the mouse to move between items in a single frame.
                    hoveredItem?.OnUnhover();
                    hoveredItem = item;
                    hoveredItem.OnHover(mouseLocation);

                    break;
                }
            }

            // It's also possible for the mouse to move to a new item and click on the same frame (which is rare, but
            // considered a valid click).
            if (hoveredItem != null && data.Query(GLFW_MOUSE_BUTTON_LEFT, InputStates.PressedThisFrame))
            {
                hoveredItem.OnClick(mouseLocation);
            }
        }