コード例 #1
0
    private bool IsWithinSelectionBounds(GameObject go, SelectorEntity selector)
    {
        if (!selector.isSelecting)
        {
            return(false);
        }

        Camera camera         = Camera.main;
        Bounds viewportBounds = Utils.GetViewportBounds(camera, selector.mousePosition1, Input.mousePosition);

        //For simple selection
        bool objectSelected = false;
        Ray  ray            = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit2D[] hit2d = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity, LayerMask.GetMask("Ignore Raycast"));
        foreach (RaycastHit2D hit in hit2d)
        {
            if (hit.collider != null && hit.collider.transform == go.transform)
            {
                // raycast hit this gameobject
                objectSelected = true;
                break;
            }
        }

        return(viewportBounds.Contains(camera.WorldToViewportPoint(go.transform.position)) || objectSelected);
    }
コード例 #2
0
    public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
    {
        if (eventCamera == null)
        {
            return;
        }

        var ray = eventCamera.ScreenPointToRay(eventData.position);

        var dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

        var hits = Physics2D.GetRayIntersectionAll(ray, dist, finalEventMask);

        PreprocessHits(ref hits);

        if (hits != null && hits.Length != 0)
        {
            eventData.worldPosition = hits[0].point;
            eventData.worldNormal   = hits[0].normal;
            for (int b = 0, bmax = hits.Length; b < bmax; ++b)
            {
                var result = new RaycastResult {
                    gameObject = hits[b].collider.gameObject,
                    module     = this,
                    distance   = 0,
                    index      = resultAppendList.Count
                };
                resultAppendList.Add(result);
            }
        }
    }
コード例 #3
0
 // Update is called once per frame
 void Update()
 {
     sr      = GetComponent <SpriteRenderer>();
     _sprite = sr.sprite;
     if (Input.GetMouseButtonDown(0))
     {
         Ray            ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity);
         foreach (var hit in hits)
         {
             Vector2 pointHit    = hit.point;
             Vector3 spritePoint = sr.gameObject.transform.position;
             if (hit.collider.CompareTag("NPC") || hit.collider.CompareTag("Principal"))
             {
                 if (pointHit.x > spritePoint.x - 0.5 && pointHit.x < spritePoint.x + 0.5)
                 {
                     if (pointHit.y > spritePoint.y - 0.5 && pointHit.y < spritePoint.y + 0.5)
                     {
                         startConversation();
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
    // Vérifier si la souris se trouve par dessus une planète
    private bool MouseIsOverPlanet()
    {
        // Raycast au curseur
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit2D[] hitsInfo = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity, planetLayerMask);

        // Si un collider
        foreach (var hitInfo in hitsInfo)
        {
            if (hitInfo.collider != null)
            {
                // Si un collider de Planet (zone d'interaction) est trouvé (VRAI)
                Planet_InteractionZone planetZone = hitInfo.collider.GetComponent <Planet_InteractionZone>();
                if (planetZone != null)
                {
                    // Aller chercher le script planet
                    Planet planet = planetZone.GetComponentInParent <Planet>();
                    // Assigner les propriétés de texte
                    _planetText  = "Souls : " + planet.CurrentSouls + "/" + planet.TotalSouls;
                    _planetText += "\nCoords : " + planet.GridCoordinates;
                    _planetText += "\nTile : (" + planet.ParentTile.tileX + ", " + planet.ParentTile.tileY + ")";

                    return(true);
                }
            }
        }
        // Sinon, retourner FAUX
        return(false);
    }
コード例 #5
0
        public static List <SpriteRenderer> GetSpriteRenderersUnderScreenPoint(Vector2 point)
        {
            var ray          = Camera.main.ScreenPointToRay(point);
            var hits         = new List <RaycastHit2D>(Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity));
            var allRenderers = hits.ConvertAll(hit => hit.transform.gameObject.GetComponent <SpriteRenderer>());

            allRenderers.RemoveAll(r => r == null);

            var layers = new Dictionary <int, List <SpriteRenderer> >();

            allRenderers.ForEach(r =>
            {
                if (!layers.ContainsKey(r.sortingLayerID))
                {
                    layers[r.sortingLayerID] = new List <SpriteRenderer>();
                }
                layers[r.sortingLayerID].Add(r);
            });

            var sortedRenderers = new List <SpriteRenderer>();
            var sortedLayers    = new List <int>(layers.Keys);

            sortedLayers.Sort((a, b) => b - a);
            sortedLayers.ForEach(key => layers[key].Sort((a, b) => b.sortingOrder - a.sortingOrder));
            sortedLayers.ForEach(key => sortedRenderers.AddRange(layers[key]));

            return(sortedRenderers);
        }
コード例 #6
0
 // Update is called once per frame
 void Update()
 {
     if (!flicked)
     {
         if (Input.GetMouseButtonDown(0))
         {
             // Debug.Log("mousedown!");
             Ray            worldRay = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit2D[] hits     = Physics2D.GetRayIntersectionAll(worldRay);
             foreach (RaycastHit2D hit in hits)
             {
                 GameObject clickedObject = hit.transform.gameObject;
                 if (clickedObject == gameObject)
                 {
                     Velocity = new Vector3(Random.Range(5, 10), Random.Range(5, 10), Random.Range(2, 10));
                     rotation = Random.Range(-720, 720);
                     gameObject.GetComponent <ShopperController>().Move = false;
                     flicked = true;
                     StartCoroutine("Kill");
                 }
             }
         }
     }
     else
     {
         transform.Translate(Velocity * Time.deltaTime);
         transform.Rotate(transform.position + Vector3.forward, rotation * Time.deltaTime);
     }
 }
コード例 #7
0
    private void OnClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray            ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray);
            for (int i = 0; i < hits.Length; i++)
            {
                if (hits [i].collider.CompareTag("Soldier"))
                {
                    _squad_selected_clicked_behavior = hits [i].collider.GetComponent <OnClickBehavior>();
                    _squad_selected_clicked_behavior.OnSelect();
                    _squad_selected = _squad_selected_clicked_behavior.GetComponent <Squad> ();
                    if (onSquadSelected != null)
                    {
                        onSquadSelected();
                    }
                }

                /*else
                 * {
                 *      if (squad_selected != null)
                 *      {
                 *              _squad_selected_clicked_behavior.OnDeselect ();
                 *              _squad_selected = null;
                 *      }
                 *
                 * }*/
            }
        }
    }
