コード例 #1
0
        /// <summary>Triggers a tooltip immediately on the game object specified.</summary>
        /// <param name="onObject">The game object to pop a tooltip over.</param>
        public void PopupTooltip(GameObject onObject, string bodyText, string buttonText)
        {
            // Add the TooltipTrigger component to the object we want to pop a tooltip up for.
            TooltipTrigger tooltipTrigger = onObject.GetComponent <TooltipTrigger>();

            // if the tooltip trigger is already being remotely controlled by this game object, exit.
            //if (tooltipTrigger != null && tooltipTrigger.remoteTrigger == gameObject) return;

            if (tooltipTrigger == null)
            {
                tooltipTrigger = onObject.AddComponent <TooltipTrigger>();
            }

            TooltipStyle tooltipStyle = Resources.Load <TooltipStyle>("CleanSimpleCloseButton");

            tooltipTrigger.tooltipStyle = tooltipStyle;

            // Set the tooltip text and properties.
            tooltipTrigger.SetText("BodyText", bodyText);
            tooltipTrigger.SetText("ButtonText", String.IsNullOrEmpty(buttonText) ? "Continue" : buttonText);
            tooltipTrigger.tipPosition  = TipPosition.TopRightCorner;
            tooltipTrigger.maxTextWidth = 300;
            tooltipTrigger.staysOpen    = true; // make this a tooltip that stays open...
            tooltipTrigger.isBlocking   = true; // ...and is blocking (no other tooltips allowed while this one is active).

            // Popup the tooltip and give it the object that triggered it (the Canvas in this case).
            tooltipTrigger.Popup(8f, gameObject);
        }
コード例 #2
0
        /// <summary>
        /// This is an example of creating a button at runtime from a prefab that does NOT already have a tooltip,
        /// programmatically adding a tooltip to it that does not already exist in the scene, and modifying it to
        /// display whatever dynamic message we want.
        /// </summary>
        private void AddNewTooltip()
        {
            // Load the button from Resources.
            GameObject buttonPrefab = Resources.Load <GameObject>("DynamicObjWithoutTooltip");

            if (buttonPrefab != null)
            {
                // Assuming the prefab exists, instantiate the button and set its parent.
                GameObject button = Instantiate(buttonPrefab);
                button.transform.SetParent(transform, false);

                // Add the TooltipTrigger component to the button.
                TooltipTrigger tooltipTrigger = button.gameObject.AddComponent <TooltipTrigger>();
                TooltipStyle   tooltipStyle   = Resources.Load <TooltipStyle>("MetroSimple");
                tooltipTrigger.tooltipStyle = tooltipStyle;

                // Set the tooltip text.
                tooltipTrigger.SetText("BodyText", String.Format("This object was created at <b><color=#F3B200>runtime</color></b> from a prefab that <b><color=#F3B200>did not</color></b> already have a tooltip on it. The tooltip was added programmatically and the message and other parameters modified through code. This \"metro\" tooltip style was also added dynamically to the scene.\n\nObject created and tooltip text assigned at {0}.", DateTime.Now));

                // Set some extra style properties on the tooltip
                tooltipTrigger.maxTextWidth   = 250;
                tooltipTrigger.backgroundTint = Color.white;
                tooltipTrigger.tipPosition    = TipPosition.BottomRightCorner;
            }
        }
コード例 #3
0
ファイル: EquipmentItem.cs プロジェクト: jlavoine/DotR
        /// <summary>Resets the tooltip for this equipment item. Call this function anytime the stats of the item change.</summary>
        public void ResetTooltip()
        {
            // If this item is equipped, turn off the Equipped Item section of the tooltip.
            if (isEquipped)
            {
                TooltipTrigger.TurnSectionOff("EquippedItem");
            }
            else
            {
                TooltipTrigger.TurnSectionOn("EquippedItem");
                // Get a list of all the currently equipped items on the character. In reality, you would probably keep this list elsewhere,
                // but we're just querying the items here to keep it simple.
                EquipmentItem[] equipmentItems = FindObjectsOfType <EquipmentItem>();

                for (int i = 0; i < equipmentItems.Length; i++)
                {
                    if (equipmentItems[i].isEquipped && equipmentItems[i].itemType == itemType)
                    {
                        TooltipTrigger.SetText("EquippedName", equipmentItems[i].itemName);
                        Image equippedImage = equipmentItems[i].GetComponent <Image>();
                        TooltipTrigger.SetImage("EquippedItemImage", equippedImage.sprite);
                        TooltipTrigger.SetText("EquippedStats", GetStatsText(equipmentItems[i]));
                        TooltipTrigger.SetText("EquippedValue", String.Format("<color=#888888>VALUE: </color> <size=14>{0}</size>", equipmentItems[i].value.ToString("##,000")));
                        break;
                    }
                }
            }

            // Set the Rarity colors
            string rarityColor = "bbbbbb"; // Default "Common" gray color.

            switch (rarity)
            {
            case Rarity.Rare:
                rarityColor = "FFC924";     // Amber color for "Rare".
                break;

            case Rarity.Uncommon:
                rarityColor = "25ff00";     // Green color for "Uncommon".
                break;
            }

            TooltipTrigger.SetText("TitleText", String.Format("{0} ({1})", itemName, itemType));
            TooltipTrigger.SetText("Stats", GetStatsText(this));
            TooltipTrigger.SetText("Description", "<b>NOTE:</b> This tooltip is dynamically populated at runtime with values from the item!");
            TooltipTrigger.SetText("Value", String.Format("<color=#888888>VALUE: </color> <size=16>{0}</size>", value.ToString("##,000")));
            TooltipTrigger.SetText("Rarity", String.Format("<color=#{0}>{1} {2}</color>", rarityColor, rarity, itemType));
            TooltipTrigger.SetImage("ItemImage", Image.sprite);
        }
コード例 #4
0
        /// <summary>
        /// This is an example of creating a button at runtime from a prefab that already has a tooltip on it,
        /// and modifying the tooltip to display whatever dynamic message we want.
        /// </summary>
        private void ModifyExistingTooltip()
        {
            // Load the button from Resources.
            GameObject buttonPrefab = Resources.Load <GameObject>("DynamicObjWithTooltip");

            if (buttonPrefab != null)
            {
                // Assuming the prefab exists, instantiate the button and set its parent.
                GameObject button = Instantiate(buttonPrefab);
                button.transform.SetParent(transform, false);

                // Get the TooltipTrigger component on the button.
                TooltipTrigger tooltipTrigger = button.GetComponent <TooltipTrigger>();
                if (tooltipTrigger != null) // Set the tooltip text.
                {
                    tooltipTrigger.SetText("BodyText", String.Format("This object was created at <b><color=#0049CE>runtime</color></b> from a prefab that already had a tooltip on it, and the tooltip message was modified programmatically.\n\nObject created and tooltip text assigned at {0}.", DateTime.Now));
                }
            }
        }