public void GetSelectablesUnderCursor(List <KSelectable> hits) { if ((UnityEngine.Object)hoverOverride != (UnityEngine.Object)null) { hits.Add(hoverOverride); } Camera main = Camera.main; Vector3 mousePos = KInputManager.GetMousePos(); float x2 = mousePos.x; Vector3 mousePos2 = KInputManager.GetMousePos(); float y2 = mousePos2.y; Vector3 position = main.transform.GetPosition(); Vector3 position2 = new Vector3(x2, y2, 0f - position.z); Vector3 pos = main.ScreenToWorldPoint(position2); Vector2 pos2 = new Vector2(pos.x, pos.y); int cell = Grid.PosToCell(pos); if (Grid.IsValidCell(cell) && Grid.IsVisible(cell)) { Game.Instance.statusItemRenderer.GetIntersections(pos2, hits); ListPool <ScenePartitionerEntry, SelectTool> .PooledList pooledList = ListPool <ScenePartitionerEntry, SelectTool> .Allocate(); GameScenePartitioner.Instance.GatherEntries((int)pos2.x, (int)pos2.y, 1, 1, GameScenePartitioner.Instance.collisionLayer, pooledList); pooledList.Sort((ScenePartitionerEntry x, ScenePartitionerEntry y) => SortHoverCards(x, y)); foreach (ScenePartitionerEntry item in pooledList) { KCollider2D kCollider2D = item.obj as KCollider2D; if (!((UnityEngine.Object)kCollider2D == (UnityEngine.Object)null) && kCollider2D.Intersects(new Vector2(pos2.x, pos2.y))) { KSelectable kSelectable = kCollider2D.GetComponent <KSelectable>(); if ((UnityEngine.Object)kSelectable == (UnityEngine.Object)null) { kSelectable = kCollider2D.GetComponentInParent <KSelectable>(); } if (!((UnityEngine.Object)kSelectable == (UnityEngine.Object)null) && kSelectable.isActiveAndEnabled && !hits.Contains(kSelectable) && kSelectable.IsSelectable) { hits.Add(kSelectable); } } } pooledList.Recycle(); } }
private void GetObjectUnderCursor2D <T>(List <Intersection> intersections, Func <T, bool> condition, int layer_mask) where T : MonoBehaviour { Camera main = Camera.main; Vector3 mousePos = KInputManager.GetMousePos(); float x = mousePos.x; Vector3 mousePos2 = KInputManager.GetMousePos(); float y = mousePos2.y; Vector3 position = main.transform.GetPosition(); Vector3 position2 = new Vector3(x, y, 0f - position.z); Vector3 pos = main.ScreenToWorldPoint(position2); Vector2 pos2 = new Vector2(pos.x, pos.y); if ((UnityEngine.Object)hoverOverride != (UnityEngine.Object)null) { intersections.Add(new Intersection { component = hoverOverride, distance = -100f }); } int cell = Grid.PosToCell(pos); if (Grid.IsValidCell(cell) && Grid.IsVisible(cell)) { Game.Instance.statusItemRenderer.GetIntersections(pos2, intersections); ListPool <ScenePartitionerEntry, SelectTool> .PooledList pooledList = ListPool <ScenePartitionerEntry, SelectTool> .Allocate(); int x2 = 0; int y2 = 0; Grid.CellToXY(cell, out x2, out y2); GameScenePartitioner.Instance.GatherEntries(x2, y2, 1, 1, GameScenePartitioner.Instance.collisionLayer, pooledList); foreach (ScenePartitionerEntry item in (List <ScenePartitionerEntry>)pooledList) { KCollider2D kCollider2D = item.obj as KCollider2D; if (!((UnityEngine.Object)kCollider2D == (UnityEngine.Object)null) && kCollider2D.Intersects(new Vector2(pos.x, pos.y))) { T val = kCollider2D.GetComponent <T>(); if ((UnityEngine.Object)val == (UnityEngine.Object)null) { val = kCollider2D.GetComponentInParent <T>(); } if (!((UnityEngine.Object)val == (UnityEngine.Object)null) && ((1 << val.gameObject.layer) & layer_mask) != 0 && !((UnityEngine.Object)val == (UnityEngine.Object)null) && (condition == null || condition(val))) { Vector3 position3 = val.transform.GetPosition(); float num = position3.z - pos.z; bool flag = false; for (int i = 0; i < intersections.Count; i++) { Intersection value = intersections[i]; if ((UnityEngine.Object)value.component.gameObject == (UnityEngine.Object)val.gameObject) { value.distance = Mathf.Min(value.distance, num); intersections[i] = value; flag = true; break; } } if (!flag) { intersections.Add(new Intersection { component = val, distance = num }); } } } } pooledList.Recycle(); } }