Exemple #1
0
    private MotdResponse GetLocalMotd(string filePath)
    {
        TextAsset    textAsset    = Resources.Load <TextAsset>(filePath.Replace(".json", string.Empty));
        MotdResponse motdResponse = JsonConvert.DeserializeObject <MotdResponse>(textAsset.ToString());

        motdResponse.image_texture = Resources.Load <Texture2D>("motd_local/image.png");
        return(motdResponse);
    }
Exemple #2
0
 private void doCallback(MotdResponse response, string error)
 {
     if (m_callback != null)
     {
         m_callback(response, error);
     }
     else
     {
         Debug.Log("Motd Response receieved, but callback was unregistered");
     }
 }
Exemple #3
0
    private void GetWebMotd(string url, MotdResponse localMotd, Action <MotdResponse, string> cb)
    {
        Action <string, string> cb2 = delegate(string response, string err)
        {
            if (err != null)
            {
                cb(null, err);
            }
            else
            {
                MotdResponse responseStruct = JsonConvert.DeserializeObject <MotdResponse>(response, new JsonSerializerSettings
                {
                    Error = (EventHandler <ErrorEventArgs>) delegate(object sender, ErrorEventArgs args)
                    {
                        args.ErrorContext.Handled = true;
                    }
                });
                if (responseStruct == null)
                {
                    cb(null, "Invalid json from server:" + response);
                }
                else if (responseStruct.version <= localMotd.version)
                {
                    Debug.Log("Using local MOTD at version: " + localMotd.version + ", web version at " + responseStruct.version);
                    cb(localMotd, null);
                }
                else
                {
                    UnityWebRequest data_wr = new UnityWebRequest
                    {
                        downloadHandler = new DownloadHandlerTexture()
                    };
                    SimpleNetworkCache.LoadFromCacheOrDownload("motd_image", responseStruct.image_url, responseStruct.image_version, data_wr, delegate(UnityWebRequest wr)
                    {
                        string arg = null;
                        if (string.IsNullOrEmpty(wr.error))
                        {
                            Debug.Log("Using web MOTD at version: " + responseStruct.version + ", local version at " + localMotd.version);
                            responseStruct.image_texture = DownloadHandlerTexture.GetContent(wr);
                        }
                        else
                        {
                            arg = "SimpleNetworkCache - " + wr.error;
                        }
                        cb(responseStruct, arg);
                        wr.Dispose();
                    });
                }
            }
        };

        getAsyncRequest(url, cb2);
    }
Exemple #4
0
    public void GetMotd(Action <MotdResponse, string> cb)
    {
        m_callback = cb;
        MotdResponse localResponse = GetLocalMotd(MotdLocalPath);

        GetWebMotd(MotdServerUrl, localResponse, delegate(MotdResponse response, string err)
        {
            if (err == null)
            {
                doCallback(response, err);
            }
            else
            {
                Debug.LogWarning("Could not retrieve web motd from " + MotdServerUrl + ", falling back to local - err: " + err);
                doCallback(localResponse, null);
            }
        });
    }