为什么我无法在persistentDataPath中的统一Android游戏中找到字体文件(.ttf)?

问题描述 投票:0回答:1

有人可以指引我正确的方向吗?我在VS 2017上使用C#在united 2018.4.9上制作的Android游戏无法检测到持久数据路径中的文件。

这两个字体文件位于持久数据路径目录中。 This is a screenshot of app persistent data folder.

这是我的代码,用于找到两个字体文件。

    string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
    string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";
    //Check Font 1 existence
    if (File.Exists(fontpath1))
    {
        Debugtext.text += "true1\r\n";
    }
    else if (!File.Exists(fontpath1))
    {

        Debugtext.text += "false1\r\n";


    }

    //Check Font 2 existence
    if (File.Exists(fontpath2))
    {
        Debugtext.text += "true2\r\n";
    }
    else if (!File.Exists(fontpath2))
    {

        Debugtext.text += "false2\r\n";


    }
    //Third File(Image file existence)
    if (File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
    {
        Debugtext.text += "trueIM\r\n";
    }
    else if (!File.Exists(Application.persistentDataPath + "/FullShot.jpg"))
    {

        Debugtext.text += "falseIM\r\n";


    }
    Debugtext.text += Application.persistentDataPath;

Debugtext.text是一个文本框,显示三个文件的结果:a)字体文件1b)字体文件2c)图像文件

文件1和2的调试跟踪始终为false,而映像文件存在时返回true。

这些字体文件使用UnityWebRequest使用以下代码从流路径下载到持久路径:

    string fontpath1 = Application.streamingAssetsPath + "/LEOPALMHINDI15K710.TTF";
    string fontpath2 = Application.streamingAssetsPath + "/LEOPALMHINDI14K240.TTF";

    //Request Font1

    UnityWebRequest request = UnityWebRequest.Get(fontpath1);
    request.SendWebRequest();
    while (!request.isDone)
    {


    }
    System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI15K710.TTF", request.downloadHandler.data);

    //Request Font2

    UnityWebRequest font2 = UnityWebRequest.Get(fontpath2);
    font2.SendWebRequest();
    while (!font2.isDone)
    {


    }
    System.IO.File.WriteAllBytes(Application.persistentDataPath + "/LEOPALMHINDI14K240.TTF", font2.downloadHandler.data);

文件已下载并正确写入存储/仿真/0/Android/data/com.appname.com/files(在跟踪中经过交叉检查。)的持久数据路径。

为什么没有找到这两个字体文件并返回false,而同一路径中的其他文件返回true?

[任何人,请帮助我修复它。我要找到这两个字体文件。

android unity3d itext itext7 true-type-fonts
1个回答
0
投票

始终使用Path.Combine,而不是通过字符串串联Path.Combine硬编码系统路径! + "/"而是根据运行的OS使用正确的路径分隔符

Path.Combine
© www.soinside.com 2019 - 2024. All rights reserved.