Пример #1
0
    /// <summary>
    /// Tell Crittercism to associate the given value/key pair with the current
    /// device UUID.
    /// <param name="val">The metadata value to set</param>
    /// <param name="key">The key to associate with the given metadata<c/param>
    /// <example>SetValue("5", "Game Level")</example>
    /// </summary>
    public static void SetValue(string key, string value)
    {
#if UNITY_IOS
        CrittercismIOS.SetValue(value, key);
#elif UNITY_ANDROID
        CrittercismAndroid.SetMetadata(new string[] { key }, new string[] { value });
#endif
    }
    void OnGUI()
    {
        if (Screen.height == 0 || Screen.width == 0)
        {
            return;
        }

        int screenButtonHeight = Screen.height / 8;

        if (GUI.Button(new Rect(0, 0, Screen.width, screenButtonHeight), "Null Reference"))
        {
            CrittercismAndroid.LeaveBreadcrumb("Null Reference incoming?!");
            string crash = null;
            crash = crash.ToLower();
        }

        if (GUI.Button(new Rect(0, screenButtonHeight, Screen.width, screenButtonHeight), "Divide By Zero"))
        {
            CrittercismAndroid.LeaveBreadcrumb("Lets divide by zero!");
            int i = 0;
            i = 2 / i;
        }

        if (GUI.Button(new Rect(0, screenButtonHeight * 2, Screen.width, screenButtonHeight), "Index Out Of Range"))
        {
            string[] arr = new string[1];
            arr[2] = "Crash";
        }

        if (GUI.Button(new Rect(0, screenButtonHeight * 3, Screen.width, screenButtonHeight), "Custom Exception"))
        {
            throw new System.Exception("Custom Exception");
        }

        if (GUI.Button(new Rect(0, screenButtonHeight * 4, Screen.width, screenButtonHeight), "Coroutine Custom Exception"))
        {
            StartCoroutine(MonoCorutineCrash());
        }

        if (GUI.Button(new Rect(0, screenButtonHeight * 5, Screen.width, screenButtonHeight), "Coroutine Null Exception"))
        {
            StartCoroutine(MonoCorutineNullCrash());
        }

        if (GUI.Button(new Rect(0, screenButtonHeight * 7, Screen.width, screenButtonHeight), "Test Messages"))
        {
            Debug.Log("User Test");
            CrittercismAndroid.SetUsername("RandomUser" + Random.Range(0, 10000).ToString());

            Debug.Log("Breadcrumb Test");
            CrittercismAndroid.LeaveBreadcrumb("BreadCrumb");

            Debug.Log("Metadata Test");
            CrittercismAndroid.SetMetadata(new string[] { "Age", "Email", "Extra" }, new string[] { Random.Range(10, 90).ToString(), string.Format("email{0}@test.com", Random.Range(0, 200)), "Data" });
        }
    }
Пример #3
0
 public static void SetValue(string key, string value)
 {
     CrittercismAndroid.SetMetadata(new string[]
     {
         key
     }, new string[]
     {
         value
     });
 }