コード例 #8
0
ファイル: Physics2DRaycaster.cs プロジェクト: shicheju1/ugui
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            if (eventCamera == null)
            {
                return;
            }

            var ray = eventCamera.ScreenPointToRay(eventData.position);

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics2D.GetRayIntersectionAll(ray, dist, finalEventMask);

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var sr = hits[b].collider.gameObject.GetComponent <SpriteRenderer>();

                    var result = new RaycastResult
                    {
                        gameObject     = hits[b].collider.gameObject,
                        module         = this,
                        distance       = Vector3.Distance(eventCamera.transform.position, hits[b].transform.position),
                        worldPosition  = hits[b].point,
                        worldNormal    = hits[b].normal,
                        screenPosition = eventData.position,
                        index          = resultAppendList.Count,
                        sortingLayer   = sr != null ? sr.sortingLayerID : 0,
                        sortingOrder   = sr != null ? sr.sortingOrder : 0
                    };
                    resultAppendList.Add(result);
                }
            }
        }
コード例 #9
0
        public void OnEndDrag(PointerEventData eventData)
        {
            var invrect = Inventory.GetComponent <RectTransform>();

            if (!InCraft)
            {
                List <RaycastHit2D> hit = Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(Input.mousePosition)).ToList();
                if (hit.Any(h => h.collider == Crafter.GetComponentInParent <Collider2D>()))
                {
                    if (Crafter.AddItem(Item))
                    {
                        OnDrop?.Invoke();
                    }
                    else
                    {
                        // display msg
                    }
                }
            }
            else if (InCraft && RectTransformUtility.RectangleContainsScreenPoint(invrect, Input.mousePosition))
            {
                if (Inventory.AddItem(Item))
                {
                    OnDrop?.Invoke();
                }
                else
                {
                    // display msg
                }
            }
            _image.transform.localPosition = Vector3.zero;
        }
