Coder Social home page Coder Social logo

moxiewhimsy / fancytextrendering Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jimmycushnie/fancytextrendering

0.0 0.0 0.0 1.64 MB

Render markdown & clickable links with TextMeshPro in Unity.

License: Do What The F*ck You Want To Public License

C# 74.71% HLSL 11.39% ShaderLab 13.90%

fancytextrendering's Introduction

FancyTextRendering

Render markdown & clickable links with TextMeshPro in Unity.

demo.png

inspector example.png

Try it yourself -- check out the live demo!

What is this?

Unity's advanced text rendering library, TextMeshPro, supports using rich text tags to format the text. While rich text tags are powerful, they are an absolute pain in the ass to use. FancyTextRendering offers convenient conversion from markdown to TMP Rich Text, which makes it much easier to write styled text in Unity.

Markdown source Converted to rich text Looks like
Text can be *italic*, or **bold**, or even ***both!*** Text can be <i>italic</i>, or <b>bold</b>, or even <i><b>both!</b></i> Text can be italic, or bold, or even both!

Additionally, while TMP contains a link tag, this only provides metadata; TMP lacks any functions to make links actually clickable with an action that occurs when you click them. FancyTextRendering contains modules for rendering links properly: they are given a separate color from the rest of the text, then a second color when the cursor hovers over them, and a third color when the mouse button is held down on them. When the mouse button is released, the links can now execute arbitrary code, such as opening a URL in a browser.

Also, it's pretty darn fast, with minimal GC. On my machine it parses a 12,000 word markdown document in under 100ms.

Project context

FancyTextRendering was written for our game Logic World. It is primarily for our in-game chat, but it's also used for displaying various pages of information like the in-game changelog.

FancyTextRendering is part of LogicUI, the custom UI library we're writing for Logic World. The entire LogicUI library will be open sourced at some point; FancyTextRendering is just the first module to be released from it.

Disclaimer

If you use this you should keep in mind that I don't actually know what the hell I'm doing. There are probably established coding conventions for how you're supposed to write a markdown parser, but I didn't look them up because I wanted the personal challenge of puzzling out how to do it myself. As such, there are many parts of markdown spec that are missing, and there are several bugs with the parser.

If you have a bug report or feature request, please put it on the issues page. And if you'd like to help out with development, I am absolutely accepting pull requests, so please go ahead and make one :D

How to use

Rendering markdown:

  1. Create a standard TextMeshPro GameObject
  2. Add the MarkdownRenderer component
  3. Type markdown in the MarkdownRenderer's Source textbox
  4. Adjust the MarkdownRenderer's Render Settings properties to preference

Rendering links:

  1. Start with a TextMeshPro GameObject (it can be the one used in the steps above)
  2. Give the text some links, either directly using TMP's <link> tag or by using a MarkdownRenderer
  3. Add the TextLinkHelper component
  4. Adjust link color properties to preference
  5. Optional: add the SimpleLinkBehavior component to make the links actually do something when you click on them

Dependencies

Both of these libraries are pre-installed if you simply clone the project, but you will need to add them yourself if you want to use FancyTextRendering in another project.

fancytextrendering's People

Contributors

jimmycushnie avatar rafaelribeiro1510 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.