コード例 #1
0
    private void HandleMouseClick()
    {
        pointerEventData          = new PointerEventData(eventSystem);
        pointerEventData.position = transform.position;

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

        raycaster.Raycast(pointerEventData, results);

        foreach (RaycastResult result in results)
        {
            if (result.gameObject.GetComponent <Button>())
            {
                ExecuteEvents.Execute(result.gameObject, new BaseEventData(eventSystem), ExecuteEvents.submitHandler);
            }
        }

        // for physical button

        var        ray = Camera.main.ScreenPointToRay(transform.position);
        RaycastHit Hit;

        if (Physics.Raycast(ray, out Hit) && Hit.collider.gameObject.GetComponent <PhysicalButton>())
        {
            Hit.collider.gameObject.GetComponent <PhysicalButton>().Click();
        }
    }
コード例 #2
0
ファイル: CursorBehaviour.cs プロジェクト: MisterKidX/Unity
    private void Update()
    {
        PointerEventData data = new PointerEventData(_eventSystem);
        var results           = new List <RaycastResult>();

        data.position = Input.mousePosition;
        _raycaster.Raycast(data, results);
        Selectable s;

        foreach (var result in results)
        {
            var res = result.gameObject.GetComponent <Selectable>();
            if (res && res.IsInteractable())
            {
                _isSelectMode = true;
            }
            else
            {
                _isSelectMode = false;
            }
        }

        if (_isSelectMode)
        {
            Cursor.SetCursor(selectMouse, new Vector2(128, 128), CursorMode.Auto);
        }
        else
        {
            Cursor.SetCursor(regularMouse, new Vector2(128, 128), CursorMode.Auto);
        }
    }
コード例 #3
0
 /// <summary>
 /// Handles MouseInput
 /// </summary>
 private void MouseInputs()
 {
     // Click
     if (Input.GetMouseButtonDown(0))
     {
         // Raycast and select
         PointerEventData data = new PointerEventData(eventSystem)
         {
             position = Input.mousePosition
         };
         List <RaycastResult> results = new List <RaycastResult>();
         caster.Raycast(data, results);
         if (results.Count > 0 && results[0].gameObject.tag == barTag)    // Found an object
         {
             draggedImage = results[0].gameObject.GetComponent <Image>(); // Set as Dragged
             mousePos     = Input.mousePosition;                          // Store position
         }
     }
     else if (Input.GetMouseButton(0) && draggedImage != null) // Held (Drag)
     {
         // Move Image-Pos
         float deltaY = Input.mousePosition.y - mousePos.y;
         draggedImage.transform.Translate(0, deltaY, 0, Space.Self);
         // Clamp Position
         draggedImage.transform.localPosition = new Vector3(draggedImage.transform.localPosition.x, Mathf.Clamp(draggedImage.transform.localPosition.y, -45, 45), draggedImage.transform.localPosition.z);
         mousePos = Input.mousePosition;
     }
     else if (Input.GetMouseButtonUp(0)) // Released
     {
         // Deselect
         draggedImage = null;
     }
 }
コード例 #4
0
ファイル: CWVRCanvas.cs プロジェクト: chilton/CWVRGUI
    // This is decidedly indirect. We get our pointer event data from the event system, then
    // set our position to the center point of the camera,
    // then create a list to store hits in
    // and then we cast our ray and do our hit test.

    public void TrackPointer()
    {
        pointerEventData          = new PointerEventData(eventSystem);
        pointerEventData.position = VRCamera.ViewportToScreenPoint(new Vector2(0.5f, 0.5f));

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

        raycaster.Raycast(pointerEventData, results);

        if (results.Count == 0)
        {
            if (lastObject != null)
            {
                EventSystem.current.SetSelectedGameObject(null);
                lastObject = null;
            }
        }
        else
        {
            // in my tests, results[0] was always the closest item. In the case of buttons, it would hit the text sometimes.
            // so we send that Select message up the flag pole, just in case that's what happened.
            if (lastObject != results[0].gameObject)
            {
                EventSystem.current.SetSelectedGameObject(null);


                results[0].gameObject.SendMessageUpwards("Select", SendMessageOptions.DontRequireReceiver);
                lastObject = results[0].gameObject;
            }
        }
    }
