Exemplo n.º 1
0
 public LocalFileBase(string filePath, string assetText)
 {
     m_FilePath          = filePath;
     m_TextData          = assetText;
     m_LocalFileTypeEnum = LocalFileTypeEnum.ObjectSimpleVale;
     if (string.IsNullOrEmpty(assetText))
     {
         m_IsEnable = false;
         Debug.LogError("AnalysisFile Fail,assetText Is NullOrEmpty!!  " + filePath);
         return;
     }
     AnalysisFile(assetText);
 }
        public LocalFileBase GetLocalFileBase(LocalFileTypeEnum fileType, string filePath, string assetText)
        {
            switch (fileType)
            {
            case LocalFileTypeEnum.ObjectSimpleVale:
                return(new LocalFileObjectSimpleValue(filePath, assetText));

            case LocalFileTypeEnum.ArraySimpleValue:
                return(new LocalFileArraySimpleValue(filePath, assetText));

            default:
                Debug.LogError("GetLocalFileBase  Fail,没有识别的类型 " + fileType);
                return(null);
            }
        }
Exemplo n.º 3
0
        public string GetLocalTextString(string fileName, string key, LanguageType language, LocalFileTypeEnum localFileEnum = LocalFileTypeEnum.ObjectSimpleVale)
        {
            string resultStr = "";
            string filePath  = string.Format("Localization/{0}/{1}", language.ToString(), fileName);
            string path      = Application.dataPath + "/Resources/" + filePath + ".txt";

            Debug.Log("path=" + path);
            if (System.IO.File.Exists(path))
            {
                ResourcesMgr.Instance.LoadTextAsset(filePath, (localfileBase) =>
                {
                    if (localfileBase == null)
                    {
                        Debug.LogError("GetLocalTextString  Fail");
                        return;
                    }
                    resultStr = localfileBase.GetFileValueByKey(key);
                }, localFileEnum);
            }
            else
            {
                Debug.Log("GetLocalTextString Fail,当前文件不存在" + fileName);
            }
            return(resultStr);
        }
Exemplo n.º 4
0
    /// <summary>
    /// 加载TextAsset资源文件(仅仅适用于特定格式的Json 文件)
    /// </summary>
    /// <param name="assetPath">资源相对于Resource的路径</param>
    /// <param name="fileType">配置文件的类型</param>
    /// <param name="callback"></param>
    public void LoadTextAsset(string assetPath, System.Action <LocalFileBase> callback, LocalFileTypeEnum fileType = LocalFileTypeEnum.ObjectSimpleVale)
    {
        if (m_AllLoadLocalFileDic.ContainsKey(assetPath))
        {
            if (callback != null)
            {
                callback(m_AllLoadLocalFileDic[assetPath]);
            }
            return;
        }

        LoadAsset(assetPath, (obj) => {
            if (obj == null)
            {
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }

            TextAsset asset = obj as TextAsset;
            if (asset == null)
            {
                Debug.LogError("加载TextAsset 失败 " + assetPath);
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }
            LocalFileBase localFile = LocalFileFactory.GetInstance().GetLocalFileBase(fileType, assetPath, asset.text);
            if (localFile == null)
            {
                Debug.LogError("生成本地文件失败 " + assetPath);
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }
            m_AllLoadLocalFileDic.Add(assetPath, localFile);
            if (callback != null)
            {
                callback(localFile);
            }
        });
    }