Topic: Get Bounds to MultiSelect Markers
Hi, I'm trying to make a drag selection tool for my markers using this code
if (canMultiSelect)
{
if (Input.GetMouseButtonDown(0))
{
mousePos = Input.mousePosition;
double lng, lat;
Ray ray = Camera.main.ScreenPointToRay(mousePos);
if (Physics.Raycast(ray, out hit))
{
LayerMask layerMask = hit.transform.gameObject.layer;
Transform unitHit = hit.transform;
switch (layerMask.value)
{
case 7:
if (!selectedUnits.Contains(hit.transform.GetComponent<Stat>()
.marker3D.instance.transform))
SelectUnit(unitHit.GetComponent<Stat>().marker3D.instance.transform);
break;
default:
isDragging = true;
break;
}
}
}
if (Input.GetMouseButtonUp(0))
{
foreach (OnlineMapsMarker3D child in OnlineMapsMarker3DManager.instance)
{
var units = child.instance.transform;
if (units.gameObject.GetComponent<Stat>() != null)
{
var pF = units.gameObject.GetComponent<Stat>();
if (IsWithinSelectionBounds(units))
{
if (!selectedUnits.Contains(pF.marker3D.instance.transform))
SelectUnit(pF.marker3D.instance.transform);
}
}
}
isDragging = false;
}
}
}
private bool IsWithinSelectionBounds(Transform tf)
{
if (!isDragging)
{
return false;
}
Camera cam = Camera.main;
Bounds vpBounds = DragGUI.GetVPBounds(cam, mousePos, Input.mousePosition);
return vpBounds.Contains(cam.WorldToViewportPoint(tf.position));
}
public static Bounds GetVPBounds(Camera cam, Vector3 screenPos1, Vector3 screenPos2)
{
Vector3 pos1 = cam.ScreenToViewportPoint(screenPos1);
Vector3 pos2 = cam.ScreenToViewportPoint(screenPos2);
Vector3 min = Vector3.Min(pos1, pos2);
Vector3 max = Vector3.Max(pos1, pos2);
min.z = cam.nearClipPlane;
max.z = cam.farClipPlane;
Bounds bounds = new Bounds();
bounds.SetMinMax(min, max);
return bounds;
}
The code is actually fine and working but I just found out that if I tried to zoom in on the marker and then tried to drag select, the markers besides the ones in the boundaries also got called.
Is there any tools in OnlineMaps that can also use the same method that I did??