コード例 #5
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var ped = new PointerEventData(null)
            {
                position = Input.mousePosition
            };
            List <RaycastResult> results = new List <RaycastResult>();
            gr.Raycast(ped, results);

            if (results.Count <= 0)
            {
                return;
            }
            RaycastHit hitInfo;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hitInfo))
            {
                go = Instantiate(obstacle, new Vector3(hitInfo.point.x - 3.0f, 0.0f, hitInfo.point.z), Quaternion.Euler(-90.0f, 40.0f, -40.0f));
                obstacleList.Add(go.transform);
                go.GetComponent <RepairManager>().listNum = count;
                count++;
            }
        }
    }
コード例 #6
0
    void UIclickVirtualMouse()
    {
        ptrEventData          = new PointerEventData(eventSys);
        ptrEventData.position = Input.mousePosition;

        results = new List <RaycastResult>();

        rC.Raycast(ptrEventData, results);

        if (isPressed == false)
        {
            foreach (RaycastResult result in results)
            {
                if (Gamepad.current.aButton.isPressed)
                {
                    ExecuteEvents.Execute(result.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.submitHandler);
                    EventSystem.current.SetSelectedGameObject(null);
                    isPressed = true;
                }
            }
        }

        if (!Gamepad.current.aButton.isPressed)
        {
            isPressed = false;
        }
    }
コード例 #7
0
ファイル: Dragable.cs プロジェクト: ZitaRR/Agon-s-Path
    public void OnDrop(PointerEventData eventData)
    {
        transform.SetParent(parent);
        image.transform.position = parent.position;

        var pointer = new PointerEventData(EventSystem.current);

        pointer.position = Input.mousePosition;
        var results = new List <RaycastResult>();

        raycaster.Raycast(pointer, results);

        if (results.Count <= 0)
        {
            return;
        }

        var slot = results[0].gameObject.GetComponentInParent <Slot>();

        if (!slot || !slot.Add(image.sprite))
        {
            return;
        }

        this.slot.Remove();
    }
コード例 #8
0
    void StartDrawing()
    {
        results = new List <RaycastResult>();
        Ray r = cam.ScreenPointToRay(Input.mousePosition);

        Raycaster.Raycast(new PointerEventData(EventSystem)
        {
            position = Input.mousePosition
        }, results);

        invalid = Physics2D.Raycast(r.origin, r.direction).collider != null | results.Count > 0;

        if (invalid)
        {
            return;
        }

        drawMgr.Active = true;

        positions.Clear();
        lastPos  = cam.ScreenToWorldPoint(Input.mousePosition);
        drawnObj = drawMgr.DrawnObject(lastPos);

        SetLineEdge();
    }
コード例 #9
0
    public void OnPointerClick(PointerEventData clickData)
    {
        RaycastResult clickResult = clickData.pointerPressRaycast;

        Debug.Log(clickResult.gameObject);

        if (clickResult.gameObject)
        {
            Vector3 pointerPositionScaled = ScreenSpaceScaledVector3(clickData);
            Debug.Log(pointerPositionScaled);

            PointerEventData portalEventData = new PointerEventData(eventSystem);

            portalEventData.position = pointerPositionScaled;

            var results = new List <RaycastResult>();

            targetUIRaycaster.Raycast(portalEventData, results);

            foreach (RaycastResult result in results)
            {
                var resultButton = result.gameObject.GetComponent <Button>();

                if (resultButton)
                {
                    resultButton.OnPointerClick(portalEventData);
                }
            }
        }
    }
コード例 #10
0
 // cast a ray towards the canvas in the direction of touch and return a boolean representing whether or not a GameObject on the canvas was hit
 private bool hitCanvasElement(Touch touch){
     PointerEventData touchEventData = new PointerEventData(eventSystem);
     touchEventData.position = touch.position;
     List<RaycastResult> graphicsResults = new List<RaycastResult>(); // an out-parameter-like list, it seems
     graphicRaycaster.Raycast(touchEventData, graphicsResults);
     return graphicsResults.Count > 0;
 }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        this.transform.rotation = cam.transform.rotation;

        if (this.GetComponent <Canvas>().isActiveAndEnabled)
        {
            var dist = Vector3.Distance(this.transform.position, cam.transform.position);
            this.transform.localScale = Vector3.one * dist / initDist;

            if (Mouse.current.leftButton.wasPressedThisFrame)
            {
                //Set up the new Pointer Event
                PointerEventData     pointerData = new PointerEventData(EventSystem.current);
                List <RaycastResult> results     = new List <RaycastResult>();

                //Raycast using the Graphics Raycaster and mouse click position
                pointerData.position = Mouse.current.position.ReadValue();
                raycaster.Raycast(pointerData, results);

                //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
                foreach (RaycastResult result in results)
                {
                    FleetSelected(true);
                }

                if (results.Count == 0 && Time.fixedTime > deselectTime)
                {
                    FleetSelected(false);
                }
            }
        }
    }
