예제 #1
0
        public InteractionInputHandler(IInteractionInterface inInteractionInterface)
            : base()
        {
            InteractionInterface = inInteractionInterface;

            ButtonResponses.Add(EInputKey.Interact, OnInteractButton);
        }
    /// <summary>
    /// 检查是否可以交互
    /// </summary>
    private void RayInspect()
    {
        RaycastHit[] raycastHit = Physics.SphereCastAll(interactionPosition + transform.position, radius, transform.forward, radius / 2, layer);
        if (raycastHit.Length >= 1)
        {
            interaction = raycastHit[0].collider.GetComponent <IInteractionInterface>();
            if (interaction != null)
            {
                if (interaction.InteractionType == InteractionType.collect)
                {
                    collect = interaction as ICollect;
                    HintMessage.Single.ShowMessageText($"{collect.Name}:采集");
                }
                else if (interaction.InteractionType == InteractionType.bulid)
                {
                    HintMessage.Single.ShowMessageText("Q:销毁\nE:建造");
                    bulid = interaction as IBulid;
                }
            }
            else
            {
                House house = raycastHit[0].collider.GetComponent <House>();

                if (house != null)
                {
                    if (house.houseMenu.gameObject.activeSelf)
                    {
                        if (Input.GetKeyDown(KeyCode.E))
                        {
                            house.CloseMenu();
                        }
                        HintMessage.Single.CloseMessageText();
                    }
                    else
                    {
                        HintMessage.Single.ShowMessageText("E:打开菜单");
                        if (Input.GetKeyDown(KeyCode.E))
                        {
                            house.OpenMenu();
                        }
                    }
                }
            }
        }
        else
        {
            interaction = null;
            HintMessage.Single.CloseMessageText();
        }
    }