Search Unity

TextMesh Pro Creating custom styles in runtime

Discussion in 'UGUI & TextMesh Pro' started by TJHeuvel-net, Jul 30, 2020.

  1. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    We have a glyph system with which we show keybinds, we do this by modifying the style templates in runtime to the current keybind and then rebuilding TMPro.

    However its currently impossible by default to edit the styles in runtime, they are read-only. We are forced to download the source of the package and modify it to remove the readonly attribute, when we do it all works.

    Is there anyway this could be officially supported?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What properties would you need to be R/W?
     
  3. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    I have just reapplied our patches to the latest package. It certainly isnt ideal as an API, but it works for us.

    I've made the constructor of TMP_Style public instead of internal, and added a method to TMP_StyleSheet to update the known styles. This basically sets _mStyleList and calls RefreshStyles.

    So we make our own list of TMP_Styles and call Refresh on the current stylesheet. We've had some issues with setting the style opening tag to some different string, and the underlying hashcode-cache not updating, but other than that this has worked pretty well.