コード例 #12
0
    public void Update()
    {
        //transform.position = Car.transform.position + offset;
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                m_PointerEventData          = new PointerEventData(m_EventSystem);
                m_PointerEventData.position = Input.GetTouch(i).position;
                List <RaycastResult> results = new List <RaycastResult>();
                m_Raycaster.Raycast(m_PointerEventData, results);

                foreach (RaycastResult result in results)
                {
                    if (result.gameObject.tag == "touchLayer")
                    {
                        MoveCameraWithTouch(i);
                    }
                    else
                    {
                        ResetCamera();
                    }
                }
            }
        }
        else
        {
            ResetCamera();
        }
    }
コード例 #13
0
    //This will return a string, but will also set ClickedGameObject
    public string WhatDidIClickOn(Vector3 mousePosition)
    {
        //We need to make sure that the click to build isn't a click to try and select another node

        //Raycast and check if our click is on another node
        Ray MouseRay = Camera.main.ScreenPointToRay(mousePosition);


        //Raycast and check if our click is on the GUI
        PointerEventData pointerEventData = new PointerEventData(eventSystem);

        pointerEventData.position = mousePosition;

        RaycastHit2D raycastHit = Physics2D.Raycast(MouseRay.origin, MouseRay.direction, 100);

        if (raycastHit && raycastHit.transform && raycastHit.transform.gameObject)
        {
            ClickedGameObject = raycastHit.transform.gameObject;
            return("GameObject");
        }

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

        Raycaster.Raycast(pointerEventData, results);

        if (results.Count != 0)
        {
            return("GUI");
        }

        return("Nothing");
    }
コード例 #14
0
    // Update is called once per frame
    void Update()
    {
        // Check if M1
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("Using Graphic Raycaster");
            // Setup new pointer event
            pointerEventData = new PointerEventData(eventSystem);
            // Set pointer event pos to mouse pos
            pointerEventData.position = Input.mousePosition;

            // create list of raycast results
            List <RaycastResult> results = new List <RaycastResult>();

            raycaster.Raycast(pointerEventData, results);

            // raycast with graphic raycaster and mouse click position
            foreach (RaycastResult result in results)
            {
                Debug.Log("Hit " + result.gameObject.name);
                Debug.Log("reslut ==" + result);
                Debug.Log("result.gameObject ==" + result.gameObject);
                if (result.gameObject.name == "ItemUIPrefab(Clone)")
                {
                    ;
                }
                {
                    Debug.Log("Hit an ItemUIPrefab(Clone)... sending onClick message");
                    result.gameObject.GetComponent <ItemUI>().gameObject.SendMessage("onClick"); // TODO: change this to watch for interface/interface name instead (sellable...);
                }
            }
        }
    }
コード例 #15
0
    public void UiClick(BaseEventData data)
    {
        List <RaycastResult> results     = new List <RaycastResult>();
        PointerEventData     pointerData = data as PointerEventData;

        if (canvasRaycaster == null)
        {
            canvasRaycaster = GetComponent <GraphicRaycaster>();
        }

        canvasRaycaster.Raycast(pointerData, results);

        foreach (RaycastResult result in results)
        {
            if (result.gameObject.name == "TransformButton")
            {
                uIClick = true;
            }
        }

        if (results.Count == 1)
        {
            uIClick = false;
        }
    }
