示例#1
0
        private void handleCallback(string method, string jsonString)
        {
            Json json = Json.parse(jsonString);

            if (json.is_null())
            {
                Debug.LogError("Failed to parse JSON callback payload");
                throw new System.ArgumentException("Invalid JSON payload");
            }

            Debug.Log("Dispatching SocialShare callback method: " + method);

            switch (method)
            {
            case "onShareState": {
                if (callbacks.onShareState != null)
                {
                    SocialShareResponse resp = SocialShareResponse.createFromJson(json);
                    Debug.Log("share state:" + resp.state + " platform:" + resp.platform + " error:" + resp.error);
                    callbacks.onShareState.Invoke(resp);
                }
                break;
            }

            default: {
                throw new System.ArgumentException("Unknown callback type: " + method);
            }
            }
        }
示例#2
0
            public static SocialShareResponse createFromJson(Json j)
            {
                SocialShareResponse r = new SocialShareResponse();

                try {
                    r.state    = (SocialShareState)j["state"].int_value();
                    r.error    = j["error"].string_value();
                    r.platform = (SocialPlatform)j["platform"].int_value();
                } catch (Exception e) {
                    Debug.LogException(e);
                    Debug.Log("Json: " + j.dump());
                }
                return(r);
            }