12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 6990|回复: 11
打印 上一主题 下一主题

[教程] unity3d游戏本地化的研究,Localizing a Unity3D Game(二)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-12-15 14:06:50 |只看该作者 |倒序浏览
public class Localization { // ... public static string Translate(string id) { string key = id.ToLower(); // case insensitive id are used string lang = LocalizationManager.Instance().GetCurrentLanguage();   LoadTranslations(); // only loaded once int lang_index = FindLangIndex(lang);   if (lang_index == -1) { Debug.Log("Unknown translation language: " + lang); return id; }   string translation = (string)_translationData.content[lang_index][key];   if (translation == null) { Debug.Log("Missing translation for text id: "+id); return id; }   return translation; } // ... }

Localizing image assets is a greater challenge because they are often used automatically in unity3d and added to GameObjects using the component system. To localize these assets, we use components that can be “dragged-and-dropped” into the Prefabs or GameObject instances that uses these localized image assets to automatically choose the correct texture. The abstract class

LocalizedAsset

is used to perform this task.
public abstract class LocalizedAsset : MonoBehaviour { public Texture TranslateAsset(Texture initTexture) { Texture translatedTexture = null; if (initTexture != null) { translatedTexture = TranslateAsset(initTexture.name); } return translatedTexture; }   public Texture TranslateAsset(string assetName) { Texture translatedTexture = null; string langAssetName = StripLanguageExtension(assetName) + LocalizationManager.Instance().CurrentLanguageToExtension();   translatedTexture = (Texture)LocalizationManager.Instance().LoadAsset(langAssetName);   return translatedTexture; }   public abstract void LoadAssets();   public void Start() { LocalizedAssetsObserver.AddLocalizedAsset(this); LoadAssets(); } }

The

LoadAssets

method must be implemented by subclasses such that it will ensure that all the localized assets present in the current object will be correctly translated. The

TranslateAsset

methods can be used to get the translated textures easily. The

Start

implementation will then load all the localized assets of the object at***ntime for all the subclasses. The observer design pattern is used to register any localized assets in the aim of having the possibility to to reload them as needed when the language is changed at***ntime by the user. An example implementation of

LocalizedAsset

is provided below:
public class LocalizedMaterialAsset : LocalizedAsset { public override void LoadAssets() { // Assuming only 1 material is used... MeshRenderer renderer = (MeshRenderer)gameObject.GetComponent("MeshRenderer"); if (renderer != null && renderer.material.mainTexture != null) { renderer.material.mainTexture = TranslateAsset(renderer.material.mainTexture); } } }

Thus, adding the

LocalizedMaterialAsset

to any Prefab or GameObjects that have a certain material component will automatically translate the texture image used by that material. The

LocalizationManager

singleton instance is responsible for keeping track of the current localization state (current language, etc…) and uses the Unity3D

Resources

class to dynamically load localized assets:
public class LocalizationManager : MonoBehaviour { // ... public Object LoadAsset(string assetName) { return Resources.Load("Localization/"+_currentLanguage+"/"+assetName); } // ... }

Thus using a csv database and Unity3D components and dynamic resources enabled us to easily localize our game to multiple languages. I hope this can help other Unity3D community members to localize their game.
由 u8 发表
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

沙发
发表于 2012-1-21 23:18:31 |只看该作者
年年岁岁,岁岁年年,春去春来,转眼间又过了一年,小年到,祝福到,愿你在新的一年事业节节高,生活红火火,拜个早年,提前祝你新年好!
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-1-22 23:26:40 |只看该作者
年末感慨实在是多,三言两语道不完!最让我揪心的还是你,行李备好了没?火车票买了没?别感动,我只是问问,自己的事情还是要自己做滴!哈哈。
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-3-24 23:18:19 |只看该作者
心中有爱,爱咋咋地
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-4-18 23:24:11 |只看该作者
我看看就走,你们聊!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

6#
发表于 2012-7-23 23:20:25 |只看该作者
顶!学习了!阅!
回复

使用道具 举报

3795

主题

2

听众

5万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
53202
精华
32

活跃会员 优秀版主 推广达人 突出贡献 荣誉管理 论坛元老

7#
发表于 2012-7-24 09:32:24 |只看该作者
高手速来赐教!kismet里面怎么加一个延迟DELAY??



unity特效大家PP_武功盖世呀








【严重分享】Unity3D_3.0破解版[安装包][下载]






高手请赐教!用模型做的特效动画材质丢失








antares_universe(vizio)可视化编辑
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

8#
发表于 2013-2-23 23:20:38 |只看该作者
我就看看,我不说话
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2013-3-19 23:20:17 |只看该作者
很经典,很实用,学习了!
回复

使用道具 举报

nts    

3

主题

1

听众

743

积分

初级设计师

Rank: 3Rank: 3

纳金币
7
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2013-10-17 11:04:07 |只看该作者
本地化游戏是游戏必备
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-5 11:43 , Processed in 0.090519 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部