public override void UpdateClick(IClickable button)
 {
     Game1.self.FocusedElement = button;
     if (button is Dropdown)
     {
         Dropdown d = (Dropdown)button;
         if (d.ShowChildren)
         {
             button.OnClick();
             d.Active = false;
         }
         else
         {
             d.ShowChildren = true;
             d.Update();
             dropClicked   = true;
             button.Active = false;
             d.Active      = true;
         }
     }
     else if (button.Parent is Dropdown)
     {
         dropClicked = true;
         Dropdown d = (Dropdown)button.Parent;
         button.OnClick();
         // d.Active = true;
     }
     else
     {
         button.OnClick();
     }
 }
Ejemplo n.º 2
0
 IEnumerator ClickListener()
 {
     while (mouse_over)
     {
         if (clickable.can_click && Input.GetMouseButtonDown(0))
         {
             clickable.OnLeftClickDown();
             bool mouse_left = false;
             while (clickable.can_click && !Input.GetMouseButtonUp(0))
             {
                 mouse_left = !mouse_over || mouse_left || clickable.must_drag;
                 if (mouse_left)
                 {
                     clickable.OnHoldDrag(OverObject(), OverPosition());
                 }
                 yield return(null);
             }
             if (!mouse_left)
             {
                 clickable.OnClick();
             }
             else
             {
                 clickable.OnFinishDrag(OverObject(), OverPosition());
             }
             clickable.OnEndClick();
         }
         yield return(null);
     }
 }
Ejemplo n.º 3
0
    private void Update()
    {
        Vector3 clickPos  = Vector3.zero;
        bool    isClicked = false;

        if (Input.GetMouseButtonDown(0))
        {
            clickPos  = Input.mousePosition;
            isClicked = true;
        }
        else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            clickPos  = Input.GetTouch(0).position;
            isClicked = true;
        }

        if (isClicked)
        {
            var worldPos      = Camera.main.ScreenToWorldPoint(clickPos);
            var worldClickPos = new Vector2(worldPos.x, worldPos.y);

            if (col == Physics2D.OverlapPoint(worldClickPos))
            {
                context.OnClick();
            }
        }
    }
Ejemplo n.º 4
0
    public override void Execute(float d)
    {
        if (Input.GetMouseButton(0))
        {
            if (!GameManager.Instance.clicking)
            {
                PointerEventData pointerData = new PointerEventData(EventSystem.current);
                pointerData.position = Input.mousePosition;

                List <RaycastResult> results = new List <RaycastResult>();

                //get all objects our pointer is overlapping with
                EventSystem.current.RaycastAll(pointerData, results);

                foreach (RaycastResult r in results)
                {
                    IClickable c = r.gameObject.GetComponentInParent <IClickable>();
                    if (c != null)
                    {
                        c.OnClick();
                        break;
                    }
                }
            }
            GameManager.Instance.clicking = true;
        }
    }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     if (controllable)
     {
         if (!EventSystem.current.IsPointerOverGameObject())
         {
             Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hitInfo;
             if (Physics.Raycast(ray, out hitInfo))
             {
                 if (targetObject != hitInfo.collider.gameObject)
                 {
                     targetObject = hitInfo.collider.gameObject;
                     mouseTarget  = targetObject.GetComponent <IClickable>();
                     if (mouseTarget != null)
                     {
                         targetClickable = true;
                         mouseTarget.MouseOver(Survivors.instance.GetActiveSurvivor(), activeItem);
                     }
                     else
                     {
                         targetClickable = false;
                         Cursor.SetCursor(mouseCursorImage, Vector2.zero, CursorMode.Auto);
                     }
                 }
                 if (Input.GetMouseButtonUp(0))
                 {
                     if (targetClickable)
                     {
                         mouseTarget.OnClick(Survivors.instance.GetActiveSurvivor(), activeItem);
                         Cursor.SetCursor(mouseCursorImage, Vector2.zero, CursorMode.Auto);
                         targetObject    = null;
                         mouseTarget     = null;
                         targetClickable = false;
                     }
                     StopUsingItem();
                 }
             }
             else
             {
                 //MAKE THIS ONLY RUN ONCE
                 targetObject    = null;
                 mouseTarget     = null;
                 targetClickable = false;
                 Cursor.SetCursor(mouseCursorImage, Vector2.zero, CursorMode.Auto);
             }
         }
         else
         {
             //MAKE THIS ONLY RUN ONCE
             targetObject    = null;
             mouseTarget     = null;
             targetClickable = false;
             Cursor.SetCursor(mouseCursorImage, Vector2.zero, CursorMode.Auto);
         }
     }
 }
Ejemplo n.º 7
0
    void ClickCast()
    {
        var hit = RaycastAt(input.mouseWorldPosition);

        if (hit)
        {
            IClickable clickable = hit.collider.GetComponent <IClickable>();
            clickable?.OnClick();
        }
    }
Ejemplo n.º 8
0
    void Clicked()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new RaycastHit();

        if (Physics.Raycast(ray, out hit))
        {
            IClickable clickable = hit.collider.gameObject.GetComponent <IClickable>();
            clickable.OnClick(hit);
        }
    }
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.Mouse1))
     {
         Vector2      mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
         RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);
         if (hit)
         {
             IClickable clickable = hit.collider.GetComponent <IClickable>();
             clickable?.OnClick();
         }
         else
         {
             Debug.Log("Click did not hit anything.");
         }
     }
 }
Ejemplo n.º 10
0
        public override void Execute(float d)
        {
            if (Input.GetMouseButtonDown(0))
            {
                List <RaycastResult> results = Settings.GetUIObjects();

                foreach (RaycastResult r in results)
                {
                    IClickable c = r.gameObject.GetComponentInParent <IClickable>();
                    if (c != null)
                    {
                        c.OnClick();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 // Update is called once per frame
 void Update()
 {
     //On mouse click check if there is a tile to select
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = _camera.ScreenPointToRay(Input.mousePosition);
         RaycastHit _rh;
         if (Physics.Raycast(ray, out _rh, rayDistance, tileHitLayerMask))
         {
             IClickable hit = _rh.transform.GetComponent <IClickable>();
             if (hit != null)
             {
                 hit.OnClick();
             }
         }
     }
 }
        private void Update()
        {
            if (!_enabled)
            {
                return;
            }

            if (_inputProvider.GetButtonDown(0))
            {
                var origin = Camera.main.ScreenToWorldPoint(_inputProvider.MousePosition);
                var hit    = Physics2D.Raycast(origin, Vector2.zero, 200);
                if (hit.collider != null &&
                    hit.collider.gameObject.GetComponent <IClickable>() != null)
                {
                    _startMousePos = _inputProvider.MousePosition;
                    _clickedObject = hit.collider.gameObject.GetComponent <IClickable>();
                }

                NoInputTime = 0;
            }

            if (_clickedObject != null && _inputProvider.GetButtonUp(0))
            {
                var mouseDelta = Mathf.Abs(_inputProvider.MousePosition.magnitude - _startMousePos.magnitude);
                if (mouseDelta < AllowedMovement)
                {
                    _clickedObject.OnClick();
                    OnClick?.Invoke(_clickedObject);
                }

                _clickedObject = null;
                NoInputTime    = 0;
            }

            NoInputTime += Time.deltaTime;
            if (NoInputTime >= _timeToHint)
            {
                OnTimeToHint?.Invoke();
                NoInputTime = 0;
            }
        }
Ejemplo n.º 13
0
    protected virtual void ChechClick( )
    {
#if UNITY_EDITOR || UNITY_STANDALONE
        if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject go = hit.collider.gameObject;
                IClickable clickableGameObject = go.GetComponent <IClickable>();
                if (clickableGameObject != null)
                {
                    float distance = Vector3.Distance(transform.position, hit.collider.transform.position);
                    clickableGameObject.OnClick(distance);
                }
            }
        }
#elif UNITY_IOS || UNITY_ANDROID
        if (Input.touchCount > 0 && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(0))
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Ended)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject go = hit.collider.gameObject;
                    IClickable clickableGameObject = go.GetComponent <IClickable>();
                    if (clickableGameObject != null)
                    {
                        float distance = Vector3.Distance(transform.position, hit.collider.transform.position);
                        clickableGameObject.OnClick(distance);
                    }
                }
            }
        }
#endif
    }
