Crown.Log C# (CSharp) Méthode

Log() public static méthode

public static Log ( string msg, bool hidetime = false ) : void
msg string
hidetime bool
Résultat void
    public static void Log(string msg, bool hidetime = false)
    {
        if (!hidetime)
        {
            string _time = Time.time.ToString();
            if (_time.Length > 6) _time = _time.Substring(0, 6);
            msg = _time + " " + msg;
        }
        if (log != "") log += "\n";
        log += msg;
    }

Usage Example

Exemple #1
0
    /*
     * Network request (send data and get result)
     */
    public static IEnumerator Request(string function, JSON parameters = null, CrownCallbackJSON callback = null, CrownCallbackJSON internalCallback = null)
    {
        string url = instance.serverURL;

        Crown.Log("Server request " + function);

        // Create www post
        WWWForm form = new WWWForm();

        // Add platform, function and parameters
        form.AddField("function", function);
        form.AddField("parameters", parameters.print());

        // Add user data
        form.AddField("userId", instance.userId);
        form.AddField("userKey", instance.userKey);
        form.AddField("userSpot", instance.userSpot);

        // Download
        WWW www = new WWW(url, form);

        yield return(www);

        // Get request
        if (www.error == null)
        {
            // Try to get JSON DATA
            JSON result = null;
            try
            {
                result = new JSON(www.text);
                Crown.Log("Request result: " + result.print());
            }
            catch
            {
                Crown.Error("Server wrong data: " + www.text);
            }

            // Check for server errors
            if (result["error"] != null)
            {
                Crown.Error("Server error: " + result["error"], true);
            }
            // Get json array
            else if (result["data"] != null)
            {
                if (callback != null)
                {
                    callback(result["data"]);
                }
                if (internalCallback != null)
                {
                    internalCallback(result["data"]);
                }
            }
            else
            {
                Crown.Error("Server return's null result", true);
            }
        }
        else
        {
            Crown.Error("Request error " + url + ", www error: " + www.error, true);
        }
    }