小编emo*_*hus的帖子

在手机浏览器上玩Unity webGl游戏时如何保存游戏数据?

我的 Unity WebGL 游戏在大量优化音频和纹理数据后在移动 Web 浏览器上运行。保存游戏数据在桌面环境下运行良好。但是当我在移动浏览器上玩同一个游戏时,似乎没有任何地方保存游戏数据。下面给出了我在本地保存和加载数据的代码。

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

public class DataAccess
{
    [DllImport ( "__Internal" )]
    private static extern void SyncFiles ( );

    [DllImport ( "__Internal" )]
    private static extern void WindowAlert ( string message );

    public static void Save ( Stats stats )
    {
        string dataPath = string.Format ( "{0}/Stats.dat", Application.persistentDataPath );
        BinaryFormatter binaryFormatter = new BinaryFormatter ( );
        FileStream fileStream;

        try
        {
            if ( File.Exists ( dataPath ) )
            { …
Run Code Online (Sandbox Code Playgroud)

save unity-game-engine unity-webgl

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

save ×1

unity-game-engine ×1

unity-webgl ×1