Been surfing around the forums a while but haven’t gotten much wiser. I have several showstopper issues I need to resolve before I can start developing the actual game play. I was hoping someone out there has the knowledge and time to help me. This project has a very tight schedule so any help would be greatly appreciated. And from surfing around the forums many developers have the same problems. Hopefully this thread can serve as a guide for others too.
The game will be localized into four different (Scandinavian) languages. It will be for both Mac and PC. What I would like is that the user will chose their language when running the installer. The installer will then pick the matching language pack containing both speech and text. The installer will also contain the files that differ from PC and Mac and install the correct ones depending on the users platform.
Unicode
When ever a the game path, file, folder, or the project name contains å, ä, ö (or any other non English characters) the game crashed with the following message:
Conversion from character set ‘UTF-8’ to ‘CP1252’ is not supported
Please add the correct encoding to MONO_EXTERNAL_ENCODINGS and try again.
How is this resolved? Where do I change the character set?
Localization and extern media
The way I was going to solve this is that the installer includes a folder for each language with all the text and speech translated. Could these be made into a single .assets file? And the correct one would be installed into the data folder depending on the users input during install. If so how would you read this into the game? If a object wants to play a sound named sound1.wav that is part of the translation.assets file how would the object find it? Same goes with text translations. If all the game text is found inside the file named text.txt how would I load it? What would be a good way to parse it? I was thinking something along:
I would then open and read the file with system.IO. The text handler class would then have a textmap[key][value]. So a label could call the text handler function:
string GetText(string keyName)
Which if called with the key tutorial1 would return Blah blah blah blah1.
Shared data
It seems that the OS and PC standalones data folders are pretty similar and therefore it should be possible to share it? At least the level and asset files. This way the installer would pretty much be half the size as opposed to including both the data folders for both Mac and PC.
Icon
How do I set the icon for the PC executable and Mac application?
I am currently running the 2.5 BETA 5 on PC. When ever I export the project and run it the intro sequence always seem to have a veil of fog over it making the colors bleak and unity logos are shown. Is this a BETA feature that will be removed once the final is released? If not how do I get rid of them?
Sorry, this grew to be a long post. Hope I was somewhat clear.
OK, after some testing I came to the conclusion AssetBundles wouldn’t work since the BETA isn’t a pro version. Done some testing with the resource folder. Got it to load two different models if I replaced both the mainData and the .assets file. If the file names of all the data files in the project are the same could the same mainData file be used with different data? I’ll try to get some testing done. If it works I believe the problem with extern data (for localization files) could be solved.
More testing done and great results! Exported two different builds both with a sound.aif (different melodies same data name) in the resource folder. Copied the .assets file from the second build into the first build and it worked. The new song played and nothing crashed. Hurray!
Tried copying the level and .assets files form the Mac to the PC standalone version and vice versa. I am happy to tell you that it worked. Data can be shared between the two platforms.
Now I am going to start on the text handler for text localization, I’ll keep you posted.
Finished the TextHandler. It’s a singleton class that formats a .txt file located in the Resource folder into a hash table. It might need more work in the future but for my testing purposes it passes. The TextHandler assumes the .txt file in the resource folder is named text.txt and is formatted in the following way:
MENU_START=Start
MENU_EXIT=Exit
Where “MENU_START” is the key and “Start” is the value.
using UnityEngine;
using System.Collections;
using System.IO;
public class TextHandler : MonoBehaviour
{
// This is class is a singleton!
private static TextHandler m_Instance = null;
private TextAsset m_TheTextAsset;
private string m_TheTextString;
private Hashtable m_TextMap = new Hashtable();
void Awake()
{
// Keep this object alive even if we change scene.
DontDestroyOnLoad(this);
}
void Start ()
{
m_TheTextAsset = (TextAsset)Resources.Load("text", typeof(TextAsset));
FormatTextIntoHashtable();
}
void FormatTextIntoHashtable()
{
if (m_TheTextAsset != null)
{
Debug.Log("TextHandler - Processing the localized text into text hash table.");
m_TheTextString = m_TheTextAsset.text;
int iTextIndex = 0;
while (iTextIndex < m_TheTextString.Length)
{
int iIndexOfDevider1 = m_TheTextString.IndexOf('=');
int iIndexOfDevider2 = m_TheTextString.IndexOf('\n');
string sKey = m_TheTextString.Substring(0, iIndexOfDevider1).ToString();
string sValue = m_TheTextString.Substring(iIndexOfDevider1 + 1, iIndexOfDevider2 - (iIndexOfDevider1 + 1)).ToString();
m_TheTextString = m_TheTextString.Substring(iIndexOfDevider2 + 1, m_TheTextString.Length - (iIndexOfDevider2 + 1));
m_TextMap.Add(sKey, sValue);
iTextIndex = iIndexOfDevider2 + 1;
}
Debug.Log("TextHandler - Finished processing the localized text into text hash table.");
}
else
{
Debug.LogError("TextHandler - Failed to process the localized text into hash table!");
}
}
public string GetLocalizedText(string sKey)
{
if (m_TextMap.ContainsKey(sKey))
{
return m_TextMap[sKey].ToString();
}
else
{
Debug.LogError("TextHandler - Key not available!");
return "TextHandler - Key not found!";
}
}
public static TextHandler instance
{
get
{
if (m_Instance == null)
{
m_Instance = FindObjectOfType(typeof(TextHandler)) as TextHandler;
if (m_Instance == null)
{
Debug.LogError("TextHandler - Could not find the TextHandler instance!");
}
}
return m_Instance;
}
}
void OnApplicationQuit()
{
m_Instance = null;
}
}
So with the text.txt file from above GetLocalizedText(“MENU_START”) would in this case return the string “Start”.
Managed to read non English characters from a .txt file today by changing the encoding of the file to UTF-8 (using PSPad). Still no luck with the project path or Product Name setting though. Any help with be greatly appreciated. I am using Windows XP and VS2005 to write the code.
I use this class for converting Cyrillic char set (1251, 1252)
Not all is good, but working well with txt or static String vars.
Nog good with dinamically taped texts.Capital letters are not perceived. I don’t understand why.
using UnityEngine;
using System;
using System.Text;
public class ConvertToChar : MonoBehaviour
{
public static string CheckText(string str)
{
if(str.Length==0)return"";
string str1="";
char aa;
int length = str.Length;
for(int i=0; i<length; i++)
{
int res=Convert.ToInt32(str[i]);
if (res>191 res<256)res=res+848;
aa = Convert.ToChar(res);
str1+=aa.ToString();
}
return str1;
}
}
That could be useful if one want to translate between the encodings. I am going to go ahead and guess:
The problem with capital letters probably has something to do with the scope of the values in the “if” and the value added afterwards.
The problem with typed strings probably has something to do with the way they are saved. Maybe the dynamical typed string is not saved with CP1252 encoding.
This still doesn’t help with issue that a game that has a path or is named with non English characters won’t start. Maybe the problem is how unity compiles the game? And if so how do you changed it? Pure speculation.
heh… But in game I cannot normally use cyrillic fonts. Many letters are displayed not correctly or not displayed at all.
Especially badly all in Windows… :?:
And in dynamically typed texts.
Make sure the font you’re using actually contains those glyphs. If you enter any text strings in the script files themselves, save the script files in UTF16 encoding. Various keyboard input problems (different on various platforms) will also be fixed in 2.5.
Yes, of course I use only correct fonts.
Inside the scripts I save nothing. Only like outside vars. And there all is ok with my converter class, which presented in first page of this thread.
But this is hard and painful method.
And with dynamically taped words (in the text field for example) this method doe’s not work with more capital letters.
I don’t know why.
This problems appears in all versions of Windows and in MacOS X too.