protected void AutoSize(GUIContent content) { GUIStyle normalStyle = new GUIStyle(); normalStyle.font = font; normalStyle.fontSize = GetFontSize(); if (string.IsNullOrEmpty(content.text)) { Vector2 oldSize = normalStyle.CalcSize(content); SetAbsoluteSize(oldSize); return; } // Calculate with no word-wrapping Vector2 singleLineSize = normalStyle.CalcSize(content); // Calculate with word-wrapping normalStyle.wordWrap = true; float maxWidth = AdvGame.GetMainGameViewSize().x / 2f; float height = normalStyle.CalcHeight(content, maxWidth); Vector2 wrappedSize = new Vector2(maxWidth, height); // Compare the two sizes if (wrappedSize.y == singleLineSize.y && singleLineSize.x < wrappedSize.x) { wrappedSize.x = singleLineSize.x; } wrappedSize.x += 2; SetAbsoluteSize(wrappedSize); }
public virtual void RecalculateSize(MenuSource source) { if (source != MenuSource.AdventureCreator) { return; } dragOffset = Vector2.zero; Vector2 screenSize = Vector2.one; if (sizeType == AC_SizeType.Automatic) { AutoSize(); } if (sizeType != AC_SizeType.AbsolutePixels) { screenSize = new Vector2(AdvGame.GetMainGameViewSize().x / 100f, AdvGame.GetMainGameViewSize().y / 100f); } if (orientation == ElementOrientation.Horizontal) { relativeRect.width = slotSize.x * screenSize.x * numSlots; relativeRect.height = slotSize.y * screenSize.y; if (numSlots > 1) { relativeRect.width += slotSpacing * screenSize.x * (numSlots - 1); } } else if (orientation == ElementOrientation.Vertical) { relativeRect.width = slotSize.x * screenSize.x; relativeRect.height = slotSize.y * screenSize.y * numSlots; if (numSlots > 1) { relativeRect.height += slotSpacing * screenSize.y * (numSlots - 1); } } else if (orientation == ElementOrientation.Grid) { if (numSlots < gridWidth) { relativeRect.width = (slotSize.x + slotSpacing) * screenSize.x * numSlots; relativeRect.height = slotSize.y * screenSize.y; } else { float numRows = Mathf.CeilToInt((float)numSlots / gridWidth); relativeRect.width = slotSize.x * screenSize.x * gridWidth; relativeRect.height = slotSize.y * screenSize.y * numRows; if (numSlots > 1) { relativeRect.width += slotSpacing * screenSize.x * (gridWidth - 1); relativeRect.height += slotSpacing * screenSize.y * (numRows - 1); } } } }
private void DrawPreviewMenu(Menu menu) { if (menu == null || menu.IsUnityUI()) { return; } if (KickStarter.mainCamera != null) { KickStarter.mainCamera.DrawBorders(); } CheckScreenSize(menu); if (menu.CanPause() && menu.pauseWhenEnabled && menuManager.pauseTexture) { GUI.DrawTexture(AdvGame.GUIRect(0.5f, 0.5f, 1f, 1f), menuManager.pauseTexture, ScaleMode.ScaleToFit, true, 0f); } if ((menu.positionType == AC_PositionType.FollowCursor || menu.positionType == AC_PositionType.AppearAtCursorAndFreeze || menu.positionType == AC_PositionType.OnHotspot || menu.positionType == AC_PositionType.AboveSpeakingCharacter || menu.positionType == AC_PositionType.AbovePlayer) && AdvGame.GetReferences().cursorManager&& AdvGame.GetReferences().cursorManager.pointerIcon.texture) { CursorIconBase icon = AdvGame.GetReferences().cursorManager.pointerIcon; GUI.DrawTexture(AdvGame.GUIBox(new Vector2(AdvGame.GetMainGameViewSize().x / 2f, AdvGame.GetMainGameViewSize().y / 2f), icon.size), icon.texture, ScaleMode.ScaleToFit, true, 0f); } menu.StartDisplay(); foreach (MenuElement element in menu.visibleElements) { SetStyles(element); for (int i = 0; i < element.GetNumSlots(); i++) { if (menuManager.GetSelectedElement() == element && element.isClickable && i == 0) { element.Display(highlightedStyle, i, 1f, true); } else { element.Display(normalStyle, i, 1f, false); } } if (UnityEditor.EditorWindow.mouseOverWindow != null && UnityEditor.EditorWindow.mouseOverWindow.ToString() != null && UnityEditor.EditorWindow.mouseOverWindow.ToString().Contains("(UnityEditor.GameView)")) { if (menu.IsPointerOverSlot(element, 0, Event.current.mousePosition + new Vector2(menu.GetRect().x, menu.GetRect().y))) { menuManager.SelectElementFromPreview(menu, element); } } } menu.EndDisplay(); if (menuManager.drawOutlines) { menu.DrawOutline(menuManager.GetSelectedElement()); } }
/** * Updates the GameObject's position according to the camera. This is called every frame by the StateHandler. */ public void UpdateOffset() { switch (reactsTo) { case ParallaxReactsTo.Camera: if (KickStarter.mainCamera.attachedCamera is GameCamera2D && !KickStarter.mainCamera.attachedCamera.Camera.orthographic) { perspectiveOffset = KickStarter.mainCamera.GetPerspectiveOffset(); } else { perspectiveOffset = new Vector2(Camera.main.transform.position.x, Camera.main.transform.position.y); } break; case ParallaxReactsTo.Cursor: Vector2 screenCentre = AdvGame.GetMainGameViewSize() / 2f; Vector2 mousePosition = KickStarter.playerInput.GetMousePosition(); perspectiveOffset = new Vector2(((1f - mousePosition.x) / screenCentre.x) + 1f, ((1f - mousePosition.y) / screenCentre.y + 1f)); break; } if (limitX) { perspectiveOffset.x = Mathf.Clamp(perspectiveOffset.x, minX, maxX); } if (limitY) { perspectiveOffset.y = Mathf.Clamp(perspectiveOffset.y, minY, maxY); } xDesired = xStart; if (xScroll) { xDesired += perspectiveOffset.x * depth; xDesired += xOffset; } yDesired = yStart; if (yScroll) { yDesired += perspectiveOffset.y * depth; yDesired += yOffset; } if (xScroll && yScroll) { transform.localPosition = new Vector3(xDesired, yDesired, transform.localPosition.z); } else if (xScroll) { transform.localPosition = new Vector3(xDesired, transform.localPosition.y, transform.localPosition.z); } else if (yScroll) { transform.localPosition = new Vector3(transform.localPosition.x, yDesired, transform.localPosition.z); } }
public int GetFontSize() { if (sizeType == AC_SizeType.AbsolutePixels) { return((int)(fontScaleFactor * 10f)); } return((int)(AdvGame.GetMainGameViewSize().x *fontScaleFactor / 100)); }
protected override void AutoSize() { int languageNumber = Options.GetLanguage(); string _newLabel = (Application.isPlaying) ? newLabel : label; if (labelType == AC_LabelType.DialogueLine) { GUIContent content = new GUIContent(TranslateLabel(_newLabel, languageNumber)); #if UNITY_EDITOR if (!Application.isPlaying) { if (speech != null && !string.IsNullOrEmpty(speech.displayText)) { // Timeline preview content = new GUIContent(speech.displayText); } AutoSize(content); return; } #endif GUIStyle normalStyle = new GUIStyle(); normalStyle.font = font; normalStyle.fontSize = (int)(AdvGame.GetMainGameViewSize(true).x *fontScaleFactor / 100); UpdateSpeechLink(); if (speech != null) { string line = " " + speech.FullText + " "; content = new GUIContent(line); // AutoSize(content); } } else if (labelType == AC_LabelType.ActiveSaveProfile) { GUIContent content = new GUIContent(GetLabel(0, 0)); AutoSize(content); } else if (string.IsNullOrEmpty(_newLabel) && backgroundTexture != null) { GUIContent content = new GUIContent(backgroundTexture); AutoSize(content); } else if (labelType == AC_LabelType.Normal) { GUIContent content = new GUIContent(TranslateLabel(_newLabel, languageNumber)); AutoSize(content); } else { GUIContent content = new GUIContent(_newLabel); AutoSize(content); } }
/** * <summary>Checks if the the point of contact is visible on-screen.</summary> * <returns>True if the point of contact is visible on-screen.</returns> */ public bool IsOnScreen() { Vector2 screenPosition = Camera.main.WorldToScreenPoint(grabPoint.position); if (screenPosition.x < 0f || screenPosition.y < 0f || screenPosition.x > AdvGame.GetMainGameViewSize().x || screenPosition.y > AdvGame.GetMainGameViewSize().y) { return(false); } return(true); }
private Rect GetDragRectRelative() { Rect positionRect = dragRect; if (sizeType != AC_SizeType.AbsolutePixels) { positionRect.x = dragRect.x / 100f * AdvGame.GetMainGameViewSize(true).x; positionRect.y = dragRect.y / 100f * AdvGame.GetMainGameViewSize(true).y; positionRect.width = dragRect.width / 100f * AdvGame.GetMainGameViewSize(true).x; positionRect.height = dragRect.height / 100f * AdvGame.GetMainGameViewSize(true).y; } return(positionRect); }
protected override void AutoSize() { int languageNumber = Options.GetLanguage(); if (labelType == AC_LabelType.DialogueLine) { GUIContent content = new GUIContent(TranslateLabel(label, languageNumber)); #if UNITY_EDITOR if (!Application.isPlaying) { AutoSize(content); return; } #endif GUIStyle normalStyle = new GUIStyle(); normalStyle.font = font; normalStyle.fontSize = (int)(AdvGame.GetMainGameViewSize(true).x *fontScaleFactor / 100); UpdateSpeechLink(); if (speech != null) { string line = " " + speech.log.fullText + " "; if (line.Length > 40) { line = line.Insert(line.Length / 2, " \n "); } content = new GUIContent(line); AutoSize(content); } } else if (labelType == AC_LabelType.ActiveSaveProfile) { GUIContent content = new GUIContent(GetLabel(0, 0)); AutoSize(content); } else if (label == "" && backgroundTexture != null) { GUIContent content = new GUIContent(backgroundTexture); AutoSize(content); } else { GUIContent content = new GUIContent(TranslateLabel(label, languageNumber)); AutoSize(content); } }
public static void DrawTextEffect(Rect rect, string text, GUIStyle style, Color outColor, Color inColor, float size, TextEffects textEffects) { if (AdvGame.GetReferences().menuManager != null && AdvGame.GetReferences().menuManager.scaleTextEffects) { size = AdvGame.GetMainGameViewSize().x / 200f / size; } if (textEffects == TextEffects.Outline || textEffects == TextEffects.OutlineAndShadow) { AdvGame.DrawTextOutline(rect, text, style, outColor, inColor, size); } if (textEffects == TextEffects.Shadow || textEffects == TextEffects.OutlineAndShadow) { AdvGame.DrawTextShadow(rect, text, style, outColor, inColor, size); } }
private void DrawSlider(float zoom) { sliderRect = relativeRect; if (sliderDisplayType == SliderDisplayType.FillBar) { if (useFullWidth) { sliderRect.x = relativeRect.x; sliderRect.width = slotSize.x * visualAmount; } else { sliderRect.x = relativeRect.x + (relativeRect.width / 2); sliderRect.width = slotSize.x * visualAmount * 0.5f; } if (sizeType != AC_SizeType.AbsolutePixels) { sliderRect.width *= AdvGame.GetMainGameViewSize().x / 100f; } } else if (sliderDisplayType == SliderDisplayType.MoveableBlock) { sliderRect.width *= blockSize.x; sliderRect.height *= blockSize.y; sliderRect.y += (relativeRect.height - sliderRect.height) / 2f; if (useFullWidth) { sliderRect.x = slotSize.x * visualAmount + relativeRect.x - (sliderRect.width / 2f); } else { sliderRect.x = slotSize.x * visualAmount * 0.5f + relativeRect.x + (relativeRect.width / 2) - (sliderRect.width / 2f); } if (sizeType != AC_SizeType.AbsolutePixels) { sliderRect.x *= AdvGame.GetMainGameViewSize().x / 100f; } } GUI.DrawTexture(ZoomRect(sliderRect, zoom), sliderTexture, ScaleMode.StretchToFill, true, 0f); }
public Rect GetSlotRectRelative(int _slot) { Vector2 screenFactor = Vector2.one; if (sizeType != AC_SizeType.AbsolutePixels) { screenFactor = new Vector2(AdvGame.GetMainGameViewSize().x / 100f, AdvGame.GetMainGameViewSize().y / 100f); } Rect positionRect = relativeRect; positionRect.width = slotSize.x * screenFactor.x; positionRect.height = slotSize.y * screenFactor.y; if (_slot > numSlots) { _slot = numSlots; } if (orientation == ElementOrientation.Horizontal) { positionRect.x += (slotSize.x + slotSpacing) * _slot * screenFactor.x; } else if (orientation == ElementOrientation.Vertical) { positionRect.y += (slotSize.y + slotSpacing) * _slot * screenFactor.y; } else if (orientation == ElementOrientation.Grid) { int xOffset = _slot + 1; float numRows = Mathf.CeilToInt((float)xOffset / gridWidth) - 1; while (xOffset > gridWidth) { xOffset -= gridWidth; } xOffset -= 1; positionRect.x += (slotSize.x + slotSpacing) * (float)xOffset * screenFactor.x; positionRect.y += (slotSize.y + slotSpacing) * numRows * screenFactor.y; } return(positionRect); }
/** * <summary>Performs the drag.</summary> * <param name = "_dragVector">The amount and direction to drag by</param> * <returns>True if the drag effect was successful</returns> */ public bool DoDrag(Vector2 _dragVector) { if (dragType == DragElementType.EntireMenu) { if (menuToDrag == null) { return(false); } if (!menuToDrag.IsEnabled() || menuToDrag.IsFading()) { return(false); } } if (elementToDrag == null && dragType == DragElementType.SingleElement) { return(false); } // Convert dragRect to screen co-ordinates Rect dragRectAbsolute = dragRect; if (sizeType != AC_SizeType.AbsolutePixels) { dragRectAbsolute = new Rect(dragRect.x * AdvGame.GetMainGameViewSize(true).x / 100f, dragRect.y * AdvGame.GetMainGameViewSize(true).y / 100f, dragRect.width * AdvGame.GetMainGameViewSize(true).x / 100f, dragRect.height * AdvGame.GetMainGameViewSize(true).y / 100f); } if (dragType == DragElementType.EntireMenu) { menuToDrag.SetDragOffset(_dragVector + dragStartPosition, dragRectAbsolute); } else if (dragType == AC.DragElementType.SingleElement) { elementToDrag.SetDragOffset(_dragVector + dragStartPosition, dragRectAbsolute); } return(true); }
/** * <summary>Draws GUI text with an outline and/or shadow.</summary> * <param name = "rect">The Rect of the GUI text</param> * <param name = "text">The text itself</param> * <param name = "style">The GUIStyle that the GUI text uses</param> * <param name = "outColour">The colour of the text's outline/shadow</param> * <param name = "inColour">The colour of the text itself</param> * <param name = "size">The size of the text</param> * <param name = "textEffects">The type of text effect (Outline, Shadow, OutlineAndShadow, None)</param> */ public static void DrawTextEffect(Rect rect, string text, GUIStyle style, Color outColor, Color inColor, float size, TextEffects textEffects) { if (AdvGame.GetReferences().menuManager != null && AdvGame.GetReferences().menuManager.scaleTextEffects) { size = AdvGame.GetMainGameViewSize().x / 200f / size; } int i = 0; string effectText = text; if (effectText != null) { while (text.IndexOf("<color=", i) > 0) { int startPos = effectText.IndexOf("<color=", i); int endPos = 0; if (effectText.IndexOf(">", startPos) > 0) { endPos = effectText.IndexOf(">", startPos); } if (endPos > 0) { effectText = effectText.Substring(0, startPos) + "<color=black>" + effectText.Substring(endPos + 1); } i = startPos + i; } if (textEffects == TextEffects.Outline || textEffects == TextEffects.OutlineAndShadow) { AdvGame.DrawTextOutline(rect, text, style, outColor, inColor, size, effectText); } if (textEffects == TextEffects.Shadow || textEffects == TextEffects.OutlineAndShadow) { AdvGame.DrawTextShadow(rect, text, style, outColor, inColor, size, effectText); } } }
public void SetProximity(bool isGameplay) { if (highlight != null) { if (!isGameplay || !IsOn()) { highlight.SetMinHighlight(0f); } else { float amount = Vector2.Distance(GetIconScreenPosition(), KickStarter.playerInput.GetMousePosition()) / Vector2.Distance(Vector2.zero, AdvGame.GetMainGameViewSize()); if (amount < 0f) { amount = 0f; } else if (amount > 1f) { amount = 1f; } highlight.SetMinHighlight(1f - (amount * KickStarter.settingsManager.highlightProximityFactor)); } } }
private void OnGUI() { if (!Application.isPlaying) { if (AdvGame.GetReferences()) { menuManager = AdvGame.GetReferences().menuManager; if (menuManager && menuManager.drawInEditor) { if (menuManager.GetSelectedMenu() != null) { AC.Menu menu = menuManager.GetSelectedMenu(); if (menu.IsUnityUI()) { return; } CheckScreenSize(menu); if ((menu.appearType == AppearType.Manual || menu.appearType == AppearType.OnInputKey) && menu.pauseWhenEnabled && menuManager.pauseTexture) { GUI.DrawTexture(AdvGame.GUIRect(0.5f, 0.5f, 1f, 1f), menuManager.pauseTexture, ScaleMode.ScaleToFit, true, 0f); } if ((menu.positionType == AC_PositionType.FollowCursor || menu.positionType == AC_PositionType.AppearAtCursorAndFreeze || menu.positionType == AC_PositionType.OnHotspot || menu.positionType == AC_PositionType.AboveSpeakingCharacter || menu.positionType == AC_PositionType.AbovePlayer) && AdvGame.GetReferences().cursorManager&& AdvGame.GetReferences().cursorManager.pointerIcon.texture) { CursorIconBase icon = AdvGame.GetReferences().cursorManager.pointerIcon; GUI.DrawTexture(AdvGame.GUIBox(new Vector2(AdvGame.GetMainGameViewSize().x / 2f, AdvGame.GetMainGameViewSize().y / 2f), icon.size), icon.texture, ScaleMode.ScaleToFit, true, 0f); } menu.StartDisplay(); foreach (MenuElement element in menu.visibleElements) { SetStyles(element); for (int i = 0; i < element.GetNumSlots(); i++) { if (menuManager.GetSelectedElement() == element && element.isClickable && i == 0) { // element.PreDisplay (i, true, 0); element.Display(highlightedStyle, i, 1f, true); } else { // element.PreDisplay (i, true, 0); element.Display(normalStyle, i, 1f, false); } } if (menu.IsPointerOverSlot(element, 0, Event.current.mousePosition + new Vector2(menu.GetRect().x, menu.GetRect().y))) { menuManager.SelectElementFromPreview(menu, element); } } menu.EndDisplay(); if (menuManager.drawOutlines) { menu.DrawOutline(menuManager.GetSelectedElement()); } } } } } }
protected void SetAbsoluteSize(Vector2 _size) { slotSize = new Vector2(_size.x * 100f / AdvGame.GetMainGameViewSize().x, _size.y * 100f / AdvGame.GetMainGameViewSize().y); }