Unity3d游戏中实现阿拉伯语文字正常显示
https://www.cnblogs.com/MrLidx/p/8436089.html
Unity3d游戏中实现阿拉伯语文字正常显示
Unity3d游戏中实现阿拉伯语文字正常显示
由于项目需求要把游戏文字显示为维语版本(维语属于阿拉伯语系),我先把维语替换进去,之后发现文字是错的(每个字符都分开了,而且显示方向也不对)后来在网上查了一下发现阿拉伯语是从右往左读的,并且阿拉伯语的32个字符单说写法就有126种(同一个字符有多种写法)如下图:
部分维语字符的不同书写形式
首先我们来了解一下维语:
① 维文是以阿拉伯字母为基层的因素文字,由32个字母构成。分为元音、辅音两大类。
② 8个元音又分三类;3个前元音、3个后元音、2个央元音。 每个词的元音要么都是前元音,要么都是后元音。这8个元音中有4个同汉语元音等值完全相同,有4个相差较大。
③ 24个辅音又分为两类;分别为:10个清音、14个浊音。这24个辅音中有20个同汉语声母辅音等值完全相同,有4个相差较大。
④ 注有“新维文”字样的框格,代表发音相差较大。
书写规则:
【单立式】(又称独立式、独写体)用于词末尾单独构成一个音节时。
【后连式】(又称连首体)用于词首或音节首。
【双连式】(又称前后连式、中连式、连中体)用于两种书写形式的辅音字母之外的其余辅音字母的中间。
【隔音双连式】(又称隔音前后连式)用于词中的音节首。
【前连式】(又称连尾体)用于词末尾与前面的字母相连。
【隔音前连式】用于词末尾与前面的字母连写单独构成一个音节。
【简单单立式】用于词末尾而且是两种书写形式的辅音字母之后。
【简单后连式】用于词中间而且是两种书写形式的辅音字母之后。
上面这都是在网上看到的怎么感觉有点像我们小时候学习 a o e 一样了呢,哈哈.. 不得不说,真的看不懂!
其实看到这些字符我是一脸懵逼,不是龙舟就是战舰的,最主要的是不认识。
最开始我是在网上找了个插件(如果在看到我这篇博客之前你查过阿拉伯语的显示问题,你一定也在GitHub上看到过ArabicSupport这个插件吧),它不过也就是把文字显示方向可以修改过来,但是里边还是存在很多问题的,后来修改了他的源码,这才把项目里的阿拉伯语正常显示出来!当你仔细看他demo源码的时候就会发现,他的做法是把一句话的每个字符分别存到两个数组里,然后用Unicode编码进行比对、替换。打开一个阿拉伯语字体你会看到每一个字符都会有它对应的Unicode编码。如下图:
图一 图二
图二中一套字体里为什么会有长得一样的字符呢?点开一个字符,然后左下角你会发现对应的Unicode编码是不同的,并且一个是独立形式,另一个是非独立形式。然而那些错误的字符就是因为使用的非独立形式,才导致再次变形的时候出现错误,我们要做的就是要把这些读取出来的非独立形式转换为独立形式,做好映射!
然后在GitHub那个Demo的源码中我们看到他里面提供了几个接口,分别是判断当前字符要使用前连书体、后边书体、还是前后连书体或独立书体,修改代码如下:
1 /// <summary>2 /// Checks if the letter at index value is a leading character in Arabic or not.3 /// </summary>4 /// <param name="letters">The whole word that contains the character to be checked</param>5 /// <param name="index">The index of the character to be checked</param>6 /// <returns>True if the character at index is a leading character, else, returns false</returns>7 internal static bool IsLeadingLetter(char[] letters, int index)8 {9 10 bool lettersThatCannotBeBeforeALeadingLetter = index == 0 11 || letters[index - 1] == ' ' 12 || letters[index - 1] == '*' // ??? Remove?13 || letters[index - 1] == 'A' // ??? Remove?14 || char.IsPunctuation(letters[index - 1])15 || char.IsNumber(letters[index - 1])16 || letters[index - 1] == '>' 17 || letters[index - 1] == '<' 18 || letters[index - 1] == (int)IsolatedArabicLetters.Alef19 || letters[index - 1] == (int)IsolatedArabicLetters.Dal 20 || letters[index - 1] == (int)IsolatedArabicLetters.Thal21 || letters[index - 1] == (int)IsolatedArabicLetters.Ra2 22 || letters[index - 1] == (int)IsolatedArabicLetters.Zeen 23 || letters[index - 1] == (int)IsolatedArabicLetters.PersianZe24 //|| letters[index - 1] == (int)IsolatedArabicLetters.AlefMaksora 25 || letters[index - 1] == (int)IsolatedArabicLetters.Waw26 || letters[index - 1] == (int)IsolatedArabicLetters.AlefMad 27 || letters[index - 1] == (int)IsolatedArabicLetters.AlefHamza28 || letters[index - 1] == (int)IsolatedArabicLetters.AlefMaksoor 29 || letters[index - 1] == (int)IsolatedArabicLetters.WawHamza30 || letters[index - 1] == (int)IsolatedArabicLetters.Ae31 || letters[index - 1] == (int)IsolatedArabicLetters.U32 || letters[index - 1] == (int)IsolatedArabicLetters.Yu33 || letters[index - 1] == (int)IsolatedArabicLetters.Oe34 || letters[index - 1] == (int)IsolatedArabicLetters.Ve;35 36 bool lettersThatCannotBeALeadingLetter = letters[index] != ' ' 37 && letters[index] != (int)IsolatedArabicLetters.Dal38 && letters[index] != (int)IsolatedArabicLetters.Thal39 && letters[index] != (int)IsolatedArabicLetters.Ra2 40 && letters[index] != (int)IsolatedArabicLetters.Zeen 41 && letters[index] != (int)IsolatedArabicLetters.PersianZe42 && letters[index] != (int)IsolatedArabicLetters.Alef 43 && letters[index] != (int)IsolatedArabicLetters.AlefHamza44 && letters[index] != (int)IsolatedArabicLetters.AlefMaksoor45 && letters[index] != (int)IsolatedArabicLetters.AlefMad46 && letters[index] != (int)IsolatedArabicLetters.WawHamza47 && letters[index] != (int)IsolatedArabicLetters.Waw48 && letters[index] != (int)IsolatedArabicLetters.Hamza49 && letters[index] != (int)IsolatedArabicLetters.Ae50 && letters[index] != (int)IsolatedArabicLetters.U51 && letters[index] != (int)IsolatedArabicLetters.Yu52 && letters[index] != (int)IsolatedArabicLetters.Oe53 && letters[index] != (int)IsolatedArabicLetters.Ve;54 55 bool lettersThatCannotBeAfterLeadingLetter = index < letters.Length - 1 56 && letters[index + 1] != ' '57 && !char.IsPunctuation(letters[index + 1] )58 && !char.IsNumber(letters[index + 1])59 && !char.IsSymbol(letters[index + 1])60 && !char.IsLower(letters[index + 1])61 && !char.IsUpper(letters[index + 1])62 && letters[index + 1] != (int)IsolatedArabicLetters.Hamza;63 64 if(lettersThatCannotBeBeforeALeadingLetter && lettersThatCannotBeALeadingLetter && lettersThatCannotBeAfterLeadingLetter)65 {66 return true;67 }68 else69 return false;70 }71 72 /// <summary>73 /// Checks if the letter at index value is a finishing character in Arabic or not.74 /// </summary>75 /// <param name="letters">The whole word that contains the character to be checked</param>76 /// <param name="index">The index of the character to be checked</param>77 /// <returns>True if the character at index is a finishing character, else, returns false</returns>78 internal static bool IsFinishingLetter(char[] letters, int index)79 {80 bool indexZero = index != 0;81 bool lettersThatCannotBeBeforeAFinishingLetter = (index == 0) ? false : 82 letters[index - 1] != ' '83 && letters[index - 1] != (int)IsolatedArabicLetters.Dal 84 && letters[index - 1] != (int)IsolatedArabicLetters.Thal85 && letters[index - 1] != (int)IsolatedArabicLetters.Ra2 86 && letters[index - 1] != (int)IsolatedArabicLetters.Zeen 87 && letters[index - 1] != (int)IsolatedArabicLetters.PersianZe88 //&& letters[index - 1] != (int)IsolatedArabicLetters.AlefMaksora 89 && letters[index - 1] != (int)IsolatedArabicLetters.Waw90 && letters[index - 1] != (int)IsolatedArabicLetters.Alef 91 && letters[index - 1] != (int)IsolatedArabicLetters.AlefMad92 && letters[index - 1] != (int)IsolatedArabicLetters.AlefHamza 93 && letters[index - 1] != (int)IsolatedArabicLetters.AlefMaksoor94 && letters[index - 1] != (int)IsolatedArabicLetters.WawHamza 95 && letters[index - 1] != (int)IsolatedArabicLetters.Hamza96 && letters[index - 1] != (int)IsolatedArabicLetters.Ae97 && letters[index - 1] != (int)IsolatedArabicLetters.U98 && letters[index - 1] != (int)IsolatedArabicLetters.Yu99 && letters[index - 1] != (int)IsolatedArabicLetters.Oe 100 && letters[index - 1] != (int)IsolatedArabicLetters.Ve 101 102 103 && !char.IsNumber(letters[index - 1]) 104 && !char.IsPunctuation(letters[index - 1]) 105 && letters[index - 1] != '>' 106 && letters[index - 1] != '<'; 107 108 109 bool lettersThatCannotBeFinishingLetters = letters[index] != ' ' && letters[index] != (int)IsolatedArabicLetters.Hamza; 110 111 112 113 114 if(lettersThatCannotBeBeforeAFinishingLetter && lettersThatCannotBeFinishingLetters) 115 { 116 return true; 117 } 118 else 119 return false; 120 } 121 122 /// <summary> 123 /// Checks if the letter at index value is a middle character in Arabic or not. 124 /// </summary> 125 /// <param name="letters">The whole word that contains the character to be checked</param> 126 /// <param name="index">The index of the character to be checked</param> 127 /// <returns>True if the character at index is a middle character, else, returns false</returns> 128 internal static bool IsMiddleLetter(char[] letters, int index) 129 { 130 bool lettersThatCannotBeMiddleLetters = (index == 0) ? false : 131 letters[index] != (int)IsolatedArabicLetters.Alef 132 && letters[index] != (int)IsolatedArabicLetters.Dal 133 && letters[index] != (int)IsolatedArabicLetters.Thal 134 && letters[index] != (int)IsolatedArabicLetters.Ra2 135 && letters[index] != (int)IsolatedArabicLetters.Zeen 136 && letters[index] != (int)IsolatedArabicLetters.PersianZe 137 //&& letters[index] != (int)IsolatedArabicLetters.AlefMaksora 138 && letters[index] != (int)IsolatedArabicLetters.Waw 139 && letters[index] != (int)IsolatedArabicLetters.AlefMad 140 && letters[index] != (int)IsolatedArabicLetters.AlefHamza 141 && letters[index] != (int)IsolatedArabicLetters.AlefMaksoor 142 && letters[index] != (int)IsolatedArabicLetters.WawHamza 143 && letters[index] != (int)IsolatedArabicLetters.Hamza 144 && letters[index] != (int)IsolatedArabicLetters.Ae 145 && letters[index] != (int)IsolatedArabicLetters.U 146 && letters[index] != (int)IsolatedArabicLetters.Yu 147 && letters[index] != (int)IsolatedArabicLetters.Oe 148 && letters[index] != (int)IsolatedArabicLetters.Ve; 149 150 bool lettersThatCannotBeBeforeMiddleCharacters = (index == 0) ? false : 151 letters[index - 1] != (int)IsolatedArabicLetters.Alef 152 && letters[index - 1] != (int)IsolatedArabicLetters.Dal 153 && letters[index - 1] != (int)IsolatedArabicLetters.Thal 154 && letters[index - 1] != (int)IsolatedArabicLetters.Ra2 155 && letters[index - 1] != (int)IsolatedArabicLetters.Zeen 156 && letters[index - 1] != (int)IsolatedArabicLetters.PersianZe 157 //&& letters[index - 1] != (int)IsolatedArabicLetters.AlefMaksora 158 && letters[index - 1] != (int)IsolatedArabicLetters.Waw 159 && letters[index - 1] != (int)IsolatedArabicLetters.AlefMad 160 && letters[index - 1] != (int)IsolatedArabicLetters.AlefHamza 161 && letters[index - 1] != (int)IsolatedArabicLetters.AlefMaksoor 162 && letters[index - 1] != (int)IsolatedArabicLetters.WawHamza 163 && letters[index - 1] != (int)IsolatedArabicLetters.Hamza 164 && letters[index - 1] != (int)IsolatedArabicLetters.Ae 165 && letters[index - 1] != (int)IsolatedArabicLetters.U 166 && letters[index - 1] != (int)IsolatedArabicLetters.Yu 167 && letters[index - 1] != (int)IsolatedArabicLetters.Oe 168 && letters[index - 1] != (int)IsolatedArabicLetters.Ve 169 && !char.IsNumber(letters[index - 1]) 170 && !char.IsPunctuation(letters[index - 1]) 171 && letters[index - 1] != '>' 172 && letters[index - 1] != '<' 173 && letters[index - 1] != ' ' 174 && letters[index - 1] != '*'; 175 176 bool lettersThatCannotBeAfterMiddleCharacters = (index >= letters.Length - 1) ? false : 177 letters[index + 1] != ' ' 178 && letters[index + 1] != '\r' 179 && letters[index + 1] != (int)IsolatedArabicLetters.Hamza 180 && !char.IsNumber(letters[index + 1]) 181 && !char.IsSymbol(letters[index + 1]) 182 && !char.IsPunctuation(letters[index + 1]); 183 if(lettersThatCannotBeAfterMiddleCharacters && lettersThatCannotBeBeforeMiddleCharacters && lettersThatCannotBeMiddleLetters) 184 { 185 try 186 { 187 if (char.IsPunctuation(letters[index + 1])) 188 return false; 189 else 190 return true; 191 } 192 catch 193 { 194 return false; 195 } 196 //return true; 197 } 198 else 199 return false; 200 }
对照维语的Unicode编码总结出:
①独立形式Unicode编码的基础之上加1就是前连书体
②独立形式Unicode编码的基础之上加2就是后连书体
③独立形式Unicode编码的基础之上加3就是前后连书体
前面做好映射,有了上面这三个方法就能正常显示字符的书写形式了!(主要就是前连、后连、前后连这几种书写形体,其他形体不再多说)
看一下效果图:(文字看起来是不是舒服一些)
登录效果图
此篇文章经过自己归纳总结整理出来,仅供参考,如果大家有什么好的修改方式,或是好的意见或建议欢迎留言、交流,一起探讨!
Unity3d游戏中实现阿拉伯语文字正常显示相关推荐
- Unity3d 游戏中集成Firebase 统计和Admob广告最新中文教程
之前写过俩相关的教程,最近发现插件官方更新了不少内容,所以也更新一篇Firebase Admob Unity3d插件的教程,希望能帮到大家. Firebase Admob Unity3d插件是一个Un ...
- Unity3D游戏中隐藏鼠标光标
在游戏中隐藏鼠标光标,之前的方法Screeen.showCursor=false;已经被弃用了,目前的方法是Cursor.visible = false;
- android 阿拉伯语文字方向,android – 如何将RTL文本(阿拉伯语)绘制到位图并正确排序?...
我正在尝试将阿拉伯文字绘制到位图上以供显示: Bitmap img = Bitmap.createBitmap( (int) f+100, 300, Config.RGB_565); Canvas c ...
- [Unity3D] Unity3D游戏开发之UGUI实现伤害数值显示
UGUI实现伤害数值显示的原理是在人物头顶放置空物体,然后将下面的脚本挂在空物体上,将该空物体制作为预制体: using UnityEngine; using System.Collections;p ...
- 实现游戏中的轮廓描边
Unity3D教程:实现游戏中的轮廓描边.Unity3D游戏中常用到轮廓描边,效果就是对轮廓描边后再进行模糊处理.有两种思路可以实现: 一.在RTT中绘制单一像素,对1绘制后的RTT进行blur处理惩 ...
- Unity3D游戏开发之回合制游戏原型的实现
http://blog.csdn.net/qinyuanpei/article/details/28125171 大家好,欢迎大家关注我的博客,我是秦元培,我的博客地址是blog.csdn.net/q ...
- Unity3D 2D游戏中寻径算法的一些解决思路
需求 unity3d的3d开发环境中,原生自带了Navigation的组件,可以很便捷快速的实现寻路功能.但是在原生的2d中并没有相同的功能. 现在国内很多手机游戏都有自动寻路的功能,或者游戏中存在一 ...
- 一、创建Assetbundle 在unity3d开发的游戏中,无论模型,音频,还是图片等,我们都做成Prefab,然后打包成Assetbundle,方便我们后面的使用,来达到资源的更新。
一.创建Assetbundle 在unity3d开发的游戏中,无论模型,音频,还是图片等,我们都做成Prefab,然后打包成Assetbundle,方便我们后面的使用,来达到资源的更新. 一个Asse ...
- unity3d api 中文文档_unity3D游戏开发工程师完整简历范文
基本信息 姓名:七分简历 年龄:23岁 电话:131****7089 邮箱:689262****@qq.com 经验:1年 意向:unity3D游戏开发工程师 教育背景 时间:2011-09 - 20 ...
最新文章
- 【Unity】11.5 物理材质 (Physics Material)
- java学习笔记(二) ----基本数据类型应用
- 多环境下读取不同的配置文件
- Linux 小知识翻译 - 「单CD 的linux」
- Spring5的AOP 和设备支持
- spark和hadoop升级记录(持续更新中)
- 论文阅读:SSD: Single Shot MultiBox Detector
- android编程文献,郭宏志. Android应用开发详解[M]. 2011.
- 一个简单混合协议通讯列子,物联网和互联网通讯。
- mongodb 导出一条数据_将 MongoDB 导出成 csv
- 想要导航提示页_如何优化网站导航呢?
- vuex中store存储store.commit和store.dispatch的区别及用法
- Java解析魔兽争霸3录像W3G文件(四):解析游戏进行时的信息
- matlab 声纹识别,识别模型论文,关于基于MATLAB的声纹识别系统软件的设计相关参考文献资料-免费论文范文...
- PPT怎么切换不同的母版
- OpenCV-绘制圆角矩形
- java 四边形_java求教,编写一个四边形的类与子类
- 领英改版变成领英中国的解决办法,完整详细版教程,亲测可用。
- 科研试剂Norbornene-5-TAMRA,降冰片烯-5-羧基四甲基罗丹明
- dry的原理_Dry Etch 工艺基本原理及良率剖析(经典讲解)