Beispiel #1
0
    void OnGUI()
    {
        // Define text and button formatting
        ////////////////////////////////////////
        int      padding      = 10;
        int      buttonHeight = 80;
        int      textHeight   = 40;
        int      buttonWidth  = Screen.width - padding * 2;
        GUIStyle titleStyle   = new GUIStyle("label");

        titleStyle.fontSize         = 48;
        titleStyle.fontStyle        = FontStyle.BoldAndItalic;
        titleStyle.normal.textColor = Color.red;
        titleStyle.alignment        = TextAnchor.MiddleCenter;
        GUIStyle buttonStyle = new GUIStyle("button");

        buttonStyle.fontSize  = 32;
        buttonStyle.fontStyle = FontStyle.Bold;
        GUIStyle defaultTextStyle = new GUIStyle("label");

        defaultTextStyle.fontSize         = 32;
        defaultTextStyle.normal.textColor = Color.black;
        defaultTextStyle.fontStyle        = FontStyle.Bold;
        defaultTextStyle.alignment        = TextAnchor.MiddleCenter;


        // Render title and practice button
        ////////////////////////////////////
        GUI.Label(new Rect(padding, padding, buttonWidth, 80), "Clickster", titleStyle);

        if (GUI.Button(new Rect(padding, 400, buttonWidth, buttonHeight), "Practice", buttonStyle))
        {
            gameState.challenge = null;
            Application.LoadLevel("ClickArena");
        }


        // Arbiter Logic
        ////////////////////////////////////
        if (uiEnabled)
        {
            // If logged into Arbiter, then create and display a Cash Challenge
            if (Arbiter.IsAuthenticated)
            {
                // Opens the Wallet Dashboard for the user to purchase and cashout their credits
                /////////////////////////////////////////////////////////////////////////////////
                if (GUI.Button(new Rect(padding, Screen.height - padding * 2 - buttonHeight * 2, buttonWidth, buttonHeight), "View Arbiter Wallet", buttonStyle))
                {
                    Arbiter.DisplayWalletDashboard(OnWalletClosed);
                }

                // Logout button destroys the current session. If the player authenticated with
                // their device (vs using Game Center), they will lose access to their wallet
                /////////////////////////////////////////////////////////////////////////////////
                if (GUI.Button(new Rect(padding, Screen.height - padding - buttonHeight, buttonWidth, buttonHeight), "Logout", buttonStyle))
                {
                    uiEnabled = false;
                    Arbiter.Logout(LogoutSuccessHandler, DefaultErrorHandler);
                }

                // Cash Challenge Details and Entry Button
                ////////////////////////////////////////////
                if (gameState.challenge != null)
                {
                    GUI.Label(new Rect(padding, 400 + buttonHeight * 2, buttonWidth, buttonHeight), "Cash Challenge", titleStyle);
                    GUI.Label(new Rect(padding, 400 + buttonHeight * 3, buttonWidth, buttonHeight), "Score to beat: " + gameState.challenge.ScoreToBeat, defaultTextStyle);
                    GUI.Label(new Rect(padding, 400 + buttonHeight * 3 + textHeight, buttonWidth, buttonHeight), "Entry fee: " + gameState.challenge.EntryFee, defaultTextStyle);
                    GUI.Label(new Rect(padding, 400 + buttonHeight * 4, buttonWidth, buttonHeight), "Prize: " + gameState.challenge.Prize, defaultTextStyle);
                    if (GUI.Button(new Rect(padding, 400 + buttonHeight * 5, buttonWidth, buttonHeight), "Enter Cash Challenge", buttonStyle))
                    {
                        Arbiter.AcceptCashChallenge(gameState.challenge.Id, OnCashChallengeAccepted, OnCashChallengeError);
                    }
                }

                // If not logged into Arbiter, then display the login options
            }
            else
            {
                // Authenticates with Token stored on the device
                ////////////////////////////////////////////////
                if (GUI.Button(new Rect(padding, Screen.height - padding - buttonHeight, buttonWidth, buttonHeight), "Login with Device", buttonStyle))
                {
                    uiEnabled = false;
                    Arbiter.LoginWithDeviceId(LoginSuccessHandler, DefaultErrorHandler);
                }

                // Uses Unity's social plugin to authenticate with Apple Game Center
                // and then uses that Game Center account to authenticate with Aribter
                //////////////////////////////////////////////////////////////////////
                if (GUI.Button(new Rect(padding, Screen.height - padding * 2 - buttonHeight * 2, buttonWidth, buttonHeight), "Login with Game Center", buttonStyle))
                {
                    uiEnabled = false;
                    Action <bool> processAuth = (success) => {
                        if (success)
                        {
                            Arbiter.LoginWithGameCenter(LoginSuccessHandler, DefaultErrorHandler);
                        }
                        else
                        {
                            Debug.LogError("Could not authenticate to Game Center! Make Sure the user has not disabled Game Center on their device, or have them create an Arbiter Account.");
                        }
                    };
                    Social.localUser.Authenticate(processAuth);
                }
            }
        }
    }
