Example #1
0
    void OnGUI()
    {
        Rect  position;
        float yPosition = startY;

        if (inputStyle == null)
        {
            inputStyle          = GUI.skin.textField;
            inputStyle.fontSize = fontSize;
        }

        // User id
        position = new Rect(startX, yPosition, labelWidth, buttonHeight);
        GUI.Label(position, "User Id:", labelStyle);

        position    = new Rect(startX + labelWidth, yPosition, inputWidth, buttonHeight);
        inputUserId = GUI.TextField(position, inputUserId, 30, inputStyle);

        yPosition += yPadding;

        // User Level
        position = new Rect(startX, yPosition, inputWidth, buttonHeight);
        GUI.Label(position, "User Level:", labelStyle);

        position       = new Rect(startX + labelWidth, yPosition, inputWidth, buttonHeight);
        inputUserLevel = GUI.TextField(position, "" + inputUserLevel, 30, inputStyle);

        yPosition += yPadding;

        // User Friends
        position = new Rect(startX, yPosition, inputWidth, buttonHeight);
        GUI.Label(position, "User Friends:", labelStyle);

        position         = new Rect(startX + labelWidth, yPosition, inputWidth, buttonHeight);
        inputUserFriends = GUI.TextField(position, "" + inputUserFriends, 30, inputStyle);

        yPosition += yPadding;

        // User Cohorts Header
        position = new Rect(startX, yPosition, inputWidth, buttonHeight);
        GUI.Label(position, "User Cohorts:", headerStyle);
        yPosition += yPadding;

        // User Cohorts
        for (int i = 0; i < 5; i++)
        {
            position = new Rect(startX, yPosition, inputWidth, buttonHeight);
            GUI.Label(position, "  Cohort " + (i + 1) + ":", labelStyle);

            position        = new Rect(startX + labelWidth, yPosition, inputWidth, buttonHeight);
            cohortValues[i] = GUI.TextField(position, "" + cohortValues[i], 30, inputStyle);

            yPosition += yPadding;
        }

        yPosition += yPadding;

        position = new Rect(centerX - buttonWidth - buttonPadding, yPosition, buttonWidth, buttonHeight);
        if (GUI.Button(position, "Set"))
        {
            // Set user info
            Tapjoy.SetUserID(inputUserId);

            int temp = 0;
            if (int.TryParse(inputUserLevel, out temp))
            {
                Tapjoy.SetUserLevel(temp);
            }

            if (int.TryParse(inputUserFriends, out temp))
            {
                Tapjoy.SetUserFriendCount(temp);
            }

            // Set User cohorts
            for (int i = 0; i < cohortValues.Length; i++)
            {
                Tapjoy.SetUserCohortVariable(i + 1, cohortValues[i]);
            }
        }

        position = new Rect(centerX + buttonPadding, yPosition, buttonWidth, buttonHeight);
        if (GUI.Button(position, "Clear"))
        {
            inputUserId      = inputUserIdPlaceholder;
            inputUserLevel   = inputUserLevelPlaceholder;
            inputUserFriends = inputUserFriendsPlaceholder;
            cohortValues     = new string[5];
        }

        yPosition += yPadding;

        position = new Rect(startX, yPosition, inputWidth, buttonHeight);
        GUI.Label(position, "User Tag:", labelStyle);

        position = new Rect(startX + labelWidth, yPosition, inputWidth, buttonHeight);
        userTag  = GUI.TextField(position, "" + userTag, 30, inputStyle);

        yPosition += yPadding;

        position = new Rect(centerX - buttonWidth - buttonPadding, yPosition, buttonWidth * 2 / 3, buttonHeight);
        if (GUI.Button(position, "Add"))
        {
            Tapjoy.AddUserTag(userTag);
            userTag = "";
        }
        position = new Rect(centerX - buttonWidth / 3, yPosition, buttonWidth * 2 / 3, buttonHeight);
        if (GUI.Button(position, "Remove"))
        {
            Tapjoy.RemoveUserTag(userTag);
            userTag = "";
        }
        position = new Rect(centerX + buttonWidth / 3 + buttonPadding, yPosition, buttonWidth * 2 / 3, buttonHeight);
        if (GUI.Button(position, "Clear"))
        {
            Tapjoy.ClearUserTags();
            userTag = "";
        }

        yPosition += yPadding;
    }