/** * <summary>Updates a Menu's position.</summary> * <param name = "menu">The Menu to reposition</param> * <param name = "invertedMouse">The y-inverted mouse position</param> */ public void UpdateMenuPosition(AC.Menu menu, Vector2 invertedMouse) { if (menu.IsUnityUI ()) { if (Application.isPlaying) { Vector2 screenPosition = Vector2.zero; if (menu.uiPositionType == UIPositionType.Manual) { return; } else if (menu.uiPositionType == UIPositionType.FollowCursor) { screenPosition = new Vector2 (invertedMouse.x, Screen.height + 1f - invertedMouse.y); menu.SetCentre (screenPosition); } else if (menu.uiPositionType == UIPositionType.OnHotspot) { if (!menu.IsFadingOut ()) { if (mouseOverInventory) { screenPosition = new Vector2 (activeInventoryBoxCentre.x, Screen.height + 1f - activeInventoryBoxCentre.y); menu.SetCentre (screenPosition); } else if (KickStarter.playerInteraction.GetActiveHotspot ()) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (KickStarter.playerInteraction.GetActiveHotspot ().transform.position); } else { screenPosition = KickStarter.playerInteraction.GetHotspotScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } } else if (menu.uiPositionType == UIPositionType.AboveSpeakingCharacter) { Char speaker = null; if (dupMenus.Contains (menu)) { if (menu.speech != null) { speaker = menu.speech.GetSpeakingCharacter (); } } else { speaker = KickStarter.dialog.GetSpeakingCharacter (); } if (speaker != null) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (speaker.transform.position); } else { screenPosition = speaker.GetScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } else if (menu.uiPositionType == UIPositionType.AbovePlayer) { if (KickStarter.player) { if (menu.canvas.renderMode == RenderMode.WorldSpace) { menu.SetCentre (KickStarter.player.transform.position); } else { screenPosition = KickStarter.player.GetScreenCentre (); screenPosition = new Vector2 (screenPosition.x * Screen.width, (1f - screenPosition.y) * Screen.height); menu.SetCentre (screenPosition); } } } } return; } if (invertedMouse == Vector2.zero) { invertedMouse = KickStarter.playerInput.GetInvertedMouse (); } if (menu.positionType == AC_PositionType.FollowCursor) { menu.SetCentre (new Vector2 ((invertedMouse.x / Screen.width) + (menu.manualPosition.x / 100f) - 0.5f, (invertedMouse.y / Screen.height) + (menu.manualPosition.y / 100f) - 0.5f)); } else if (menu.positionType == AC_PositionType.OnHotspot) { if (!menu.IsFadingOut ()) { if (mouseOverInventory) { Vector2 screenPosition = new Vector2 (activeInventoryBoxCentre.x / Screen.width, activeInventoryBoxCentre.y / Screen.height); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } else if (KickStarter.playerInteraction.GetActiveHotspot ()) { Vector2 screenPosition = KickStarter.playerInteraction.GetHotspotScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } } else if (menu.positionType == AC_PositionType.AboveSpeakingCharacter) { Char speaker = null; if (dupMenus.Contains (menu)) { if (menu.speech != null) { speaker = menu.speech.GetSpeakingCharacter (); } } else { speaker = KickStarter.dialog.GetSpeakingCharacter (); } if (speaker != null) { Vector2 screenPosition = speaker.GetScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } else if (menu.positionType == AC_PositionType.AbovePlayer) { if (KickStarter.player) { Vector2 screenPosition = KickStarter.player.GetScreenCentre (); menu.SetCentre (new Vector2 (screenPosition.x + (menu.manualPosition.x / 100f) - 0.5f, screenPosition.y + (menu.manualPosition.y / 100f) - 0.5f)); } } }