Example #1
0
        public override void Update()
        {
            if (!pickupEventRepository.HasValue)
            {
                return;
            }

            var pickupEvent = pickupEventRepository.Value;

            var gameObject = pickupEvent.Marker.gameObject;

            if (PositionHelper.GetDistance(player, gameObject.transform) <= config.InteractCriticalDistance)
            {
                pickupEventRepository.RemoveValue();
                movementEventRepository.RemoveValue();

                addToInventoryEventRepository.SetValue(new AddToInventoryEvent(pickupEvent.Marker.Id));
            }
        }
        public override void Update()
        {
            if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.PickupableItem) ||
                MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.Npc) ||
                MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.SceneTransfer) ||
                MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.DialogueButton) ||
                MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.FinishDialogueButton))
            {
                cursor = Resources.Load <Texture2D>("pointer");
            }
            else
            {
                cursor = Resources.Load <Texture2D>("normal");
            }

            Cursor.SetCursor(cursor, new Vector2(0, 0), CursorMode.Auto);

            if (Input.GetMouseButtonDown(0))
            {
                if (Input.mousePosition != previousPointClicked && previousClickDateTime - DateTime.UtcNow < TimeSpan.FromMilliseconds(200)) // у нас происходит двойной клик. Для кнопок это критично
                {                                                                                                                            // Поэтому я сохраняю предыдущую точку нажатия и сравниваю её с текущей
                    previousClickDateTime = DateTime.UtcNow;
                    previousPointClicked  = Input.mousePosition;
                    movementEventRepository.RemoveValue();
                    pickupEventRepository.RemoveValue();
                    interactWithNpcEventRepository.RemoveValue();
                    newTextEventRepository.RemoveValue();

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.Ground))
                    {
                        ProcessMovement();
                    }

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.PickupableItem))
                    {
                        ProcessPickup();
                    }

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.Npc))
                    {
                        ProcessNpc();
                    }

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.DialogueButton))
                    {
                        ProcessButton();
                    }

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.FinishDialogueButton))
                    {
                        ProcessFinishDialogue();
                    }

                    if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.SceneTransfer))
                    {
                        ProcessSceneTransition();
                    }
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                if (MouseHelper.IsMouseAboveObjectWithTag(Constants.Tags.PickupableItem))
                {
                    var marker = MouseHelper.GetComponentOnGameObjectUnderMouse <PickupableItemMarker>();
                    startDialogueEventRepository.SetValue(new StartDialogueEvent(marker.Id, "You"));
                }
            }
        }