/// This should be the place where the items of type T are being loaded, /// either on the fly, or from file, etc. /// /// Parses a single item from textAsset /// /// @param group /// The unique ID of the group to load. /// /// @return The parsed instance /// protected virtual T ParseItem(TextAsset textAsset) { T serializable = new T(); string assetName = ""; if (textAsset != null) { assetName = textAsset.name; serializable.m_id = assetName; try { object jsonData = JsonWrapper.ParseJsonFromTextAsset(textAsset); serializable.Deserialize(jsonData); } catch (System.Exception exception) { // Something went wrong during the parsing of the file Debug.LogError(string.Format("Could not parse file '{0}' of type {1}.\n{2}", textAsset.name, typeof(T), exception.Message)); } } Debug.Assert(m_data.ContainsKey(assetName) == false, string.Format("Duplicate serializable id found: {0} already exists", assetName)); return(serializable); }
/// @param path /// The path to the registry file /// protected void LoadRegistry(string path) { TextAsset textAsset = Resources.Load <TextAsset>(path); if (textAsset == null) { Debug.LogError(string.Format("Could not find registry file with path '{0}'", path)); } var dictionary = JsonWrapper.ParseJsonFromTextAsset(textAsset).AsDictionary(); if ((dictionary != null) && dictionary.ContainsKey(k_keyRegistry)) { m_registry = dictionary.GetValue(k_keyRegistry).AsList <string>(); } }
/// Loads all assets in a single folder and adds them to the dictionary. /// /// @param group /// The unique ID of the group to load. /// protected virtual void LoadInternal(string group) { string path = m_dataPath; if (m_loaderBehaviour == LoaderBehaviour.LoadInGroups) { path = string.Format(k_pathWithGroupFormat, path, group); } if (m_fileType == FileType.SeparateFiles) { TextAsset[] textAssets = Resources.LoadAll <TextAsset>(path); Debug.Assert(textAssets.Length > 0, string.Format("No data on path {0}", path)); foreach (TextAsset asset in textAssets) { // Avoid duplicate if (IsLoaded(asset.name) == false) { T serializable = ParseItem(asset); AddItem(serializable, group); } } } else { TextAsset textAsset = Resources.Load <TextAsset>(path); if (textAsset != null) { var jsonData = JsonWrapper.ParseJsonFromTextAsset(textAsset).AsDictionary(); foreach (var asset in jsonData) { // Avoid duplicate if (IsLoaded(asset.Key) == false) { T serializable = new T(); serializable.m_id = asset.Key; serializable.Deserialize(asset.Value); AddItem(serializable, group); } } } } }