Exemplo n.º 1
0
    public void Serialize()
    {
        //Create the root object
        JSONClass rootNode = new JSONClass();

        //Serialize the location manager
        m_LocationManager.Serialize(rootNode);

        //Write the JSON data (.ToString in release as it saves a lot of data compard to ToJSON)
        string jsonStr = "";

        #if UNITY_ANDROID && !UNITY_EDITOR
        jsonStr = rootNode.ToString();
        #else
        jsonStr = rootNode.ToJSON(0);
        #endif

        try
        {
            File.WriteAllText(m_RootPath + "/savegame.json", jsonStr);
            Debug.Log("Save game succesfully saved!");
        }
        catch (Exception e)
        {
            Debug.LogError("Save game error: " + e);
        }
    }
Exemplo n.º 2
0
    public string ToJSON()
    {
        JSONClass root = new JSONClass();

        root.Add("code", new JSONData(code));
        root.Add("messgae", new JSONData(code));
        root.Add("data", data);
        return(root.ToJSON(0));
    }
Exemplo n.º 3
0
        public static string NotifyToJSON(Notify _notify)
        {
            JSONClass head = new JSONClass();

            head.Add("msg", new JSONData(_notify.head.msg));

            JSONClass root = new JSONClass();

            root.Add("head", head);
            root.Add("body", _notify.body);
            return(root.ToJSON(0));
        }
Exemplo n.º 4
0
        public static string ResponseToJSON(Response _rsp)
        {
            JSONClass head = new JSONClass();

            head.Add("msg", new JSONData(_rsp.head.msg));
            head.Add("session", new JSONData(_rsp.head.session));

            JSONClass root = new JSONClass();

            root.Add("head", head);
            root.Add("body", _rsp.body);
            return(root.ToJSON(0));
        }
Exemplo n.º 5
0
        public static string RequestToJSON(Request _req)
        {
            JSONClass head = new JSONClass();

            head.Add("msg", new JSONData(_req.head.msg));
            head.Add("session", new JSONData(_req.head.session));

            JSONClass root = new JSONClass();

            root.Add("head", head);
            root.Add("body", _req.body);
            return(root.ToJSON(0));
        }
Exemplo n.º 6
0
        public static void DownloadManifest(OnSuccessFinishDelegate _onFinish, OnErrorDelegate _onError)
        {
            string uri = Settings.fangs_domain + "/storage/list";

            Log.Debug("HttpMgr", "DownloadMinifest: {0}", uri);
            Dictionary <string, object> paramAry = new Dictionary <string, object>(0);

            paramAry.Add("bucket", HttpMgr.Base64Encode(Settings.beans_bucket));
            paramAry.Add("sort", HttpMgr.Base64Encode("time"));
            paramAry.Add("from", 0);
            paramAry.Add("to", 32);
            Http.Operation operation = http.AsyncPOST(uri, paramAry, (_data) =>
            {
                Log.Debug("HttpMgr", "DownloadMinifest Finish: {0}", uri);
                // parse the response
                JSONNode json = JSON.Parse(System.Text.Encoding.UTF8.GetString(_data));
                int errcode   = json["errcode"].AsInt;
                // 0 is OK
                if (0 != errcode)
                {
                    _onError(string.Format("Download manifest has error, the errorcode is {0}", errcode));
                    return;
                }

                // take all the guid of bean and put them to a array.
                int count      = json["data"]["keys:length"].AsInt;
                string[] beans = new string[count];
                for (int i = 0; i < count; ++i)
                {
                    string field = string.Format("keys:{0}", i);
                    string value = json["data"][field].Value;
                    beans[i]     = Base64Decode(value);
                }
                // save the minifest file with beans
                JSONArray beanAry = new JSONArray();
                foreach (string bean in beans)
                {
                    beanAry.Add(bean);
                }
                JSONClass root = new JSONClass();
                root.Add("beans", beanAry);
                string manifestJson = root.ToJSON(0);

                File.WriteAllText(Path.Combine(beansPath, "manifest.txt"), manifestJson);
                _onFinish();
            }, (_err) =>
            {
                Log.Error("HttpMgr", _err);
                _onError(_err.errmessage);
            });
        }
Exemplo n.º 7
0
    public string SaveToString()
    {
        JSONNode N = new JSONClass();         // Start with JSONArray or JSONClass

        N["settings"]["fov"].AsFloat         = fov;
        N["settings"]["sensitivity"].AsFloat = sensitivity;
        N["settings"]["viewmodel"].AsFloat   = viewModelOn ? 1 : 0;

        N["audio"]["master"].AsFloat        = masterVolume;
        N["audio"]["music"].AsFloat         = musicVolume;
        N["audio"]["sound effects"].AsFloat = soundEffectsVolume;

        N["video"]["bloom"].AsFloat      = bloom ? 1 : 0;
        N["video"]["motionBlur"].AsFloat = motionBlur ? 1 : 0;

        return(N.ToJSON(4));
    }