コード例 #10
0
ファイル: LevelSelector.cs プロジェクト: csaye/computeroid
    bool overFolder(float currentFolder)
    {
        // If left mouse button pressed
        if (Input.GetMouseButtonDown(0))
        {
            // For each hit overlapped with the mouse position
            foreach (RaycastHit2D rayHit in (Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(InputEx.mousePosition))))
            {
                // If found collider, check for folder
                if (rayHit.collider != null)
                {
                    // If hit collider belongs to a folder
                    if (rayHit.collider.gameObject.GetComponent <FolderSelect>() != null)
                    {
                        // If folder number is same as one overlapped by level selector, return true
                        if (rayHit.collider.gameObject.GetComponent <FolderSelect>().folderNumber == currentFolder)
                        {
                            return(true);
                        }
                    }
                }
            }
        }

        // If mouse position and folder do not meet requirements, return false
        return(false);
    }
コード例 #11
0
        private float CalcHitDistance(Ray ray)
        {
            float hitDistance = float.MaxValue;

            if (blockingObjects != BlockingObjects.None)
            {
                float dist = eventCamera.farClipPlane;

                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics.RaycastAll(ray, dist, m_BlockingMask);
                    if (hits.Length > 0 && hits[0].distance < hitDistance)
                    {
                        hitDistance = hits[0].distance;
                    }
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics2D.GetRayIntersectionAll(ray, dist, m_BlockingMask);
                    if (hits.Length > 0 && hits[0].fraction * dist < hitDistance)
                    {
                        hitDistance = hits[0].fraction * dist;
                    }
                }
            }

            return(hitDistance);
        }
コード例 #12
0
ファイル: LevelComplete.cs プロジェクト: waffle5/DarkDreams
 void Update()
 {
     //Checks to see if the cutscene has been activated yet to prevent multiple instances of the cutscene
     if (cutsceneActivated == false)
     {
         if (playerContact == true && ((Input.GetKeyDown(KeyCode.Space))))
         {
             Debug.Log("Level completed");
             EndingCutscene();
         }
         else if (playerContact == true && Input.GetMouseButtonDown(0))
         {
             RaycastHit2D[] hits;
             hits = Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(Input.mousePosition), 100);
             for (int i = 0; i < hits.Length; i++)
             {
                 RaycastHit2D hit = hits[i];
                 if (hit.collider.tag == "Bed")
                 {
                     Debug.Log("Level completed");
                     EndingCutscene();
                 }
             }
         }
     }
 }
コード例 #13
0
    // Checks if the mouse is over the tile, and if so, highlights the tile
    void CheckHighlight()
    {
        // Reset parameter
        isTile = false;

        // For each hit overlapped with the mouse position
        foreach (RaycastHit2D rayHit in (Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(InputEx.mousePosition))))
        {
            // If found collider, check for tile
            if (rayHit.collider != null)
            {
                // If at least one of the colliders has the position of the tile
                if (transform.position == rayHit.collider.gameObject.transform.position)
                {
                    // Because tile found, highlight tile
                    isTile = true;
                }
            }
        }

        // If a tile is found, highlight the tile
        if (isTile)
        {
            spriteRenderer.sprite = tileHighlight;

            // If a tile is not found, set it back to normal
        }
        else
        {
            spriteRenderer.sprite = tileNormal;
        }
    }
コード例 #14
0
    public static GameObject[] IntersectObjects(Vector3 position)
    {
        Ray ray  = Camera.main.ScreenPointToRay(position);
        var hits = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity);

        return(hits.Select(h => h.collider.gameObject).ToArray());
    }