コード例 #16
0
    private List <RaycastResult> RaycastAllCanvasAtScreenPosition(Vector3 p_screenPosition)
    {
        List <GameObject>    __listNullCanvas          = new List <GameObject>();
        List <RaycastResult> ___listTotalRaycastResult = new List <RaycastResult>();

        for (int i = 0; i < _listCanvas.Count; i++)
        {
            if (_listCanvas[i] != null)
            {
                if (_listCanvas[i].activeSelf == true)
                {
                    GraphicRaycaster __graphicRaycaster = _listCanvas[i].GetComponent <GraphicRaycaster>();
                    if (__graphicRaycaster != null)
                    {
                        List <RaycastResult> __listResults = new List <RaycastResult>();

                        PointerEventData __pointerEventData = new PointerEventData(EventSystem.current);
                        __pointerEventData.position = p_screenPosition;
                        __graphicRaycaster.Raycast(__pointerEventData, __listResults);
                        ___listTotalRaycastResult.AddRange(__listResults);
                    }
                }
            }
            else
            {
                __listNullCanvas.Add(_listCanvas[i]);
            }
        }

        for (int i = 0; i < __listNullCanvas.Count; i++)
        {
            _listCanvas.Remove(__listNullCanvas[i]);
        }
        return(___listTotalRaycastResult);
    }
コード例 #17
0
ファイル: Indicators.cs プロジェクト: algor1/WingScripts
    //---------------------------------- SO  END  ----------------------------



    void TouchEvents()
    {
        GraphicRaycaster gr = this.GetComponent <GraphicRaycaster>();
        //Create the PointerEventData with null for the EventSystem
        PointerEventData ped = new PointerEventData(null);

        //Set required parameters, in this case, mouse position

        for (int i = 0; i < Input.touchCount; ++i)
        {
            if (Input.GetTouch(i).phase == TouchPhase.Began)
            {
                //				print ("touch");
                ped.position = Input.GetTouch(i).position;
                //Create list to receive all results
                List <RaycastResult> results = new List <RaycastResult>();
                //Raycast it
                gr.Raycast(ped, results);
                if (results.Count > 0)
                {
                    if (indicatorsList_sh.Contains(results[0].gameObject))
                    {
                        //Debug.Log(results[0].gameObject.GetComponent<IndicatorLink>().linkedObj);//.GetComponent<ShipMotor>().thisShip.p.visibleName);
                        spaceManager.GetComponent <CommandManager>().SendUserCommand(SpaceObjects.ShipCommand.SetTargetShip, results[0].gameObject.GetComponent <IndicatorLink>().linkedObj);
                    }
                    if (indicatorsList_so.Contains(results [0].gameObject))
                    {
                        //Debug.Log (results [0].gameObject.GetComponent<IndicatorLink> ().linkedObj);//.GetComponent<ShipMotor>().thisShip.p.visibleName);
                        spaceManager.GetComponent <CommandManager>().SendUserCommand(SpaceObjects.ShipCommand.SetTarget, results[0].gameObject.GetComponent <IndicatorLink>().linkedObj);
                    }
                }
            }
        }
    }
コード例 #18
0
    public bool did_raycast_hit_blocking_mask()
    {
        //Code to be place in a MonoBehaviour with a GraphicRaycaster component
        //print("turn off raycast target");
        //GameManager.tutorial_manager.toggle_raycast(false);
        //Create the PointerEventData with null for the EventSystem
        PointerEventData ped = new PointerEventData(null);

        //Set required parameters, in this case, mouse position
        ped.position = Input.mousePosition;
        //Create list to receive all results
        List <RaycastResult> results = new List <RaycastResult>();

        //Raycast it
        for (int i = 0; i < gr_list.Length; i++)
        {
            GraphicRaycaster gr = gr_list[i];
            gr.Raycast(ped, results);
            if (results.Count > 0)
            {
                return(true);
            }
        }
        return(false); // no mask hit by raycasters
    }
コード例 #19
0
    // Update is called once per frame
    void Update()
    {
        //Set the Pointer Event Position to that of the mouse position
        pointerEventData          = new PointerEventData(eventSystem);
        pointerEventData.position = new Vector2(Camera.main.pixelWidth / 2, Camera.main.pixelHeight / 2);

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

        raycaster.Raycast(pointerEventData, results);
        foreach (RaycastResult result in results)
        {
            print("Result:" + result.gameObject.name);
            if (isButton(result.gameObject))
            {
                if (buttonObject == null)
                {
                    buttonObject = result.gameObject;
                    OnPointerEnter(buttonObject);
                }

                Vector3 newScale = Vector3.Lerp(gazer.transform.localScale, gazerMaxScale, Time.deltaTime / gazeTriggerTime);
                gazer.transform.localScale = newScale;
                return;
            }
        }

        if (buttonObject != null)
        {
            OnPointerExit(buttonObject);
            buttonObject = null;
            Vector3 newScale = Vector3.Lerp(gazerMinScale, gazer.transform.localScale, Time.deltaTime / gazeTriggerTime);
            gazer.transform.localScale = newScale;
        }
    }
