Search Unity

[RELEASED] Dialogue System for Unity - easy conversations, quests, and more!

Discussion in 'Assets and Asset Store' started by TonyLi, Oct 12, 2013.

  1. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    For the Dialogue UI prefab, is it possible to not using UIRoot ? I would like to instantiate Dialogue UI prefab and parent it in my own UIRoot in the Scene.
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Yes, that's fine. When you instantiate, you just need to:
    1. Assign your UIRoot to the dialogue UI's uiRoot variable and then call FindControls() to set it up with the new uiRoot value.
    2. Set deactivateUIRootWhenHidden to false.
     
  3. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    When I have a fresh import of Dialogue System to the unity project, If I open one of the Dialogue Database and select tab "Conversation", everytime I save the project , it throws message of "Cleaning up leaked objects in scene since no game object, component or manager is referencing them Texture2D has been leaked 1 times."
     
  4. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Another problem is that,
    1. opening the Dialogue Editor to tab Conversation
    2. update the Dialogue Text in the Inspector.
    3. play in unity editor ( keep the Dialogue Editor opened), it show the conversation dialog with updated text.
    4. then update the Dialogue Text in the Inspector again.
    5. play in unity editor ( keep the Dialogue Editor opened), it fail to show the updated text.
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi yuewahchan, this is due to garbage collection and should be harmless. I'll see if I can prevent the message anyway in the next release.

    This is addressed in a patch available now on the customer download page (I PM'ed you access information), and will be in the next release on the Asset Store.
     
  6. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    TonyLi, you are so helpful, thank you very much. Just rated 5 stars in asset store.
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Happy to help, and thank you very much for the feedback!
     
  8. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    [Feature Request], Is it possible to have some spreadsheet format or csv format converter ?
     
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi yuewahchan, you can currently convert to Chat Mapper XML format. Will this work? If not, what data are you looking for in the spreadsheet?

    You can import Chat Mapper XML into Chat Mapper. From Chat Mapper, you can export it to spreadsheet format, screenplay format, and more. If you would like a 10% discount code we've arranged with the makers of Chat Mapper, please PM me.
     
    Last edited: May 23, 2014
  10. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using PixelCrushers.DialogueSystem;
    4.  
    5. public class RecordConversationName : MonoBehaviour {
    6.     public void OnConversationStart(Transform actor) {
    7.         DialogueLua.SetVariable("ConversationName", DialogueManager.LastConversationStarted);
    8.     }
    9. }
    10.  
    As your suggestion, it throws error if I call StartConversation without actor and conversant transform
    Failed to call function OnConversationStart of class LogConversation
    Calling function OnConversationStart with no parameters but the function requires 1.
    UnityEngine.GameObject:BroadcastMessage(String, Object, SendMessageOptions)
    PixelCrushers.DialogueSystem.DialogueSystemController:StartConversation(String, Transform, Transform)
    PixelCrushers.DialogueSystem.DialogueManager:StartConversation(String)
     
  11. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    I would like to write script for converting the Google SpreadSheet to Dialogue Database using Google Doc Api. I see there are some converter , ChatMapperConverter, ArticyConverter and AuroraConverter. I see their coding style is very different. Which one is better to start with ? I would suggest having a common converter api for others to adding more converter.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Try something like this, which will handle the case when the actor and conversant are both null:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using PixelCrushers.DialogueSystem;
    4.  
    5. public class RecordConversationName : MonoBehaviour {
    6.     public void OnConversationStart(Transform actor) {
    7.         RecordToLua();
    8.     }
    9.     public void OnConversationStart() {
    10.         RecordToLua();
    11.     }
    12.     public void RecordToLua() {
    13.         DialogueLua.SetVariable("ConversationName", DialogueManager.LastConversationStarted);
    14.     }
    15. }
    16.  
     
  13. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    That's another good idea. I'll add a common API to the roadmap. I'll try to include a Google Spreadsheets converter as an example for the common API.
     
  14. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Actually, I am urgent to make the google spreadsheet converter by myself. So, which existing converter is better to start with?
     
  15. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Btw, the xls format of chat mapper is hard to work with. I would suggest the all the conversation and its dialog entries can be edited in the same spreadsheet. What do u think?
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    The Chat Mapper Converter (Scripts/Core/Editor/ChatMapperConverter.cs) is the simplest. It's probably the best one to start with. If you have any questions about it, please post here or email me directly at tony (at) pixelcrushers.com.

    Every type of asset (actor, item, quest, variable, conversation, dialogue entry) has different fields. An Actor has a portrait texture, but a Variable doesn't. The spreadsheet is going to be complex no matter what, since the original data is complex. We can probably do one worksheet per asset type. So you'd have a worksheet of Actors, a worksheet of Items, a worksheet of Dialogue Entries, etc.

    May I ask what's the reason for the spreadsheet? The industry has generally moved away from spreadsheets for dialogue since we've realized that the data is more complex than spreadsheets can represent efficiently. Hence the rise of products like Chat Mapper and articy:draft. The only area where spreadsheets are commonly used any more is localization translation because translators are used to going through a column of lines in a spreadsheet and translating each line. Then again, there are retro developers who use spreadsheets, use 8-bit art, etc.
     
    Last edited: May 23, 2014
  17. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Actually, I have coded an early version of spreadsheet converter by looking at the ChatMapperConverter as it is simple than other two converter. Later, it seems that it is too simple and the coding structure is different to other two. For your new common converter api, which converters will you be based on or totally from ground up?
     
  18. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    In my company, the dialogue content is outsourced to the writers all over the world, they are usually not willing to learn new tools. But very good to work with spreadsheet. And Google spreadsheet is web based, easier to access, free, and they can be worked (edited) at the same time. e.g. Some one can write the dialogue script, someone can input the animation sequence.

    Our game dialogue flow is quite simple and linear, so spreadsheet is enough.
     
    Last edited: May 23, 2014
  19. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    yes, you are right, each type of asset should put in different sheets (table).
     
  20. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    From the ground up. The runtime code was designed to be modified and extendable by the user; the editor code not so much, but clearly it's possible to do since you already did it. A common API will make it easier in the future.

    Got it.

    I plan to put these in a single release:
    1. Export to spreadsheet
    2. Import from spreadsheet
    3. Common converter API
    It won't be next week's release, but possibly the one after. As soon as I can get it implemented, I'll make sure you have a download link to a patch so you can use it as soon as it's available.
     
    Last edited: May 23, 2014
  21. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Connecting and query the google spreadsheet is a little bit tricky, I would like to post the code on next Monday.
     
  22. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Thanks! I plan to use EPPlus to read and write xlsx files.
     
  23. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Last edited: May 26, 2014
  24. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    https://dl.dropboxusercontent.com/u/9322397/GoogleSpreadsheet/GoogleSpreadsheet.unitypackage

    1. Login to https://docs.google.com using google account.
    2. New or open Spreadsheet ( if new, the spreadsheet url looks like "https://docs.google.com/spreadsheets/d/1Z6ndhqEhJTtxC-mytRq2Hw6xEp0fd8wvd-8nlsSN92Q/edit#gid=0" , the worksheet name is "Sheet1")
    3. Enter some value in cell ( if there is empty rows, the google api will fetch nothing below it )
    4. Run the Unity project, and enter the url and worksheet name above, then click "Get Data"
     
  25. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    Just figure out a more elegant method to query the Google Spreadsheet by using linq. Please ignore my previous post.
     
  26. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Hello~

    I finally got around to test this asset out and I'm thrilled so far!
    Would you mind me asking a few questions?

    1. Rich text
    When combining a letter-by-letter skin like JRPG2 with rich text formatting options (e.g. <i>) it is only formatted once it's closes (e.g. </i>) which results in seeing "<i>text</i>" instead of "text" for a second.
    Is there a workaround or does one have to choose one or another?

    2. Stop letter-by-letter
    In case that the previous thing is possible, is there also a way to implement pressing a button to show the whole text instantly when using letter-by-letter? (It's commonly found in games--impatient gamers can press enter once to display the whole text immediately, pressing twice skips to the next box.)

    Thank you a lot for your time!

    - KW
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi yuewahchan, okay, I'll look into this, too. Since Google Sheets can import and export Excel, I had thought it was a more useful format for developers who aren't using Google Sheets. But I agree that direct import/export would streamline the workflow.

    Hi Endorphin, this is on the roadmap. Right now, it's one or the other. If you untick Use Rich Text, letter-by-letter works with [em] codes, but it applies to the entire line. The fade effect works with Rich Text if that's an acceptable substitute until the typewriter effect supports it.

    Yes, you can set up Continue Button Fast Forward. By default, the continue button is a button that you set up in the dialogue UI. Some prefab UIs are already set up with continue buttons. You can add your own continue button to the others. If you want the player to be able to click anywhere on the screen to fast forward, make the button invisible and cover the whole screen.
     
  28. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    @TonyLi, I think it is better that you make a xlsx convertor in the first place, easy for people to get used to and modify. Then I can make my own google spreadsheet by myself.
     
  29. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    In Dialogue Editor 's Tab "Conversations" of node view, the conversation dropdown does not updated when I change the Dialogue Database in Project View.
     
  30. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi yuewahchan, I'll target xlsx first, and then Google Sheets. Thanks, by the way, for the information on Google Sheets.

    The patch on the customer download page fixes this issue. The next release, v1.2.4, is being published later today. It includes many more fixes and enhancements to the Dialogue Editor, and includes this fix, too.
     
  31. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Thank you a lot, this is really helpful!

    Concerning the fade effect, I'm having troubles with this one--I attached it (default settings) to the alert in my custom UI (plus the slide effect), but the screen always seems to "flash" before the alert slides in (I also ran into this problem with the JRPG2 style), plus it doesn't seem to fade out.
    Is there something I'm not aware of?

    - KW
     
  32. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi Endorphin, I'll look into this and get back to you. In the meantime, try deactivating GUIRoot, the dialogue panel (if you assigned one), and the alert panel (if you assigned one). The Dialogue UI script will reactivate them as needed. If they start inactive, it may resolve the flash issue.
     
  33. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Apparently, it was a camera problem since I tested it on the first person controller and thus moved the camera in dialogue--the flashing's gone now.
    Now I'm only having troubles with the fade effect--it works fine with the alert line, but not on the background image, though the slide effect apparently has no problems. I even tried putting the image and the line in a panel and assigning the effects there, but without success (the line is currently parented under a GUI Image which is the background image and is defined in the skin as the alert panel--hopefully this is no problem?).

    I really want to thank you for the superb support and the asset itself, interface design and implementation is a tedious task but thanks to you it's been rather nice so far!

    - KW
     
  34. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Thank you! I'll test the steps to set up the fade effect and post them here later today. It may require the upcoming v1.2.4, which will be available today or tomorrow. GUI Image controls weren't affected by fades prior to v1.2.4. GUI Labels are, though. (Sorry, this was just an oversight on my part.) To simplify your setup, you might consider assigning the texture to the alert GUI style's background image. Then you can get rid of the GUI Image entirely. You'll want to play around with the GUI Style's border settings to get the scaling right, or just set a fixed size.
     
  35. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Oh, that's good to know--I'm not in a hurry, so I don't mind.
    I had problems adjusting the image to have the right proportions in the GUIskin, but I'll definitely give it a try again!

    - KW
     
    Last edited: May 27, 2014
  36. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Gosh, I really hate asking so many questions, but is there any way to adjust the colour of the outline when creating a dialogue UI?

    - KW
     
  37. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    No problem at all! That's why I'm here! :)

    And good timing on the questions, too. That also is in the upcoming v1.2.4 release. You can now set the color of the outline/shadow in GUI Labels, Bark UIs, and the Selector/Proximity Selector.
     
  38. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    The Dialogue System for Unity v1.2.4 is now available on the customer download site, and should be available through the Unity Asset Store in 5-7 days. If you need access to the customer download site, please PM me your invoice number.

    The highlights of this release are:
    • Improvements to Dialogue Editor, including easier quest editing and new Abandoned state for quests
    • RandomElement() Lua function
    • Unity GUI: Customizable outline color, Typewriter effect handles rich text, Fade effect works on GUI Image
    • Updated support for Adventure Creator 1.33b plyGame 2.14d

    Version 1.2.4

    Editors Converters
    • Dialogue Editor improvements:
      - Improved: Changes are now automatically saved when switching between edit and play modes.
      - Improved: Major improvements to quest editing.
      - Improved: Localization fields are shown in the main section of dialogue entries and quests, not just in All Fields.
      - Fixed: Cosmetic issue. Clicking Conversation tab caused "Cleaning up leaked objects in scene since no game object, component or manager is referencing them" message.
    • (Aurora) Quest entries are now sorted by journal ID.
    • (articy:draft) Is Item field set to False now for Flow Fragments (quests).
    Engine
    • Added: Abandoned state to quests.
    • Added: RandomElement() Lua function.
    • Added: DialogueManager.LastConversationStarted property.
    • Improved: Minor performance increase to conversation startups.
    • Changed: Double quotes in dialogue database are now retained (escaped) in the Lua environment, not converted to single quotes.
    • Changed: SetPortrait() now occurs immediately (Unity GUI, NGUI, DF-GUI).
    • Changed: IsDialogueEntryValid now takes immediate effect, not next conversation.
    • Changed: OnConversationLine is now also broadcast to Dialogue Manager.
    UIs Cutscenes
    • Added: TextlessBarkUI (useful for playing bark cutscene sequences without text).
    • Added: New Bark UI option to raycast for visibility to player (Unity, NGUI, RPG Kit, DF-GUI).
    • Added: Added special keyword 'original' to Camera() sequence command.
    • Improved: Audio/AudioWait/Voice() sequencer commands: If subject is null, audio is played on the Dialogue Manager object.
    • Unity GUI system:
      - Added: Text Style Color (for outline/shadow) for GUI Label, Unity Bark UI, Selector.
      - Improved: Typewriter effect now handles rich text.
      - Improved: Fade Effect now works on GUI Image.
      - Fixed: GUIScrollView threw an exception if vertical slider in GUI skin didn't have texture assigned.
      - Fixed: Wheel1a prefab UI (had nested slide effects that weren't working).
    Third-Party Support
    • Adventure Creator support:
      - Updated to support Adventure Creator 1.33b.
      - Bridge now also turns off Adventure Creator camera control during conversations so you can use Dialogue System sequences.
      - Conversation Bark actions now sync before conversations start, so conditions on the START node work.
    • Core GameKit support: Updated example scene for new default LevelSettings values.
    • plyGame support: Updated to support plyGame 2.1.4d.
     
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    An alternate download link is now available on the Pixel Crushers customer download site in case anyone has had trouble downloading the latest version. The hosting provider has been experiencing intermittent network issues recently.
     
  40. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Version 1.2.4 is now available on the Asset Store!
     
  41. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
  42. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi dreamlarp, yes, I'm looking forward to this in Unity 4.6! As soon as it's out, I'll start working on Dialogue System support for it.
     
  43. Earthsnake

    Earthsnake

    Joined:
    Feb 25, 2014
    Posts:
    30
    I have a problem with uSequencer third party support. When I added the add-on asset, this error exist:

    Assets/Dialogue System/Third Party Support/uSequencer/SequencerCommanduSeq.cs(5,7): error CS0246: The type or namespace name `WellFired' could not be found. Are you missing a using directive or an assembly reference?

    Please help, thanks
     
  44. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi Earthsnake, please make sure you've imported uSequencer v1.3.5 or higher. Well Fired moved the uSequencer code into its own namespace ("WellFired") in version 1.3.5, which was released on March 15, 2014.
     
  45. EvilAlfredo

    EvilAlfredo

    Joined:
    Aug 11, 2012
    Posts:
    7
    So, two things. One a question, another a bug.

    Firstly, my project involves the player switching between many different characters, and each have their own set of stats within the actor fields. I'm trying to reference these stats dynamically within conversation (and more specifically, conditions) but since I am using Playmaker to tell the conversation what the actor and conversant are, it seems to have trouble. While it properly sets the actor and conversant in the conversation, I can't reference their corresponding actor's fields in the database. It says that they return Nil.

    To clarify, if char1 is the actor, and char2 is the conversant, and in the conversation it reference's the actor's age stat in the actor database, it won't get any value. I could set it to get char1's stat specifically, but then the conversation only works for them, rather than dynamically.

    Is there anything I could be doing better here, or is there some step I am missing? Any suggestions would be greatly appreciated.

    As for the bug, it seems that when going to edit conversations after playtesting, or selecting a different database, I have to pick a different conversation first and then return to selecting the initial one, else it won't save any changes.


    EDIT: Also, as a side note, what is the proper way to use the "Set Variable" Playmaker action, when setting to an Actor variable? Since it acts as a dropdown menu, rather than an input field, I'm not sure if it would be a string, or a float (for the ID).

    EDIT2: After messing around for another hour, I think I may know the source of my problem. It seems that Variable["Actor"] can't call any fields at all. So I can't do anything like Variable["Actor"].Age, whereas I can do Actor["Char1"].Age. Is there a way to call the actor of the conversation in the Actor field rather than the Variable one?
     
    Last edited: Jun 2, 2014
  46. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi EvilAlfredo, sorry about chopping up your post; I'm grouping the edits so I can reply to each question in its own section.

    The Variable[] table is one-dimensional. That is, every variable (such as Variable["Actor"]) has only one value. Variable["Actor"].Age isn't valid. Variable["Actor"] and Variable["Conversant"] are string values. Variable["Actor"] contains the name of the actor in the current conversation, and Variable["Conversant"] contains the name of the conversant.

    As you've found, the Actor[] table is two-dimensional. Every entry, such as Actor["Char1"] has a number of fields such as Actor["Char1"].Age.

    Let's say you know the name of an actor ("Fred"), and you want to get his age. In the Dialogue System's Lua environment, this is stored in Actor["Fred"].Age, and this is what you'll use in the Dialogue Editor in Conditions and Script fields.

    In PlayMaker, you can use the Get Lua Field action. Select the Actor Table and manually enter "Fred" as the element and "Age" as the Field. In the example below, the result is stored in a float variable named "Freds Age".



    If you're in the middle of a conversation and you don't know ahead of time who the actor is, you can first get the value Variable["Actor"] by using the Get Variable action. In the example below, it's stored in a string variable named "Current Actor Name". Then you can provide the string variable's value to the Get Lua Field action.




    The Set Lua Field and Set Variable actions have a little gotcha. Lua is basically typeless. You can assign a number to Actor["Fred"].Age, and then you can turn around and assign a string to it. Of course, a string probably wouldn't make sense in context, but in Lua you can still do it if you want. The PlayMaker action will assign any/all values that you've specified. In the example below, to prevent the action from trying to assign a string or bool value, I set them to "None" by clicking the little button to the right of each one.



    If I had left Bool Value as false, Actor["Fred"].Age would have been assigned the value 99, and then it would have been assigned the value false.

    Similarly, remember to set the unused values to None in the Set Variable action. Also note that "Variable Name" for the Variable[] table is equivalent to "Element" for the Actor[] table. It's the value inside the square brackets. These values are typically called indices, since they provide an index into the table. The action below sets Variable["Another Variable"] to 42.



    One more gotcha. This one comes from the convention established by Chat Mapper, whose design I borrowed. (The Dialogue System started life as a way to import Chat Mapper projects into Unity.) In Lua, spaces (' ') and hyphens ('-') in indices are replaced by underscores ('_'). So in your Conditions and Script fields, you should use Variable["Another_Variable"]. (Note the underscore.)

    Sorry about the bug. It's been fixed. I didn't have time to get it into the v1.2.4 release, but it was the first thing I fixed in the upcoming v1.2.4.1 patch that I expect to release tomorrow.
     
  47. EvilAlfredo

    EvilAlfredo

    Joined:
    Aug 11, 2012
    Posts:
    7
    Wow. That was incredible support, thank you so much! I'm away from my work environment right now, but this should fix the problems I was having.
    I must say, this system is quite amazing, and has cut down the work I had to do on this project by half, at the very least. And it has pretty solid integration too, which is great to find on an asset like this. I will be certain to recommend this system to my peers!
     
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Happy to help! If you run into any snags when you get back to your work environment, don't hesitate to post or PM me directly!
     
  49. gooberoo

    gooberoo

    Joined:
    Jun 3, 2014
    Posts:
    2
    Hi! I've been using it and I love it but I'm having trouble with something that'd hopefully be an easy fix. I've been making the Dialogue UI however I'd like the Font Size to scale with the size of the screen. It's easy to do with the rest of it because of the "Normalized" functions, (thank you for those!) but I've been trying to do something similar with the font size to no avail.
     
  50. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi gooberoo, sorry, Unity GUI doesn't provide an easy way scale the font size. You have to set each GUI style's font size to a specific integer number. You can attach a script like the one below (ScaleFontSize.cs) to your GUI Root object. It detects screen height changes and adjusts the font size of the "label" style.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using PixelCrushers.DialogueSystem.UnityGUI;
    4.  
    5. public class ScaleFontSize : MonoBehaviour {
    6.  
    7.     public float scaleFactor = 0.04f;
    8.  
    9.     private GUIRoot guiRoot = null;
    10.     private float lastScreenHeight = 0f;
    11.  
    12.     void Awake() {
    13.         guiRoot = GetComponent<GUIRoot>();
    14.     }
    15.  
    16.     void OnGUI() {
    17.         if (guiRoot == null || guiRoot.guiSkin == null) return;
    18.         if (Screen.height == lastScreenHeight) return;
    19.         lastScreenHeight = Screen.height;
    20.         guiRoot.guiSkin.label.fontSize = (int) (scaleFactor * Screen.height);
    21.         guiRoot.ManualRefresh();
    22.     }
    23. }
    24.  
    You could expand this to fit your needs -- for example, expose an array of style names and their scaling factors instead of just the style named "label":
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using PixelCrushers.DialogueSystem.UnityGUI;
    4.  
    5. public class ScaleFontSize : MonoBehaviour {
    6.  
    7.     [System.Serializable]
    8.     public class StyleScale {
    9.         public string styleName = string.Empty;
    10.         public float scaleFactor = 0.04f;
    11.     }
    12.  
    13.     public StyleScale[] styles = new StyleScale[0];
    14.  
    15.     private GUIRoot guiRoot = null;
    16.     private float lastScreenHeight = 0f;
    17.  
    18.     void Awake() {
    19.         guiRoot = GetComponent<GUIRoot>();
    20.     }
    21.  
    22.     void OnGUI() {
    23.         if (guiRoot == null || guiRoot.guiSkin == null) return;
    24.         if (Screen.height == lastScreenHeight) return;
    25.         lastScreenHeight = Screen.height;
    26.         foreach (var style in styles) {
    27.             GUIStyle guiStyle = guiRoot.guiSkin.GetStyle(style.styleName);
    28.             if (guiStyle != null) {
    29.                 guiStyle.fontSize = (int) (style.scaleFactor * Screen.height);
    30.             }
    31.         }
    32.         guiRoot.ManualRefresh();
    33.     }
    34. }
    35.