コード例 #15
0
    void CheckDraggingUnitEnd()
    {
        if (!draggingUnit)
        {
            return;
        }

        if (Input.GetMouseButtonUp(0))
        {
            // 마우스 밑에 레이저 검사
            int          layerMask = 1 << LayerMask.NameToLayer("SpawnArea");
            Ray          ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit       = Physics2D.GetRayIntersection(ray, Mathf.Infinity, layerMask);

            // 스폰 가능한 위치에 드랍했는가?
            if (hit.collider != null)
            {
                // 밑에 다른 유닛이 존재하는지 검사
                ray.origin = new Vector3(Mathf.Floor(hit.point.x) + 0.5f, Mathf.Floor(hit.point.y) + 0.5f, ray.origin.z);
                layerMask  = 1 << LayerMask.NameToLayer("BattleUnitPlanPhase");
                RaycastHit2D[] hits      = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity, layerMask);
                GameObject     underUnit = null;
                foreach (RaycastHit2D _hit in hits)
                {
                    if (_hit.collider.gameObject == draggingUnit.gameObject)
                    {
                        continue;
                    }
                    underUnit = _hit.collider.gameObject;
                }

                // 밑에 아무것도 없을 경우 그냥 옮기기
                if (underUnit == null)
                {
                    Vector2 point = new Vector2(Mathf.Floor(hit.point.x) + 0.5f, Mathf.Floor(hit.point.y) + 0.5f);
                    draggingUnit.transform.position = point;
                }
                // 밑에 유닛이 존재할 경우 위치 바꾸기
                else
                {
                    Vector3 tempPosition = underUnit.transform.position;
                    underUnit.transform.position    = dragStartPosition;
                    draggingUnit.transform.position = tempPosition;
                }
            }
            // 스폰 불가능한 위치에 드랍했는가?
            else
            {
                draggingUnit.transform.position = dragStartPosition;
                Debug.LogWarning("해당 위치로 유닛을 옮길 수 없습니다.");
            }

            // 유닛 드래깅 정보 초기화
            draggingUnit      = null;
            dragStartPosition = new Vector3();
        }
    }
コード例 #16
0
    private void DoRaycast()
    {
        RaycastHit2D[] hits;
        Ray            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        hits = Physics2D.GetRayIntersectionAll(ray, 100.0f);
        Debug.Log(hits.Length);
        if (hits.Length > 0)
        {
            for (int i = 0; i < hits.Length; i++)
            {
                Collider2D collider = hits[i].collider;
                // First check that the collider has not been selected/painted yet

                ColorableSectionInstance colorableSection = collider.GetComponentInParent <ColorableSectionInstance>();
                if (colorableSection == null)
                {
                    Debug.Log("No colorable section.");
                    continue;
                }

                if (!colorableSection.Colored)
                {
                    SpriteRenderer spriteRenderer = collider.GetComponent <SpriteRenderer>();
                    if (spriteRenderer == null)
                    {
                        Debug.Log("No sprite renderer.");
                        continue;
                    }


                    Texture2D currentTexture = spriteRenderer.sprite.texture;

                    // Get current color
                    Vector2 uv;
                    uv.x = (hits[i].point.x - hits[i].collider.bounds.min.x) / hits[i].collider.bounds.size.x;
                    uv.y = (hits[i].point.y - hits[i].collider.bounds.min.y) / hits[i].collider.bounds.size.y;

                    uv.x *= currentTexture.width;
                    uv.y *= currentTexture.height;

                    Color currentColor = currentTexture.GetPixel((int)(uv.x), (int)(uv.y));

                    if (currentColor.r == 0 && currentColor.g == 0 && currentColor.b == 0)
                    {
                        OnSectionSelect(colorableSection);
                    }

                    //Debug.Log(uv);
                    //Debug.Log(currentColor);
                }
            }
        }
    }
コード例 #17
0
ファイル: CameraLayer2D.cs プロジェクト: vousk/TouchScript
        protected override LayerHitResult castRay(Ray ray, out TouchHit hit)
        {
            hit = new TouchHit();
            var hits = Physics2D.GetRayIntersectionAll(ray, float.PositiveInfinity, LayerMask);

            if (hits.Length == 0)
            {
                return(LayerHitResult.Miss);
            }
            if (hits.Length > 1)
            {
                hits = sortHits(hits);
            }

            var success = false;

            foreach (var raycastHit in hits)
            {
                hit = TouchHit.FromRaycastHit2D(raycastHit);
                var hitTests = raycastHit.transform.GetComponents <HitTest>();
                if (hitTests.Length == 0)
                {
                    success = true;
                    break;
                }

                var hitResult = HitTest.ObjectHitResult.Error;
                foreach (var test in hitTests)
                {
                    hitResult = test.IsHit(hit);
                    if (hitResult == HitTest.ObjectHitResult.Hit || hitResult == HitTest.ObjectHitResult.Discard)
                    {
                        break;
                    }
                }

                if (hitResult == HitTest.ObjectHitResult.Hit)
                {
                    success = true;
                    break;
                }
                if (hitResult == HitTest.ObjectHitResult.Discard)
                {
                    break;
                }
            }

            if (success)
            {
                return(LayerHitResult.Hit);
            }

            return(LayerHitResult.Miss);
        }