Ejemplo n.º 14
0
    public override void Execute(float d)
    {
        if (Input.GetMouseButtonDown(0))
        {
            PointerEventData pointerData = new PointerEventData(EventSystem.current)
            {
                position = Input.mousePosition
            };

            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(pointerData, results);

            foreach (RaycastResult r in results)
            {
                IClickable c = r.gameObject.GetComponentInParent <IClickable>();
                if (c != null)
                {
                    c.OnClick();
                    break;
                }
            }
        }
    }
Ejemplo n.º 15
0
    void Update()
    {
        if (isPopupOn == true)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0)) // Left
        {
            Vector3        mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Ray2D          ray      = new Ray2D(mousePos, Vector2.zero);
            RaycastHit2D[] hits     = Physics2D.RaycastAll(ray.origin, ray.direction); //부딪히는 모든 콜라이더 검출

            foreach (var hit in hits)
            {
                IClickable clickable = hit.transform.GetComponent <IClickable>();
                if (clickable != null)
                {
                    clickable.OnClick();
                }
            }
        }
    }
Ejemplo n.º 16
0
        private void Update()
        {
            EventSystem currentSystem = EventSystem.current;

            HandleOverlayUI();
            if (currentSystem.IsPointerOverGameObject())
            {
                return;
            }
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000))
                {
                    IClickable iClickable = hit.transform.GetComponent <IClickable>();
                    if (iClickable != null)
                    {
                        iClickable.OnClick(this);
                    }
                    else
                    {
                        if (mSelectedUnit != null)
                        {
                            uiOverlay.CloseInteractions();
                            NavMeshHit nHit;
                            if (NavMesh.SamplePosition(hit.point, out nHit, 1, NavMesh.AllAreas))
                            {
                                mTargetUIOverlayPos = Input.mousePosition;
                                stepOverlayUI.gameObject.SetActive(true);
                                mSelectedUnit.AddSteps(nHit.position);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
    void Update()
    {
        //Check if there's a pickupable item in front
        RaycastHit hit;

        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, RayRange, ~raycastIgnoreLayer))
        {
            IGetable pickup = hit.collider.GetComponent <IGetable>();
            if (holdingItem == null)
            {
                if (pickup != null)
                {
                    Debug.Log("there's a pickup object");
                    if (Input.GetKeyDown("e"))
                    {
                        pickup.OnGet(itemPlace);
                        holdingItem = hit.transform.gameObject;
                        return;
                    }
                }
            }
        }

        //when you're holding an item
        if (holdingItem != null)
        {
            RaycastHit hot;
            if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hot, RayRange, ~raycastIgnoreLayer))
            {
                IClickable clicable = hot.collider.GetComponent <IClickable>();
                if (clicable != null)
                {
                    if (Input.GetMouseButtonDown(1))
                    {
                        if (holdingItem != null)
                        {
                            clicable.OnClick(holdingItem, this.gameObject);
                        }
                        return;
                    }
                }
            }
            //if held item is an interactable
            IInteractable interactable = holdingItem.GetComponent <IInteractable>();
            if (interactable != null)
            {
                RaycastHit het;
                if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out het, RayRange, ~raycastIgnoreLayer))
                {
                    Debug.DrawRay(playerCamera.transform.position, playerCamera.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
                    Crafter CraftingTable = het.collider.GetComponent <Crafter>();
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (CraftingTable != null)
                        {
                            interactable.OnInteract(CraftingTable.gameObject);
                        }
                        else
                        {
                            interactable.OnInteract();
                        }
                        return;
                    }
                }
            }

            //drop the held item
            if (Input.GetKeyDown("e"))
            {
                holdingItem.GetComponent <IGetable>().OnDrop(playerCamera.gameObject);
                holdingItem = null;
            }
        }

        //Check if there's an clickable object in front;
        RaycastHit hat;

        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hat, RayRange, ~raycastIgnoreLayer))
        {
            IClickable clicable = hat.collider.GetComponent <IClickable>();
            if (clicable != null)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    clicable.OnClick();
                    return;
                }
            }
        }
    }
Ejemplo n.º 18
0
 public virtual void UpdateClick(IClickable button)
 {
     Game1.self.FocusedElement = button;
     button.OnClick();
 }