Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

New UI Widgets

Discussion in 'Assets and Asset Store' started by ilih, Feb 11, 2015.

  1. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    please explain Max Display Size and Default Display Size?
     
  2. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    @ilih
    Great work on this LayoutSwitcher update, its 90% working according to workflow earlier mentioned.
    However view doesnt update on some cases

    For example, i added 2 aspect ratios
    1- portrait 9:16 (iphone x)
    1- landscape (4:3)

    Now if i chose any portrait aspect ratio on runtime, which means value will be always less than 1 (width/height = 9/16 = 0.5625) so your code should see if there is any aspect ratio with portrait (less than 1). In my case there is only 1, portrait so it should show it, otherwise if aspect ratio is landscape (greater than 1) then it should fall back to landscape.

    Now imagine i have 2 landscape aspect ratios 4:3 = 1.33 and 16:9 = 1.7
    now if current aspect ratio divided value should be close one of these 2 values, if its closer to 16:9, set 16:9 if its closer to 4:3 (as 1.33) then set it to 4:3 settings.

    Thanks



    Update
    To explain further, limitation of last build is as i have 2 aspect ratios
    9:16 potriat, and 4:3 landscape
    then my potrait view (current scene) will only change its layout, if i precisely set 4:3 aspect ratio otherwise it will remain in portrait even if my current aspect ratio is 5:3, 3:2 etc
     
  3. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Default Display Size - Display size used when actual display size cannot be detected.
    Max Display Size - layout will be used if max size greater or equal to Display Size.
    All sizes in inches, actual display size calculated with Screen.dpi.
     
  4. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    This done with this code
    .OrderBy(x => Mathf.Abs(aspectRatio - x.AspectRatioFloat))
    to find closest aspect ratio.

    Then you can use such code:
    Code (CSharp):
    1.         UILayout SimpleSelector(List<UILayout> layouts, float displaySize, float aspectRatio)
    2.         {
    3.             // if aspect_ration 4:3
    4.             if (NearlyEqual(4f / 3f, aspectRatio, 0.001f))
    5.             {
    6.                 var layout_4_3_index = 0;
    7.                 return layouts[layout_4_3_index];
    8.             }
    9.  
    10.             var layout_9_16_index = 1;
    11.             return layouts[layout_9_16_index];
    12.         }
    13.  
    14.         public static bool NearlyEqual(float a, float b, float epsilon)
    15.         {
    16.             if (a == b)
    17.             {
    18.                 return true;
    19.             }
    20.  
    21.             var diff = Mathf.Abs(a - b);
    22.  
    23.             if (a == 0 || b == 0 || diff < float.Epsilon)
    24.             {
    25.                 return diff < (epsilon * float.Epsilon);
    26.             }
    27.  
    28.             var absA = Mathf.Abs(a);
    29.             var absB = Mathf.Abs(b);
    30.  
    31.             return diff / (absA + absB) < epsilon;
    32.         }
    33.  
     
    AmRafay1 likes this.
  5. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    Oh, so just to reconfirm, So layoutSelector callback can make the decision of what layout to use and LayoutSelector then display that layout which it gets from callback? right?
    thats even better :)
     
  6. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Yes.
     
    AmRafay1 likes this.
  7. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    @ilih,

    please add isOnWithoutEvent property so it doesnt dispatch onValueChange,

    Reason is i want to set default values and action handler gets trigger, one way is to explicitly ignore it adding code in all screens where im using them but adding this property in switch will make life easier.
     
  8. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    You can use
    Switch.SetStatus(bool isOn)
    function to change IsOn without event invocation.
     
    AmRafay1 likes this.
  9. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    @ilih, how can i do both SetStatus and disable switch animations (only when im calling SetStatus) to avoid this error


    Code (CSharp):
    1. Coroutine couldn't be started because the the game object 'PrefabSwitch' is inactive!
    2. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    3. UIWidgets.Switch:SetMarkPosition(Boolean) (at Assets/New UI Widgets/Scripts/Switch/Switch.cs:332)
    4. UIWidgets.Switch:SetStatus(Boolean) (at Assets/New UI Widgets/Scripts/Switch/Switch.cs:284)
     
  10. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    You need to modify SetStatus:
    • add "animate" argument to SetStatus method:
      public void SetStatus(bool value, bool animate = true)
    • and use it is SetMarkPosition call:
      SetMarkPosition(animate);
    Now you can use
    Switch.SetStatus(isOn, false)
    to set state without using animation.
     
    AmRafay1 likes this.
  11. AmRafay1

    AmRafay1

    Joined:
    Oct 22, 2013
    Posts:
    671
    Is there PickerString Example scene?
    Thanks
     
  12. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    No, but you can use PickerInt example ("Open Picker" button under the Miscellaneous tab in the main scene). The only difference is a type of the value.

    Code (CSharp):
    1.         [SerializeField]
    2.         protected PickerString PickerTemplate;
    3.  
    4.         string currentValue = string.Empty;
    5.  
    6.         public void Test()
    7.         {
    8.             // create picker from template
    9.             var picker = PickerTemplate.Clone();
    10.  
    11.             // set values from template
    12.             picker.ListView.DataSource = PickerTemplate.ListView.DataSource.ToObservableList();
    13.  
    14.             // show picker
    15.             picker.Show(currentValue, ValueSelected, Canceled);
    16.         }
    17.  
    18.         void ValueSelected(string value)
    19.         {
    20.             currentValue = value;
    21.             Debug.Log("value: " + value);
    22.         }
    23.  
    24.         void Canceled()
    25.         {
    26.             Debug.Log("canceled");
    27.         }
     
    Last edited: Dec 11, 2018
    AmRafay1 likes this.
  13. Yerkisk

    Yerkisk

    Joined:
    Jul 28, 2015
    Posts:
    3
    The Popup script doesn't seem to support TextMeshPro. The Text fields for the header and content text only accept normal Text fields and not TextMeshPro texts like the other components do. Dialog seems to work, just Popup that doesn't.
     
  14. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    The Popup gameobject have DialogInfoTMPro component, this component contains references to Header and Text gameobjects and used to display header and content text. (You do not need to use it directly, it will be used automatically if it added to Popup gameobject)
    It should exist by default if you created Popup correctly (TextMesh Pro support enabled and Popup created with menu "UI/UIWidgets with TextMesh Pro/Dialogs/Popup")
     
    Last edited: Dec 12, 2018 at 12:12 AM
  15. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    46
    Unless I missed something, the Spinner is not using TextMesh Pro.
    It works with Tabs and ListView, but not Spinner which is still using the standard Unity Text.

    I tried both Spinners using the latest New UIWidgets version.
     
  16. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Yes. Spinner is class inherited from InputField class and it was impossible to make it work with TextMesh Pro, so I am reworking Spinner right now to add TextMesh Pro support (Inheritance already removed in the last beta).
     
  17. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    46
    Nice!
    Thanks for your work.
     
  18. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Please check v1.10.2b9 with updated Spinner with TextMesh Pro support.
    After the update, you will need to import the TMPro support package with "Edit / Project Settings / New UI Widgets / Import TextMesh Pro support package"
     
    Last edited: Dec 13, 2018 at 8:31 PM
  19. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,144
    Really needs an update to properly support TMP everywhere in the package/demos/prefabs and scripts... like TMP is officially in unity as a package now.. <Text> might aswel be dead it's old and not all that great especially with TMP supporting dynamic fonts now (2018.3 onwards)

    and its not something I want to go through updating scripts for the package when an update will overwrite them.. just gets messy, please update
     
  20. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Please, can you be more specific about the problem with TextMesh Pro?
    TextMesh Pro is supported: separate prefabs and scripts with TMP support are included in the package (and with the latest beta update it's available for all widgets with text). For now no demos with TMP and not sure if it's really needed - the only difference will be in the scene, scripts do not require any changes.
     
  21. Yerkisk

    Yerkisk

    Joined:
    Jul 28, 2015
    Posts:
    3
    Concerning the popup, if you create a new popup with TMPro support enabled, the Title Text and Content Text of the popup script are empty as they are old Text component and not TMPro Text components so you cannot reassign them unless you rewrite the class. Even if the dialog info has TMPro support, if you do a popup.show with a title and message, they are not showing.

    Wrote a new class to change this, updated all text component of popup to textmesh pro and then it works.
     
  22. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    Strange, I just checked it and it's work without a problem. And recorded video of the test.
    Maybe font is missing but should be errors about it.

    What Unity version are you use?
     
  23. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    46
    Thanks!
    Just tried it, and it works perfectly.

    I have a minor problem with the tooltips, I have set its text to justified, and as long as it is not displayed it stays justified.
    But when it is displayed it automatically changes to a left alignement.
    Changing the size of the font works fine, but not the alignement.
     
  24. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    RectTransform anchors of the text gameobject are controlled by Horizontal Layout group.
    Tooltip itself does not control Text alignment, maybe you have some other script that changes alignment - try to create a new empty scene with a single button and Tooltip and check alignment with it.
     
  25. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,144
    yeah nvm it seems I had used a scene prefab (actually are the demo scenes all using the old the old text version?) anyway noticed the script for them was just hardcoded with Text, but on looking at the TMP version prefabs you use another additional script on some of the components to update for TMP.. so wasn't much problem adding that addition
     
  26. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    There are few problems with using TextMesh Pro by default and completely discard Text:
    • 3 different versions of the TextMesh Pro: paid AssetStore version (not available now, but still used), free AssetStore version, free built-in package version, they all use different GUID so scenes and prefabs with TMPro not compatible between different versions, unless you use tools like "Project file GUID remapping tool" to convert scenes and prefabs to required version which is not the best solution for paid assets.
    • AssetStore approve process: in the case of the built-in package you still need to import fonts and other resources without it, you will get missing references errors. Same applied to the automated tests to check submitted asset package, and the package will be rejected because of the missing references errors. (I do not know how exactly approve process work, but pretty sure it matches with my description)
    • The built-in package itself can be uninstalled: so after import will be not only missing references errors but also code errors.
    • Built-in packages are available only in the Unity 2017.3 (or 2017.4?) and later versions. But dropping support of the previous Unity versions is not an option.
    I am thinking about the possible solution: replace Text in example scripts with some proxy script and add a tool to replace Text components with TMPro in the scene automatically.
     
    hopeful likes this.
  27. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    46
    Anybody serious about using TMP knows about the issues coming from the 3 different versions of TMP, so I'm not sure it's really a problem.
    As for the lack of TMP in the new UI Widgets examples, it's not a real problem either because we can still open another Unity with the examples in order to see how it's done, while still be working on our own project on another Unity.

    I expect that New UI Widgets will sometimes go for TMP as primary text solution in some time.
    But for now it's clear that most people are still using the standard Text component, so I'm ok with this asset using Text by default, even if I am not using Text anymore.


    That said, I saw that when using "Edit / Project Settings / New UI Widgets / Import TextMesh Pro support package", the source files in 'Third party' are modified with a comment at the end.
    I understand it is to force the recompile of the project, but it's also messing with source control which is a real problem.
    Maybe it is possible to do either (or both):
    - modify only one file (if one source file is modified in a dll, then the dll will be completely rebuilt, so there's no need to modify more than one file). It would mess a bit less with the source control
    - add some text to one of the source files (as currently), save, and then remove it and re-save. It should have the same effect as the file will be considered as having been modified, but at least it won't mess at all with source control
     
  28. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    583
    It is a problem with Unity 2018.1 and 2018.2 only: unless file itself changed it's can not be used as a MonoBehavior component, and when selecting a file you see a message "No MonoBehaviour scripts in the file, or their names do not match the file name.".
    Modify only one file fix problem for this file only.
    I submitted it as a bug, but receive no response.

    Possible solutions:
    • Try Unity 2018.3. I do not check stable version yet, but the beta does not have this problem
    • Comment line "Compatibility.ForceRecompileByLabel("TMProFolder");" in file ThirdPartySupportMenuOptions.cs and check how it works
    • Use this script to remove added text in the source files

    After first save should be called
    AssetDatabase.Refresh()
    to recompile file, it cannot be done after re-save because the file will be same and recompile not happen.
    I suspect there is a chance that after
    AssetDatabase.Refresh()
    code execution will be stopped because of recompilation, but I'll still check it.
     
  29. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    46

    Thanks, as always your answers are fast and efficient, continue the good work!