private void Initialize() { if (isInitialized) { return; } // Set the GUI Canvas. RootCanvas = CanvasHelper.GetRootCanvas(); if (GuiCanvas == null) { GuiCanvas = RootCanvas; } // Set the GUI Camera. if (guiCamera == null) { guiCamera = Camera.main; } Tooltips = new Dictionary <TooltipStyle, Tooltip>(); // Create a new RectTransform container to hold all the tooltip instances. TooltipContainer = CreateTooltipContainer("Tooltip Container"); // Create a new RectTransform container for tooltips that are never angled/rotated. TooltipContainerNoAngle = CreateTooltipContainer("Tooltip Container (No Angle)"); ResetTooltipRotation(); isInitialized = true; }
private void Initialize() { if (isInitialized) { return; } RootCanvas = CanvasHelper.GetRootCanvas(); Tooltips = new Dictionary <TooltipStyle, Tooltip>(); isInitialized = true; }
/// <summary>Displays the tooltip.</summary> /// <remarks> /// This method first waits a couple frames before sizing and positioning the tooltip. /// This is necessary in order to get an accurate preferredWidth property of the dynamic text field. /// </remarks> public IEnumerator Show(TooltipTrigger trigger) { if (trigger.tooltipStyle == null) { Debug.LogWarning("TooltipTrigger \"" + trigger.name + "\" has no associated TooltipStyle. Cannot show tooltip."); yield break; } Tooltip tooltip = trigger.Tooltip; Image tooltipBkgImg = tooltip.BackgroundImage; // Move the tooltip to the No Angle container if it should never be rotated. if (tooltip.NeverRotate) { tooltip.GameObject.transform.SetParent(TooltipContainerNoAngle.transform, false); } // Replace dynamic image placeholders with the correct images. if (trigger.dynamicImageFields != null) { for (int i = 0; i < trigger.dynamicImageFields.Count; i++) { for (int j = 0; j < tooltip.ImageFields.Count; j++) { if (tooltip.ImageFields[j].Name == trigger.dynamicImageFields[i].name) { if (trigger.dynamicImageFields[i].replacementSprite == null) { tooltip.ImageFields[j].Image.sprite = tooltip.ImageFields[j].Original; } else { tooltip.ImageFields[j].Image.sprite = trigger.dynamicImageFields[i].replacementSprite; } } } } } // Toggle dynamic sections on or off. if (trigger.dynamicSectionFields != null) { for (int i = 0; i < trigger.dynamicSectionFields.Count; i++) { for (int j = 0; j < tooltip.SectionFields.Count; j++) { if (tooltip.SectionFields[j].Name == trigger.dynamicSectionFields[i].name) { tooltip.SectionFields[j].GameObject.SetActive(trigger.dynamicSectionFields[i].isOn); } } } } // Wait for 2 frames so we get an accurate PreferredWidth on the Text component. yield return(WaitFor.Frames(2)); // Get the parent canvas for this tooltip trigger. GuiCanvas = trigger.GetComponentInParent <Canvas>(); // If no parent canvas is found for the trigger object, use the main canvas. if (GuiCanvas == null) { GuiCanvas = CanvasHelper.GetRootCanvas(); } // Parent the tooltip container under the correct canvas. TooltipContainer.transform.SetParent(GuiCanvas.transform, false); // Set the position of the tooltip. tooltip.SetPosition(trigger, GuiCanvas, guiCamera); // Set the tint color of the tooltip panel and tips. tooltipBkgImg.color = trigger.backgroundTint; // If this is a blocking tooltip, assign it as such. if (tooltip.IsBlocking) { BlockingTooltip = tooltip; } // Display the tooltip. tooltip.Display(fadeDuration); }