[Free] UPersian - RTL Support for Unity

UPersian: Unity Game Engine RTL Support

This project used ArabicSupprt for Unity Asset.

Features:
Supports Arabic and Persian for now.

New GUI Items(Creation MenuItem > UPersian > ):

  • RTL Text
  • RTL Inputfield
  • RTL Buton
  • RTL Checkbox

Runtime RTL Input Field

Supports BestFit:

RightClick Contex Menu:

String Extentions:

  • string RtlFix(): fixes original rtl strings to show in unity GUI. (ie. string hello = “سلام”.RtlFix(); )
  • bool IsRtl: returns whether string is rtl or not. (ie.bool checkRtl = “سلام”.IsRtl(); )

How to use:

  • Import latest unitypackage into your project.
  • Right click in hierarchy panel > UPersian > Rtl Text
  • Select RtlText in hierarchy and change text inside inspector, everything should show correct in GUI.

ChangeLog:

  • Fix best fit for Unity 5.4.3f1

Download: Here

10 Likes

Awesome.
Its a nice package for Persian Writing.
Thank you.

Thanks for this awesome package.

I’ve had a problem with this package and other RTL packages. The problem is in selecting text in input field, When I select text and want to clear that part, the opposite part of the text is cleared.

Any suggestion to fix this problem ?

you’re welcome :slight_smile: glad you find it useful.

you’re welcome and as I answered in GitHub, I have no suggestion for this yet!

Great stuff.
Can this also work with NGUI or any way to make compatible with NGUI?

Best_Regards,
Play_edu

thanks bro
واقعا ممنون بابت ساخت این پلاگین فوق العاده و کاربردی

Thanks to you and Abdullah. Very useful asset!

Hello,

Thank you for your great asset! The only issue I find with it is that it cannot handle word/line wrapping in TextMeshPro, so if there is Arabic that extends multiple lines within a text field, then the beginning of the Arabic appears on the bottom not the top.

In the example below, the phrase
أهلا و سهلا و مرحبا بكم
كيف حالكم اليوم يا أحبابي
has a line break after the word بكم and it appears on 4 lines within the text field.

The correct rendering of the text should be:
أهلا و سهلا و مرحبا
بكم
كيف حالكم اليوم يا
أحبابي

but it appears like this in the game view:
و سهلا و مرحبا بكم
أهلا
حالكم اليوم يا أحبابي
كيف

Please see attached screenshots. Any workaround? Are there plans to address this issue in the near future? Thanks!

خیلی عالیه!آفرین!
با سپاس فراوان.

Hi,

Can you make UI elements also Bidirectionality?

SorryI did not received any notification on this thread so if you still have problems with TexMeshPro I highly recommend you to check this asset.

:shamrock:

I did not understand this, can you please explain more?

can some one help me writing urdu in Unity ?

As most developers are switching to TextMeshPro, these solutions may not get updated as fast as you need.
There is an opensource solution for using RTL in TMPro here.
you may get faster results requsting these features there.
and if you insist on using old Text solution, my own repository uses this repo so you can request there

سلام
پکیج بسیار فوقالعاده ایه خسته نباشید
تنها یک مشکلی باهاش دارم و اون اینکه در فونتهای بسیاری حرف " ی " در میانه کلمه به درستی نمایش داده نمیشه ایا راهکاری برای این مساله وجود داره یا خیر
شاد باشید

Hi dear Hamid,
As I said before:

So I highly suggest you to use TextMeshPro. This repository may not receive any more updates.

Thank you so much.
I will download the Text mesh pro solution, I hope that fix the issue
have nice day.

Thank you so much for your help! I was looking for the fix of “ی” character. Your code works flawlessly:

    public static string FixPersian(string str, bool showTashkeel, bool useHinduNumbers) {
      str = str.Replace((char)0x6CC, (char)0x64A);
      str = Fix(str, showTashkeel, useHinduNumbers);
      str = str.Replace((char)0x64A, (char)0x649);
      str = str.Replace((char)0xFEF2, (char)0xFEF0);
      return str;
    }


p.s. it did not let me enter Arabic characters in the message, so I had to add it as an image.

Hi Andrew,
This solution does not work with rich texts or tags. I use RTLTextMeshPro solution myself. it supports rich texts, tags and provides better visual quality as it works with TextMeshPro.
So because of this better solution, my repository will not be updated. hope that one covers your need and if not, you can create an issue on github and its developers are kind enough to support you.

1 Like

Thank you @od3098 once again for sharing your work with all of us. I will definably give it a try. It was a mistake to create app using simple Text component and when I imagine how much time and testing it will take to move to TextMeshPro, I am telling myself that it’s working “fine” with Text as well =)

I just got report that there is one more Persian letter which we do not handle properly - “heh docheshm”. I did some research and seems like in Persian there are situation when it should not be connected to next character (like in word “silver”) or if they are two at once (“fruits”, “stores”). Luckly for us, there is a hidden character called “zero width non-joiner”. Here is updated solution:

    public static string FixPersian(string str, bool showTashkeel, bool useHinduNumbers) {
        string hehWithZeroWidthJoiner = new string(new char[] { (char)0x647, (char)0x200C });
        string hehInIsolatedFormheh = ((char)0xFEE9).ToString();
        string tempPlaceHolder = "%%%%%%%%%";

        str = str.Replace(hehWithZeroWidthJoiner, tempPlaceHolder);
        str = str.Replace((char)0x6CC, (char)0x64A);
        str = Fix(str, showTashkeel, useHinduNumbers);
        str = str.Replace((char)0x64A, (char)0x649);
        str = str.Replace((char)0xFEF2, (char)0xFEF0);
        str = str.Replace(tempPlaceHolder, hehInIsolatedFormheh);
    
        return str;
    }

p.s. I just hope that zero width non-joiner cannot be used with other letters. In such cases, we will need regexp. I am waiting for confirmation from natives.