<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Get Bounds to MultiSelect Markers]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2008&amp;type=atom" />
	<updated>2022-08-01T09:46:29Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2008</id>
		<entry>
			<title type="html"><![CDATA[Re: Get Bounds to MultiSelect Markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8476#p8476" />
			<content type="html"><![CDATA[<p>Hello.</p><p>In addition to checking that GameObject is within bounds, you also need to check that it is enabled.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-08-01T09:46:29Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8476#p8476</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Get Bounds to MultiSelect Markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8475#p8475" />
			<content type="html"><![CDATA[<p>Hi, I&#039;m trying to make a drag selection tool for my markers using this code</p><div class="codebox"><pre><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&lt;Stat&gt;()
                                .marker3D.instance.transform))
                                SelectUnit(unitHit.GetComponent&lt;Stat&gt;().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&lt;Stat&gt;() != null)
                        {
                            var pF = units.gameObject.GetComponent&lt;Stat&gt;();

                            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;  
        }</code></pre></div><p>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.</p><p>Is there any tools in OnlineMaps that can also use the same method that I did??</p>]]></content>
			<author>
				<name><![CDATA[moonflow123]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1980</uri>
			</author>
			<updated>2022-08-01T07:00:00Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8475#p8475</id>
		</entry>
</feed>