コード例 #18
0
ファイル: OptionsThumb.cs プロジェクト: csaye/computeroid
    // Checks if the mouse is clicked over the slider and held down and moves thumb accordingly
    void CheckActivate()
    {
        // Reset parameters
        isThumb  = false;
        isSlider = false;

        // For each hit overlapped with the mouse position
        foreach (RaycastHit2D rayHit in (Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(InputEx.mousePosition))))
        {
            // If found collider, check for thumb
            if (rayHit.collider != null)
            {
                // If at least one of the colliders is the thumb
                if (gameObject == rayHit.collider.gameObject)
                {
                    // Because thumb found, use thumb
                    isThumb = true;
                }

                // If at least one of the colliders is the parent of the thumb (the slider)
                if (gameObject.transform.parent.gameObject == rayHit.collider.gameObject)
                {
                    // Because slider found, use slider if thumb not found
                    isSlider = true;
                }
            }
        }

        // If thumb is found, activate thumb
        if (isThumb)
        {
            float thumbX = transform.position.x;
            float mouseX = Camera.main.ScreenToWorldPoint(new Vector3(InputEx.mousePosition.x, InputEx.mousePosition.y, 7.8f)).x;

            // Offset slider based on original mouse click
            xOffset   = thumbX - mouseX;
            activated = true;

            // If slider found, move to mouse position and activate thumb
        }
        else if (isSlider)
        {
            xOffset   = 0;
            activated = true;

            // If neither slider or thumb found, deactivate
        }
        else
        {
            activated = false;
        }
    }
コード例 #19
0
ファイル: MouseHandler.cs プロジェクト: JustCallMeRob/LD45
 public static void PlaceBlock(BlockItem block)
 {
     if (Input.GetMouseButtonUp(0))
     {
         Ray            ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity);
         foreach (var hit in hits)
         {
             Player player = FindObjectOfType <Player>();
             player.AttachBlock(block, hit);
         }
     }
 }
コード例 #20
0
 private ManeuverNode SelectManeuverNode(Vector2 mousePosition)
 {
     //nodeLayerMask
     RaycastHit2D[] rayHits = Physics2D.GetRayIntersectionAll(mainCamera.ScreenPointToRay(Input.mousePosition), 100f, nodeLayerMask);
     for (int i = 0; i < rayHits.Length; i++)
     {
         RaycastHit2D hit = rayHits[i];
         ManeuverNode maneuverNode = hit.collider.GetComponent<ManeuverNode>();
         if (maneuverNode != null)
             return maneuverNode;
     }
     return CreateManeuverNode(mousePosition);
 }
コード例 #21
0
 void SelectManeuverNodeVector()
 {
     RaycastHit2D[] rayHits = Physics2D.GetRayIntersectionAll(mainCamera.ScreenPointToRay(Input.mousePosition), 100f, vectorLayerMask);
     for (int i = 0; i < rayHits.Length; i++)
     {
         RaycastHit2D hit = rayHits[i];
         selectedManeuverVector = hit.collider.GetComponent<ManeuverVectorHandler>();
         if (selectedManeuverVector == null)
             continue;
         
         selectedManeuverVector.InitializeVectorSelect(mainCamera.ScreenToWorldPoint(Input.mousePosition));
     }
 }
