Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by nTu4Ka · Feb 12, 2014 at 06:34 PM · guitooltip

How can I create complex tooltips

Hi,

Is there a way to create a complex tooltip for a box item? Meaning a single window containing both images and texts positioned as I need them.

I assume there ways like: -a mouse position check: if a box contains mouse and create a window -a lot of boxes in one place(?) each one containing a part of whole tooltip

But maybe there is a predefined instrument or something with less code writing?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nTu4Ka · Feb 12, 2014 at 06:58 PM 0
Share

Just want to add. The box is drawn inside a modalWindow.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by NickP_2 · Feb 12, 2014 at 07:05 PM

Use GUITextures and GUIText, these can be found under the GameObject -> create other menu.

These are tricky to work with, but so powerful when you get a grip on it!

I suggest you to read this

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nTu4Ka · Feb 12, 2014 at 08:54 PM 0
Share

Ah, I see what you mean. Looks really interesting.

avatar image
1

Answer by Scribe · Feb 12, 2014 at 10:55 PM

Hello! as NickP suggested, it is often better to use GUIElements as they are only called when they are updated rather than OnGUI which is often called ~twice per frame although as he also mentioned they are much harder to work with on trickier problems and I think as you can only have 1 tooltip active at a time it may be better to use the OnGUI method for your problem.




The main part of this code is the custom class MyGUI.Tooltip. It requires a few arguments to be passed to it:

  1. position : Vector2 => the position of the top, right corner of the tooltip

  2. imageSize : int => the size that images should be displayed

  3. spacer : int => a spacing value, to have some gaps between images

  4. images : Texture2D[] => a list of the images you want shown

  5. string : String => the string you want written

The is an example of how you can call it using a GUI.tooltip value in the OnGUI method.




Code




 import System;
 
 private var index : int;
 private var imageList;
 var imageList0 : Texture2D[];
 var imageList1 : Texture2D[];
 var imageList2 : Texture2D[];
 var stringList : String[] = ["I am the first tooltip!", "im the second tooltip though my index is 1", "3"];
 
 var imageSize : int = 32;
 var spacerSize : int = 5;
 
 public class MyGUI{
     public static function Tooltip(position : Vector2, imageSize : int, spacer : int, images : Texture2D[], string : String){
         var stringSize = GUI.skin.GetStyle("Box").CalcSize(GUIContent(string));
         var imagePanel : Vector2 = Vector2(
             imageSize*images.Length + spacer*Mathf.Max(0, images.Length-1) + spacer,
             (imageSize+spacer)*Mathf.Min(1, images.Length) + spacer);
         var tooltipSize = Vector2(
             Mathf.Max(stringSize.x, imagePanel.x) + spacer,
             imagePanel.y + stringSize.y + spacer);
         GUI.BeginGroup(Rect(position.x, position.y, tooltipSize.x, tooltipSize.y));
             GUI.Box(Rect(0, 0, tooltipSize.x, tooltipSize.y), "");
             GUI.Label(
                 Rect(3 + (tooltipSize.x-stringSize.x)/2.0,
                 imagePanel.y,
                 stringSize.x,
                 stringSize.y),
                 string);
             var imageSpacer = (tooltipSize.x - images.Length*imageSize)/(images.Length+1);
             for(var i = 0; i < images.Length; i++){
                 GUI.DrawTexture(Rect(imageSpacer + i*(imageSize+imageSpacer), spacer, imageSize, imageSize), images[i]);
             }
         GUI.EndGroup();
     }
 }
 
 function Start(){
     imageList = [imageList0, imageList1, imageList2];
 }
 
 
 function OnGUI(){
     GUI.Box (Rect (10, 10, 20, 20), GUIContent("", "0"));
     GUI.Box (Rect (40, 10, 20, 20), GUIContent("", "1"));
     GUI.Box (Rect (70, 10, 20, 20), GUIContent("", "2"));
     
     if(GUI.tooltip != ""){
         try{
             index = Int32.Parse(GUI.tooltip);
             MyGUI.Tooltip(Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y),
                 imageSize,
                 spacerSize,
                 imageList[index],
                 stringList[index]);
         }catch(err : System.FormatException){
         }
     }
 }

Scribe

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NickP_2 · Feb 13, 2014 at 06:36 AM 0
Share

Never seen your kind of method to create a GUI! Looks interesting, going to try it tonight!

avatar image nTu4Ka · Feb 14, 2014 at 07:50 PM 0
Share

Wow! Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why can't I get my tooltip to show only when there is a tooltip set? 2 Answers

tooltip to show from array C# 1 Answer

Display tooltips for objects in scene 1 Answer

automatic gui tooltips 1 Answer

Dynamic Resizing of tooltip to match content? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges