/// <summary>
    /// Load items and component settings from JSON
    /// </summary>
    /// <param name="json">JSON item</param>
    public void LoadSettings(OnlineMapsJSONItem json)
    {
        OnlineMapsJSONItem jitems = json["items"];

        RemoveAll();
        foreach (OnlineMapsJSONItem jitem in jitems)
        {
            OnlineMapsMarker marker = new OnlineMapsMarker();

            double mx = jitem.ChildValue <double>("longitude");
            double my = jitem.ChildValue <double>("latitude");

            marker.SetPosition(mx, my);

            marker.range    = jitem.ChildValue <OnlineMapsRange>("range");
            marker.label    = jitem.ChildValue <string>("label");
            marker.texture  = OnlineMapsUtils.GetObject(jitem.ChildValue <int>("texture")) as Texture2D;
            marker.align    = (OnlineMapsAlign)jitem.ChildValue <int>("align");
            marker.rotation = jitem.ChildValue <float>("rotation");
            marker.enabled  = jitem.ChildValue <bool>("enabled");
            Add(marker);
        }

        OnlineMapsJSONItem jsettings = json["settings"];

        defaultTexture    = OnlineMapsUtils.GetObject(jsettings.ChildValue <int>("defaultTexture")) as Texture2D;
        defaultAlign      = (OnlineMapsAlign)jsettings.ChildValue <int>("defaultAlign");
        defaultScale      = jsettings.ChildValue <float>("defaultScale");
        allowAddMarkerByM = jsettings.ChildValue <bool>("allowAddMarkerByM");
    }
Exemple #2
0
        /// <summary>
        /// How to get the value of JSON elements.
        /// </summary>
        /// <param name="json">JSON object</param>
        private void GetValues(OnlineMapsJSONItem json)
        {
            // Get the value of the text element.
            string text = json["text"].Value <string>();

            // or in such a ways
            text = json.ChildValue <string>("text");
            text = json.V <string>("text");
            text = json["text"].V <string>();
            Debug.Log(text);

            // You can get: string, bool, float, double, int, long, byte, short.
            int x = json["listItems/0/x"].Value <int>();

            Debug.Log(x);

            // A value of any type can be read as a string.
            // In this case, y is int.
            string y = json["listItems/0/y"].Value <string>();

            Debug.Log(y);
        }