Quantcast
Channel: Questions in topic: "unitywebplayer"
Viewing all articles
Browse latest Browse all 452

How to get the streaming assets path in WebGL?

$
0
0
I know this has been asked thousand times, but I just can not see the error. I have a xml file placed in a streaming assets folder. I am able to read it for any platform except the WebGL. I test it in Firefox. There is not even a way to debug it but I know the problem is here because of the Firefox console. It says, the problem is in LanguageManager when calling the getString() - no strings just exists. See the code bellow: public class LanguageManager : MonoBehaviour { private Hashtable Strings; private string filePath; void Awake() { if (Application.platform == RuntimePlatform.WindowsEditor) // If Unity Editor... { filePath = "Assets/StreamingAssets/Languages.xml"; } else if (Application.platform == RuntimePlatform.WindowsPlayer) // If Standalone... { filePath = Application.dataPath + "/StreamingAssets/Languages.xml"; } else if (Application.platform == RuntimePlatform.Android) // If Android... { string tempPath = System.IO.Path.Combine (Application.streamingAssetsPath, "Languages.xml"); // Android only use WWW to read file WWW reader = new WWW (tempPath); while (!reader.isDone) { } filePath = Application.persistentDataPath + "/db"; System.IO.File.WriteAllBytes (filePath, reader.bytes); } else if (Application.platform == RuntimePlatform.WebGLPlayer) // If WebGL ERROR HERE { filePath = System.IO.Path.Combine (Application.streamingAssetsPath, "Languages.xml"); } string language = PlayerPrefs.GetString ("LanguageSettings", "English"); // Set Language. var xml = new XmlDocument(); xml.Load(filePath); // Define path to the XML document. Strings = new Hashtable(); var element = xml.DocumentElement[language]; if (element != null) { var elemEnum = element.GetEnumerator(); while (elemEnum.MoveNext()) { var xmlItem = (XmlElement)elemEnum.Current; Strings.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText); } } else Debug.LogError("The specified language does not exist: " + language); } public string getString (string name) { if (!Strings.ContainsKey(name)) { Debug.LogError("The specified string does not exist: " + name); return ""; } return (string)Strings[name]; } }

Viewing all articles
Browse latest Browse all 452

Trending Articles