public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent, bool screenCenterAsZero = false, bool isNGUI = true) { Camera camera = mCameraManager.getUICamera().getCamera(); Vector2 rootSize = WidgetUtility.getRootSize(); screenPos.x = screenPos.x / camera.pixelWidth * rootSize.x; screenPos.y = screenPos.y / camera.pixelHeight * rootSize.y; Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero; txUIObject root = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot(); Vector3 scale = root.getScale(); parentWorldPosition.x = parentWorldPosition.x / scale.x; parentWorldPosition.y = parentWorldPosition.y / scale.y; Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one; Vector2 pos = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y); Vector2 windowPos = new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y); if (screenCenterAsZero) { windowPos -= rootSize / 2; } return(windowPos); }
protected override void applyScreenPosition(Vector3 screenPos) { txUIObject window = mComponentOwner as txUIObject; Vector2 rootSize = WidgetUtility.getRootSize(); window.setLocalPosition(UnityUtility.screenPosToWindowPos(screenPos, window.getParent()) - rootSize / 2); }
public static bool whetherGameObjectInScreen(Vector3 worldPos) { Vector3 screenPos = worldPosToScreenPos(worldPos); Vector2 rootSize = WidgetUtility.getRootSize(); return(screenPos.z >= 0.0f && (screenPos.x > 0 && screenPos.x < rootSize.x) && (screenPos.y > 0 && screenPos.y < rootSize.y)); }