private void OnGUI()
 {
     if (dragging)
     {
         Rect rect = RTSCore.GetScreenRect(mouseStartPosition, mouseCurrentPosition);
         RTSCore.DrawScreenRectBorderShaded(rect, BorderThickness, SelectionColor);
     }
 }
    private void Select(bool multiSelect)
    {
        // TODO - Add GUI check to nto select units if GUI selected

        RaycastHit rayHit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, SelectableUnit))
        {
            SelectionController selectedObject = rayHit.collider.GetComponent <SelectionController>();
            if (selectedObject == null)
            {
                Debug.Log(RTSCore.BuildString("Could not find Selection Controller on clicked object. Object Name:", rayHit.collider.name));
            }

            if (multiSelect)
            {
                if (selectedObject.CompareTag("Unit"))
                {
                    selectedObject.ToggleSelection();
                }
            }
            else
            {
                SelectObjects(selectedObject);
            }
        }
        else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, SelectableBuilding))
        {
            Debug.Log("We Clicked a building!");

            SelectionController selectedObject = rayHit.collider.GetComponent <SelectionController>();

            if (selectedObject == null)
            {
                Debug.Log(RTSCore.BuildString("Could not find Selection Controller on clicked object. Object Name:", rayHit.collider.name));
            }

            if (multiSelect)
            {
                Debug.Log("We clicked with Ctrl");
                if (selectedObjects.Count == 0)
                {
                    Debug.Log("Nothing else selected, selecting Building");;
                    SelectObjects(selectedObject);
                }
            }
            else
            {
                Debug.Log("Selecting Building");
                SelectObjects(selectedObject);
            }
        }
        //else
        //{
        //    Debug.Log("We did not hit anything!");
        //}
    }
    private bool IsWithinSelectionBounds(SelectionController selectionController)
    {
        //if (!dragging)
        //    return false;

        var camera         = Camera.main;
        var viewportBounds = RTSCore.GetViewportBounds(camera, mouseStartPosition, mouseCurrentPosition);

        return(viewportBounds.Contains(camera.WorldToViewportPoint(selectionController.transform.position)));
    }
예제 #4
0
    private void UpdateDebugOverlay()
    {
        string debugText = "";

        foreach (Metric metric in metrics)
        {
            debugText += RTSCore.MultiDebugLine(metric.Name, metric.Data);
        }

        DebugText.text = debugText;
    }