コード例 #22
0
    void TestMouseControl()
    {
        if (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2))
        {
            Vector2 mousePos = Input.mousePosition;
            Ray     ray      = Camera.main.ScreenPointToRay(mousePos);

            RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray, 20.0f);

            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider)
                {
                    if (hit.collider.tag == "Water")
                    {
                        TWaterTile waterComponent = hit.collider.gameObject.GetComponent <TWaterTile>();

                        if (waterComponent)
                        {
                            // Left mouse button
                            if (Input.GetMouseButton(0))
                            {
                                AddWaterToWaterTile(waterComponent.posX, waterComponent.posY);
                            }

                            // Right mouse button
                            if (Input.GetMouseButton(1))
                            {
                                SetCollisionAtTile(waterComponent.posX, waterComponent.posY, true);
                            }

                            // Middle mouse button
                            if (Input.GetMouseButton(2))
                            {
                                SetCollisionAtTile(waterComponent.posX, waterComponent.posY, false);
                            }
                        }
                        else
                        {
                            Debug.LogError("Error - WaterTile has no attached TWaterTile component!");
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            UpdateCollisionMap();
        }
    }
コード例 #23
0
    public static bool IntersectObject(Vector3 position, GameObject gameObject)
    {
        Ray ray = Camera.main.ScreenPointToRay(position);

        RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray, Mathf.Infinity);
        foreach (var hit in hits)
        {
            if (hit.collider.gameObject == gameObject)
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #24
0
ファイル: CameraController.cs プロジェクト: rtoole13/Orbital
 private void SelectFocusTarget()
 {
     RaycastHit2D[] rayHits = Physics2D.GetRayIntersectionAll(mainCamera.ScreenPointToRay(Input.mousePosition));
     for (int i = 0; i < rayHits.Length; i++)
     {
         RaycastHit2D     hit             = rayHits[i];
         ICameraTrackable cameraTrackable = hit.collider.GetComponent <ICameraTrackable>();
         if (hit.collider.isTrigger || cameraTrackable == null)
         {
             continue;
         }
         currentTarget = hit.collider.gameObject;
     }
 }
コード例 #25
0
    private void Update()
    {
        //if (Mathf.Approximately(Time.timeScale, 0f))
        //    return;
        IMessageBox mb = null;

        var hits2D = Physics2D.GetRayIntersectionAll(GameScene.Instance.UIManager.UiCamera.ScreenPointToRay(InputCtrl.MousePosition), float.MaxValue, UIManager.UI_LAYER_MASK);

        for (var i = 0; i < hits2D.Length; i++)
        {
            if (hits2D[i].transform != null)
            {
                mb = hits2D[i].transform.GetComponent <IMessageBox>();
                if (mb != null)
                {
                    break;
                }
            }
        }
        if (mb == null)
        {
            var hits = Physics.RaycastAll(InputCtrl.MainMouseRay, float.MaxValue, LayerMask.GetMask("Building"));
            for (var i = 0; i < hits.Length; i++)
            {
                if (hits[i].transform != null)
                {
                    mb = hits[i].transform.root.GetComponent <IMessageBox>();
                    break;
                }
            }
        }

        if (mb != null)
        {
            if (this.messageBox != mb)
            {
                ResetCurrentTextBox();
                this.messageBox = mb;
                currentTextBox  = UIManager.TextBoxPoolObject.Take();
                StartCoroutine(currentTextBox.AfterTakedInitialize(mb.GetMessageText));
            }
        }
        else
        {
            this.messageBox = null;
            ResetCurrentTextBox();
        }
    }
コード例 #26
0
    void UpdateCollisionMap()
    {
        Debug.Log("TFollowerWater - UpdateCollisionMap()");

        foreach (GameObject waterTileObject in waterGameObjects)
        {
            Vector3 centerOfTileObject = waterTileObject.collider2D.renderer.bounds.center;
            centerOfTileObject.z -= 10.0f;

            TWaterTile waterComponent = waterTileObject.GetComponent <TWaterTile>();

            Ray ray = new Ray(centerOfTileObject, Vector3.forward);

            RaycastHit2D[] hits = Physics2D.GetRayIntersectionAll(ray, 20.0f);

            // Debug.Log ("Center: " + centerOfTileObject + " hit: " + (hits.Length > 0 ? "YES" : "NO"));

            bool hitCollision = false;
            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider)
                {
                    // all Tags defined as collisions for water
                    if (hit.collider.tag == "Wall")
                    {
                        hitCollision = true;
                        break;
                    }
                }
            }

            int posArrayX = waterComponent.posX + 1;
            int posArrayY = waterComponent.posY + 1;

            if (hitCollision)
            {
                waterField[posArrayX, posArrayY] = COLLISION;
                mass[posArrayX, posArrayY]       = 0.0f;
            }
            else
            {
                if (waterField[posArrayX, posArrayY] == COLLISION)
                {
                    waterField[posArrayX, posArrayY] = EMPTY;
                }
            }
        }
    }