コード例 #20
0
    void ChooseLocation()
    {
        if (Input.GetMouseButtonDown(0))
        {
            UIRay               = canvas.GetComponent <GraphicRaycaster>();
            UIRayEvent          = new PointerEventData(eventSys);
            UIRayEvent.position = Input.mousePosition;
            List <RaycastResult> UIElementsHit = new List <RaycastResult>();
            UIRay.Raycast(UIRayEvent, UIElementsHit);

            Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit camRayHit;

            if (Physics.Raycast(camRay, out camRayHit))
            {
                if (UIElementsHit.Count == 0)
                {
                    if (camRayHit.collider.CompareTag("MapNode"))
                    {
                        currentLocation = camRayHit.collider.gameObject;
                    }
                }
                else
                {
                    //foreach (RaycastResult result in UIElementsHit) {
                    //	Debug.Log("UIRay hit " + result.gameObject.name);
                    //}
                }
            }
        }
    }
コード例 #21
0
    GameObject CheckTouchingUI(MobileTouch newTouch)
    {
        // Reset selected GO
        newTouch.currentSelectedGO = null;
        // Set up the new Pointer Event
        m_PointerEventData          = new PointerEventData(m_EventSystem);
        m_PointerEventData.position = newTouch.lastTouchedPos;
        // Raycast using Graphics Raycaster for UI
        List <RaycastResult> results = new List <RaycastResult>();

        m_Raycaster.Raycast(m_PointerEventData, results);

        //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
        foreach (RaycastResult result in results)
        {
            Debug.Log("Hit " + result.gameObject.name);

            // Attach the collided GO
            newTouch.currentSelectedGO = result.gameObject;
            // To make sure only detect the first UI Hit
            break;
        }

        // return result
        return(newTouch.currentSelectedGO);
    }
コード例 #22
0
ファイル: NoteArea.cs プロジェクト: bmwalters/Play
    public void OnPointerClick(PointerEventData ped)
    {
        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform,
                                                                     ped.position,
                                                                     ped.pressEventCamera,
                                                                     out Vector2 localPoint))
        {
            return;
        }

        // Check that only the NoteArea was clicked, and not a note inside of it.
        List <RaycastResult> results = new List <RaycastResult>();

        graphicRaycaster.Raycast(ped, results);
        if (results.Count != 1 || results[0].gameObject != gameObject)
        {
            return;
        }

        float  rectWidth = rectTransform.rect.width;
        double xPercent  = (localPoint.x + (rectWidth / 2)) / rectWidth;
        double positionInSongInMillis = ViewportX + (ViewportWidth * xPercent);

        songAudioPlayer.PositionInSongInMillis = positionInSongInMillis;
    }
コード例 #23
0
    public void OnDrag()
    {
        PointerEventData data = new PointerEventData(EventSystem.current);

        data.position = Input.mousePosition;

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

        bool uiTouched = false;

        _raycaster.Raycast(data, results);
        foreach (RaycastResult r in results)
        {
            if (r.gameObject.name == "Lefttoucharea" ||
                r.gameObject.name == "Handle" ||
                r.gameObject.name == "Fixed Joystick")
            {
            }
            else
            {
                uiTouched = true;
                Debug.Log("UI 요소가 드래그 되었습니다: " + r.gameObject.name);
            }
        }


        if (uiTouched == false) // 다른 ui가 터치되지 않았을 때만 캐릭터 이동하게 하기
        {
            _joystick.OnDrag(data);
        }
    }