Exemplo n.º 8
0
    private string ToJSONString(SerializedProperty symbols)
    {
        JSONClass root = new JSONClass();

        for (int i = 0; i < symbols.arraySize; i++)
        {
            SerializedProperty symbol      = symbols.GetArrayElementAtIndex(i);
            string             key         = symbol.FindPropertyRelative("key").stringValue;
            string             rulesString = symbol.FindPropertyRelative("rules").stringValue;
            JSONArray          rules       = new JSONArray();
            foreach (string rule in rulesString.Split('\n'))
            {
                rules.Add(new JSONData(rule));
            }
            root.Add(key, rules);
        }
        return(root.ToJSON(0));
    }
Exemplo n.º 9
0
    private bool Serialize(JSONClassDelegate serializeFunction, string fileName)
    {
        //Create the root object
        JSONClass rootObject = new JSONClass();

        serializeFunction(rootObject);

        //Write the JSON data (.ToString in release as it saves a lot of data compard to ToJSON)
        string jsonStr = "";

        #if UNITY_ANDROID && !UNITY_EDITOR
        jsonStr = rootObject.ToString();
        #else
        jsonStr = rootObject.ToJSON(0);
        #endif

        string filePath = m_RootPath + Path.DirectorySeparatorChar + fileName;
        File.WriteAllText(filePath, jsonStr);

        Debug.Log("Save game succesfully saved!");
        return(true);
    }
Exemplo n.º 10
0
    public string SaveToString()
    {
        JSONNode N             = new JSONClass(); // Start with JSONArray or JSONClass
        float    totalDuration = 0;

        foreach (Snapshot s in snapshotList)
        {
            totalDuration += s.duration;
        }
        N["player recording"]["total duration"].AsFloat = totalDuration;
        N["player recording"]["number frames"].AsInt    = snapshotList.Count;
        for (int i = 0; i < snapshotList.Count; i++)
        {
            Snapshot snap = snapshotList[i];
            N["player recording"]["frames"][i]["duration"].AsFloat    = snap.duration;
            N["player recording"]["frames"][i]["position"][0].AsFloat = snap.position.x;
            N["player recording"]["frames"][i]["position"][1].AsFloat = snap.position.y;
            N["player recording"]["frames"][i]["position"][2].AsFloat = snap.position.z;
            N["player recording"]["frames"][i]["rotation"][0].AsFloat = snap.rotation.x;
            N["player recording"]["frames"][i]["rotation"][1].AsFloat = snap.rotation.y;
            N["player recording"]["frames"][i]["rotation"][2].AsFloat = snap.rotation.z;
            N["player recording"]["frames"][i]["rotation"][3].AsFloat = snap.rotation.w;
            N["player recording"]["frames"][i]["inJump"].AsFloat      = snap.inJump ? 1 : 0;
            N["player recording"]["frames"][i]["y rotation"].AsFloat  = snap.playerRotation;
            N["player recording"]["frames"][i]["camera tilt"].AsFloat = snap.cameraRotation;
            N["player recording"]["frames"][i]["numberKeyRec"].AsInt  = snap.keyRecList.Count;
            for (int k = 0; k < snap.keyRecList.Count; k++)
            {
                KeyRecording keyRecording = snap.keyRecList[k];
                N["player recording"]["frames"][i]["key events"][k]["time"].AsFloat = keyRecording.time;
                N["player recording"]["frames"][i]["key events"][k]["type"]         = keyRecording.type;
                N["player recording"]["frames"][i]["key events"][k]["key"]          = keyRecording.key;
            }
        }
        return(N.ToJSON(4));
    }
Exemplo n.º 11
0
        public static void Write(this SimvaConf conf)
        {
            JSONClass toWrite = new JSONClass();

            toWrite["study"]         = conf.Study;
            toWrite["host"]          = conf.Host;
            toWrite["protocol"]      = conf.Protocol;
            toWrite["port"]          = conf.Port;
            toWrite["url"]           = conf.URL;
            toWrite["trace_storage"] = conf.TraceStorage.ToString();
            toWrite["backup"]        = conf.Backup.ToString();
            toWrite["realtime"]      = conf.Realtime.ToString();

            System.IO.File.WriteAllText(Application.streamingAssetsPath + "/simva.conf", toWrite.ToJSON(0));
        }