コード例 #27
0
        /// <inheritdoc />
        protected override LayerHitResult castRay(Ray ray, out TouchHit hit)
        {
            hit = default(TouchHit);
            var raycastHits = Physics2D.GetRayIntersectionAll(ray, float.PositiveInfinity, LayerMask);

            Debug.DrawRay(ray.origin, ray.direction, Color.green);

            if (raycastHits.Length == 0)
            {
                return(LayerHitResult.Miss);
            }
            if (raycastHits.Length > 1)
            {
                sortHits(raycastHits);

                RaycastHit2D raycastHit = default(RaycastHit2D);
                var          i          = 0;
                while (i < sortedHits.Count)
                {
                    raycastHit = sortedHits[i];
                    switch (doHit(raycastHit, out hit))
                    {
                    case HitTest.ObjectHitResult.Hit:
                        return(LayerHitResult.Hit);

                    case HitTest.ObjectHitResult.Discard:
                        return(LayerHitResult.Miss);
                    }
                    i++;
                }
            }
            else
            {
                switch (doHit(raycastHits[0], out hit))
                {
                case HitTest.ObjectHitResult.Hit:
                    return(LayerHitResult.Hit);

                case HitTest.ObjectHitResult.Error:
                    return(LayerHitResult.Error);

                default:
                    return(LayerHitResult.Miss);
                }
            }

            return(LayerHitResult.Miss);
        }
コード例 #28
0
        public bool RaycastAllObjects(Ray ray, SceneRaycastPrecision rtRaycastPrecision, List <GameObjectRayHit> hits)
        {
            if (Settings.PhysicsMode == ScenePhysicsMode.UnityColliders)
            {
                hits.Clear();
                RaycastHit[]   hits3D = Physics.RaycastAll(ray, float.MaxValue);
                RaycastHit2D[] hits2D = Physics2D.GetRayIntersectionAll(ray, float.MaxValue);
                GameObjectRayHit.Store(ray, hits2D, hits3D, hits);

                return(hits.Count != 0);
            }
            else
            {
                return(_sceneTree.RaycastAll(ray, rtRaycastPrecision, hits));
            }
        }
コード例 #29
0
ファイル: CardTouchVC.cs プロジェクト: Avatarchik/EPoker
        public CardViewModel GetCard(Gesture gesture)
        {
            Ray ray = Camera.main.ScreenPointToRay((Vector3)gesture.position);

            RaycastHit2D[] hit2D = Physics2D.GetRayIntersectionAll(ray);

            if (hit2D.Length > 0)
            {
                CardTouchVC cardTouchVC = hit2D [0].collider.GetComponent <CardTouchVC> ();
                if (cardTouchVC != null)
                {
                    return(cardTouchVC.Card);
                }
            }
            return(null);
        }
コード例 #30
0
ファイル: EscButton.cs プロジェクト: csaye/computeroid
    // Checks if the mouse is over the button, and if so, highlights the button
    void CheckHighlight()
    {
        // Reset parameter
        isButton = false;

        // For each hit overlapped with the mouse position
        foreach (RaycastHit2D rayHit in (Physics2D.GetRayIntersectionAll(Camera.main.ScreenPointToRay(InputEx.mousePosition))))
        {
            // If found collider, check for button
            if (rayHit.collider != null)
            {
                // If at least one of the colliders has the position of the button
                if (transform.position == rayHit.collider.gameObject.transform.position)
                {
                    // Because button found, highlight button
                    isButton = true;
                }
            }
        }

        // If a button is found, highlight the button
        if (isButton)
        {
            // Set cursor to hovering because over button
            CursorManager.hovering = true;

            // Set sprite to highlighted button
            spriteRenderer.sprite = escButtonHighlight;

            // If highlighted and mouse button down, activate button function
            if (Input.GetMouseButtonDown(0))
            {
                // Play button press sound
                SoundManager.currentSound = "buttonPress";
                SoundManager.updateSound  = true;

                ActivateButton();
            }

            // If a button is not found, set it back to normal
        }
        else
        {
            spriteRenderer.sprite = escButtonNormal;
        }
    }