Esempio n. 1
0
    private void SelectObjectsInRange(Vector2 startPos, Vector2 endPos)
    {
        Camera     camera = GetComponentInChildren <Camera>();
        Ray        ray    = camera.ScreenPointToRay(startPos);
        RaycastHit hit;

        Physics.Raycast(ray, out hit, 100, 1 << LayerMask.NameToLayer("Terrain"));

        EventListener.Deselected();
        if (hit.collider == null)
        {
            SelectSingleObject(startPos);
            return;
        }
        else
        {
            Vector3 worldPosStart = hit.point;
            ray = camera.ScreenPointToRay(endPos);
            Physics.Raycast(ray, out hit, 100, 1 << LayerMask.NameToLayer("Terrain"));
            if (hit.collider == null)
            {
                SelectSingleObject(endPos);
                return;
            }
            SelectAllInRange(worldPosStart, hit.point);
        }
    }
Esempio n. 2
0
    private void SelectSingleObject(Vector2 position)
    {
        Camera     camera = GetComponentInChildren <Camera>();
        Ray        ray    = camera.ScreenPointToRay(position);
        RaycastHit hit;

        Physics.Raycast(ray, out hit, 100, 1 << LayerMask.NameToLayer("SelectionBox"));

        if (hit.collider == null)
        {
            EventListener.Deselected();
        }
        else
        {
            SelectObject(0, hit.collider.transform);
            if (SelectedObj[0] != null)
            {
                EventListener.ObjectSelected(SelectedObj[0]);
            }
        }
    }