void cleanPool() { while (indicatorPool.Count > indicatorCursor) { ElementIndicator obj = indicatorPool [indicatorPool.Count - 1]; indicatorPool.RemoveAt(indicatorPool.Count - 1); Destroy(obj.gameObject); } }
private void setIndicatorForObj(Vector3 screenPos, Color color) { if (screenPos.x > 0 && screenPos.x < Screen.width && screenPos.y > 0 && screenPos.y < Screen.height) { // NO indicator } else // OFFSCREEN { Vector3 screenCenter = new Vector3(Screen.width, Screen.height, 0) / 2; // Coordinate translated to screen center screenPos -= screenCenter; float angle = Mathf.Atan2(screenPos.y, screenPos.x); angle -= 90 * Mathf.Deg2Rad; Vector3 screenBound = screenCenter * 0.9f; if (screenPos.x == 0) { if (screenPos.y > 0) { screenPos = new Vector3(0, screenBound.y, 0); } else { screenPos = new Vector3(0, -screenBound.y, 0); } } else { float k = screenPos.y / screenPos.x; float screenK = (float)Screen.height / Screen.width; if (k > 0) { if (screenPos.x > 0) { if (k > screenK) // TOP: right half { screenPos = new Vector3(screenBound.y / k, screenBound.y, 0); } else // RIGHT: top half { screenPos = new Vector3(screenBound.x, screenBound.x * k, 0); } } else { if (k > screenK) // BOTTOM: left half { screenPos = new Vector3(-screenBound.y / k, -screenBound.y, 0); } else // LEFT: bottom half { screenPos = new Vector3(-screenBound.x, -screenBound.x * k, 0); } } } else { if (screenPos.x > 0) { if (k > -screenK) // RIGHT: bottom half { screenPos = new Vector3(screenBound.x, screenBound.x * k, 0); } else // BOTTOM: right half { screenPos = new Vector3(-screenBound.y / k, -screenBound.y, 0); } } else { if (k > -screenK) // LEFT: top half { screenPos = new Vector3(-screenBound.x, -screenBound.x * k, 0); } else // TOP: left half { screenPos = new Vector3(screenBound.y / k, screenBound.y, 0); } } } } // Coordinate translated to bottom left screenPos += screenCenter; ElementIndicator indicator = GetIndicator(); indicator.transform.position = screenPos; indicator.transform.localRotation = Quaternion.Euler(0, 0, angle * Mathf.Rad2Deg); indicator.GetComponent <Image> ().color = color; } }