Пример #1
0
    //同步读文本
    public static string LoadAllTextSync(string textfilename)
    {
        //先外包
        string outerpath = ResDef.OuterPackageDirectory + textfilename;

        if (System.IO.File.Exists(outerpath))
        {
            long   t1   = Api.GetTickCount();
            string text = System.IO.File.ReadAllText(outerpath, System.Text.Encoding.UTF8);
            long   t2   = Api.GetTickCount();
            long   dt   = t2 - t1;
            Trace.Log("LoadAllTextSync OK:" + outerpath + ",time=" + dt.ToString() + "ms");
            return(text);
        }

        //接着以文件系统方式读内包
        string innerpath1 = ResDef.InterPackageDirectoryEx + textfilename;

        if (System.IO.File.Exists(innerpath1))
        {
            long   t1   = Api.GetTickCount();
            string text = System.IO.File.ReadAllText(innerpath1, System.Text.Encoding.UTF8);
            long   t2   = Api.GetTickCount();
            long   dt   = t2 - t1;
            Trace.Log("LoadAllTextSync OK:" + innerpath1 + ",time=" + dt.ToString() + "ms");
            return(text);
        }

                #if SupportPackageIO
        //再以包系统方式读内包
        string innerpath2 = ResDef.InterPackageDirectory + textfilename;
        if (PackageIO.Exists(innerpath2))
        {
            return(PackageIO.ReadAllText(innerpath2, System.Text.Encoding.UTF8));
        }
                #endif

        //Trace.LogError("LoadAllTextSync fail:" + outerpath + "," + innerpath1);

        //都失败就返回失败
        return("");
    }
Пример #2
0
    //异步读文本
    public static void LoadAllTextAsyn(string textfilename, IResourceLoad iLoad)
    {
        if (textfilename.Length <= 0)
        {
            return;
        }

        //先外包
        string outerpath = ResDef.OuterPackageDirectory + textfilename;

        if (System.IO.File.Exists(outerpath))
        {
            long   t1   = Api.GetTickCount();
            string text = System.IO.File.ReadAllText(outerpath);
            long   t2   = Api.GetTickCount();
            long   dt   = t2 - t1;

            Trace.Log("LoadAllTextAsyn OK:" + outerpath + ",time=" + dt.ToString() + "ms");

            ResLoadResult ret = new ResLoadResult();
            ret.fProgress = 1.0f;
            ret.resObj    = null;
            ret.resText   = text;
            ret.sErrorMsg = "";
            ret.sPath     = outerpath;
            iLoad.ResourceLoadSucc(ret);

            return;
        }

        //接着以文件系统方式读内包
        string innerpath1 = ResDef.InterPackageDirectoryEx + textfilename;

        if (System.IO.File.Exists(innerpath1))
        {
            long   t1   = Api.GetTickCount();
            string text = System.IO.File.ReadAllText(innerpath1);
            long   t2   = Api.GetTickCount();
            long   dt   = t2 - t1;

            Trace.Log("LoadAllTextAsyn OK:" + innerpath1 + ",time=" + dt.ToString() + "ms");

            ResLoadResult ret = new ResLoadResult();
            ret.fProgress = 1.0f;
            ret.resObj    = null;
            ret.resText   = text;
            ret.sErrorMsg = "";
            ret.sPath     = innerpath1;
            iLoad.ResourceLoadSucc(ret);

            return;
        }

                #if SupportPackageIO
        //再以包系统方式读内包
        string innerpath2 = ResDef.InterPackageDirectory + textfilename;
        if (PackageIO.Exists(innerpath2))
        {
            string text = PackageIO.ReadAllText(innerpath2);

            ResLoadResult ret = new ResLoadResult();
            ret.fProgress = 1.0f;
            ret.resObj    = null;
            ret.resText   = text;
            ret.sErrorMsg = "";
            ret.sPath     = innerpath2;
            iLoad.ResourceLoadSucc(ret);
        }
                #endif

        //Trace.LogError("LoadAllTextSync fail:" + outerpath + "," + innerpath1);

        //都失败就返回失败
        {
            ResLoadResult ret = new ResLoadResult();
            ret.fProgress = 1.0f;
            ret.resObj    = null;
            ret.resText   = "";
            ret.sErrorMsg = "";
            ret.sPath     = outerpath;
            iLoad.ResourceLoadFail(ret);

            return;
        }
    }