コード例 #24
0
    private void DetectingRaycasst()
    {
        m_PointerEventData          = new PointerEventData(m_EventSystem);
        m_PointerEventData.position = crosshair.transform.position;
        m_Raycaster.Raycast(m_PointerEventData, results);

        if (Input.GetButtonDown("A button") && resultButton != null && engaged)
        {
            resultButton.gameObject.GetComponent <Button>().OnPointerClick(m_PointerEventData);
        }
        //print(results[results.Count - 1].gameObject.name);

        try {
            if (results[results.Count - 1].gameObject.CompareTag("Button"))
            {
                resultButton = results[results.Count - 1].gameObject;
                resultButton.gameObject.GetComponent <Button>().Select();
            }
            else
            {
                resultButton = null;
            }
        }
        catch (Exception e)
        {
        }
    }
コード例 #25
0
 private bool isCursorInUI(Vector3 mouse)
 {
     raycastResults.Clear();
     pointerEventData.position = mouse;
     graphicRaycaster.Raycast(pointerEventData, raycastResults);
     return(raycastResults.Count > 0);
 }
コード例 #26
0
    private void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            // If we presseed the mouse button

            PointerEventData pointerEvent = new PointerEventData(eventSystem);
            pointerEvent.position = Input.mousePosition;

            List <RaycastResult> rayHits = new List <RaycastResult>();
            graphicRaycaster.Raycast(pointerEvent, rayHits);

            if (rayHits.Count > 0)
            {
                // If we hit a UI element
                return;
            }


            this.constructionPannel.turnOff();
            Tile selectedTile = this.tileClicked();

            if (this.gc.getBuilding(selectedTile) != null)
            {
                // If there is a building on the tile
                // Show the details
                this.detailsPanel.update(selectedTile);
            }
            else
            {
                // Else, show the construction pannel
                this.constructionPannel.turnOn(selectedTile);
            }
        }
    }
コード例 #27
0
 private bool Tracking()
 {
     pointData = new PointerEventData(eventSystem)
     {
         position = Input.mousePosition
     };
     if (result != null)
     {
         result.Clear();
     }
     raycaster.Raycast(pointData, result);
     if (result != null)
     {
         Tooltip temp = null;
         for (int i = 0; i < result.Count; i++)
         {
             temp = result[i].gameObject.GetComponent <Tooltip>();
             if (temp != null)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #28
0
    private bool HandleUIRaycast(out ControllerHitInfo hitInfo)
    {
        var pointerEventData = new PointerEventData(_eventSystem);

        pointerEventData.position = Input.mousePosition;

        var results = new List <RaycastResult>();

        _graphicRaycaster.Raycast(pointerEventData, results);

        RaycastResult result;
        IControllable controllable = null;

        for (var i = 0; i < results.Count; ++i)
        {
            if (results[i].gameObject.TryGetComponent <IControllable>(out controllable))
            {
                HitControllable(controllable, new ControllerHitInfo(controllable, results[i]));
                result  = results[i];
                hitInfo = new ControllerHitInfo(controllable, result);
                return(true);
            }
        }

        //don't reset press, maybe world objects are hit
        hitInfo = new ControllerHitInfo(true);
        return(false);
    }
コード例 #29
0
    void HandleMouseOperation()
    {
        PointerEventData ped = new PointerEventData(null)
        {
            position = Input.mousePosition
        };
        List <RaycastResult> results = new List <RaycastResult>();

        gr.Raycast(ped, results);

        if (results.Count > 0 && int.TryParse(results[0].gameObject.transform.parent.name, out int slot))
        {
            highlightIndex = slot;
        }
        else
        {
            highlightIndex = -1;
        }
        if (lastHighlightIndex != highlightIndex)
        {
            lastHighlightIndex = highlightIndex;
            RefreshUI();
        }

        if (Input.GetMouseButtonDown(0))
        {
            OnLeftMouseClick();
        }
        if (Input.GetMouseButtonDown(1))
        {
            OnRightMouseClick();
        }
    }
コード例 #30
0
    /// <summary>
    /// Determines whether pointer's current position is over any UI element.
    /// </summary>
    /// <param name="PointerInputPosition">Pointer's Input position.</param>
    public bool IsPointerOverUI(Vector2 PointerInputPosition)
    {
        Count = 0;

        pData = new PointerEventData(eSystem);

        pData.position = PointerInputPosition;

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

        gCaster.Raycast(pData, results);

        bool returnResult = (results.Count > 0) ? true : false;

        return(returnResult);
    }