Beispiel #2
0
    void OnGUI()
    {
        GUIStyle buttonStyle = new GUIStyle("button");

        buttonStyle.fontSize = 32;
        GUIStyle boxStyle = new GUIStyle("box");

        boxStyle.fontSize = 38;
        GUIStyle labelStyle = new GUIStyle("label");

        labelStyle.fontSize  = 18;
        labelStyle.alignment = TextAnchor.MiddleLeft;

        GUI.Box(new Rect(padding, boxY, boxWidth, boxHeight), "The Challenge", boxStyle);

        GUI.Label(new Rect(padding * 2, boxY + labelHeight * 2, labelWidth, labelHeight), "Challenge id:" + ChallengeId, labelStyle);
        GUI.Label(new Rect(padding * 2, boxY + labelHeight * 3, labelWidth, labelHeight), "Score to beat:" + ScoreToBeat, labelStyle);
        GUI.Label(new Rect(padding * 2, boxY + labelHeight * 4, labelWidth, labelHeight), "Score:" + Score, labelStyle);
        GUI.Label(new Rect(padding * 2, boxY + labelHeight * 5, labelWidth, labelHeight), "Results:" + ResultsDescription, labelStyle);
        GUI.Label(new Rect(padding * 2, boxY + labelHeight * 6, labelWidth, labelHeight), "Errors:" + Problems, labelStyle);

        if (ScoreReported)
        {
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 3 + boxY + padding * 3, buttonWidth, buttonHeight), "Back", buttonStyle))
            {
                Application.LoadLevel("MainMenu");
            }
        }
        else if (ChallengeAccepted)
        {
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 3 + boxY + padding * 3, buttonWidth, buttonHeight), "Play", buttonStyle))
            {
                int intScore = (int)UnityEngine.Random.Range(1f, 100f);
                Score = intScore.ToString();
                Arbiter.ReportScoreForChallenge(ChallengeId, Score, OnScoreReported, ErrorHandler);
            }
        }
        else
        {
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 2 + boxY + padding * 2, buttonWidth, buttonHeight), "Accept Custom", buttonStyle))
            {
                Arbiter.AcceptCashChallenge(ChallengeId, OnChallengeAccepted, ErrorHandler);
            }
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 3 + boxY + padding * 3, buttonWidth, buttonHeight), "Accept Default", buttonStyle))
            {
                Arbiter.AcceptCashChallengeUseNativeErrorDialogue(ChallengeId, OnChallengeAccepted, OnChallengeRejected);
            }
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 4 + boxY + padding * 4, buttonWidth, buttonHeight), "Reject", buttonStyle))
            {
                Arbiter.RejectCashChallenge(ChallengeId, OnChallengeRejected);
            }
        }

        if (ChallengeId != "Waiting")
        {
            if (GUI.Button(new Rect(padding * 2, buttonHeight * 5 + boxY + padding * 5, buttonWidth, buttonHeight), "Official Rules", buttonStyle))
            {
                Arbiter.ShowCashChallengeRules(ChallengeId, OnRulesClosed);
            }
        }
    }