Пример #4
0
    /// <summary>
    /// Tell Crittercism to associate the given value/key pair with the current
    /// device UUID.
    /// <param name="val">The metadata value to set</param>
    /// <param name="key">The key to associate with the given metadata<c/param>
    /// <example>SetValue("5", "Game Level")</example>
    /// </summary>
    public static void SetMetadata(string[] keys, string[] values)
    {
#if UNITY_IOS
        int length = keys.Length;
        for (int i = 0; i < length; i++)
        {
            string key   = keys [i];
            string value = values [i];
            CrittercismIOS.SetValue(value, key);
        }
#elif UNITY_ANDROID
        CrittercismAndroid.SetMetadata(keys, values);
#endif
    }
    public void OnGUI()
    {
        GUIStyle customStyle = new GUIStyle(GUI.skin.button);

        customStyle.fontSize = 30;
        const int numberOfButtons    = 13;
        int       screenButtonHeight = Screen.height / numberOfButtons;

        if (GUI.Button(new Rect(0, 0, Screen.width, screenButtonHeight), "Set Username", customStyle))
        {
            CrittercismAndroid.SetUsername("MommaCritter");
        }
        if (GUI.Button(new Rect(0, screenButtonHeight, Screen.width, screenButtonHeight), "Set Metadata", customStyle))
        {
            CrittercismAndroid.SetMetadata(new string[] {
                "Game Level",
                "Status"
            }, new string[] {
                "5",
                "Crashes a lot"
            });
        }
        if (GUI.Button(new Rect(0, 2 * screenButtonHeight, Screen.width, screenButtonHeight), "Leave Breadcrumb", customStyle))
        {
            CrittercismAndroid.LeaveBreadcrumb("BreadCrumb");
        }
        if (GUI.Button(new Rect(0, 3 * screenButtonHeight, Screen.width, screenButtonHeight), "Log Network Request", customStyle))
        {
            System.Random random    = new System.Random();
            string[]      methods   = new string[] { "GET", "POST", "HEAD", "PUT" };
            string        method    = methods[random.Next(0, methods.Length)];
            string        uriString = uriStrings[random.Next(0, uriStrings.Length)];
            if (random.Next(0, 2) == 1)
            {
                uriString = uriString + "?doYouLoveCrittercism=YES";
            }
            // latency in milliseconds
            long latency      = (long)Math.Floor(4000.0 * random.NextDouble());
            long bytesRead    = random.Next(0, 10000);
            long bytesSent    = random.Next(0, 10000);
            int  responseCode = 200;
            if (random.Next(0, 5) == 0)
            {
                // Some common response other than 200 == OK .
                int[] responseCodes = new int[] { 301, 308, 400, 401, 402, 403, 404, 405, 408, 500, 502, 503 };
                responseCode = responseCodes[random.Next(0, responseCodes.Length)];
            }
            Console.WriteLine("LogNetworkRequest: \"" + uriString + "\"");
            CrittercismAndroid.LogNetworkRequest(
                method,
                uriString,
                latency,
                bytesRead,
                bytesSent,
                (HttpStatusCode)responseCode,
                WebExceptionStatus.Success);
        }
        if (GUI.Button(new Rect(0, 4 * screenButtonHeight, Screen.width, screenButtonHeight), "C# Crash", customStyle))
        {
            crashInnerException();
        }
        if (GUI.Button(new Rect(0, 5 * screenButtonHeight, Screen.width, screenButtonHeight), "C# Handled Exception", customStyle))
        {
            try {
                crashInnerException();
            } catch (System.Exception e) {
                CrittercismAndroid.LogHandledException(e);
            }
        }
        if (GUI.Button(new Rect(0, 6 * screenButtonHeight, Screen.width, screenButtonHeight), "C# Null Pointer Exception", customStyle))
        {
            try {
                causeNullPointerException();
            } catch (Exception e) {
                CrittercismAndroid.LogHandledException(e);
            }
        }
        if (GUI.Button(new Rect(0, 7 * screenButtonHeight, Screen.width, screenButtonHeight), "Begin Transaction", customStyle))
        {
            CrittercismAndroid.BeginTransaction("UnityAndroid");
        }
        if (GUI.Button(new Rect(0, 8 * screenButtonHeight, Screen.width, screenButtonHeight), "End Transaction", customStyle))
        {
            CrittercismAndroid.EndTransaction("UnityAndroid");
        }
        if (GUI.Button(new Rect(0, 9 * screenButtonHeight, Screen.width, screenButtonHeight), "Fail Transaction", customStyle))
        {
            CrittercismAndroid.FailTransaction("UnityAndroid");
        }
        if (GUI.Button(new Rect(0, 10 * screenButtonHeight, Screen.width, screenButtonHeight), "Cancel Transaction", customStyle))
        {
            CrittercismAndroid.CancelTransaction("UnityAndroid");
        }
        if (GUI.Button(new Rect(0, 11 * screenButtonHeight, Screen.width, screenButtonHeight), "Set Transaction Value", customStyle))
        {
            CrittercismAndroid.SetTransactionValue("UnityAndroid", 500);
        }
        if (GUI.Button(new Rect(0, 12 * screenButtonHeight, Screen.width, screenButtonHeight), "Get Transaction Value", customStyle))
        {
            int value = CrittercismAndroid.GetTransactionValue("UnityAndroid");
            Debug.Log("TransactionValue is: " + value);
        }
    }
Пример #6
0
 public static void SetMetadata(string[] keys, string[] values)
 {
     CrittercismAndroid.SetMetadata(keys, values);
 }