Exemplo n.º 1
0
    public void OnGPGCloudLoadResult(string result)
    {
        // result is in the format result;keyNum;length
        // where result is either success/conflict/error
        // keyNum is the key for which this result is 0-3 range as per GPG
        // length is the length of data received from GPG Cloud. Important for binary data handling
        // NOTE: In this code we are only saving/loading STRING data. but it should be fine to use it for any binary data
        Debug.Log("OnGPGCloudLoadResult " + result);
        string[] resArr = result.Split(';');
        if (resArr.Length < 3)
        {
            Debug.LogError("Length of array after split is less than 3");
            return;             // weird stuff
        }
        int keyNum = System.Convert.ToInt16(resArr[1]);

        if (resArr[0] == "success")
        {
            // lets see what our data holds.
            byte[] data = NerdGPG.Instance().getKeyLoadedData(keyNum);
            string str  = System.Text.Encoding.Unicode.GetString(data);
            Debug.Log("Data read for key " + resArr[1] + " is " + str + " with len " + resArr[2] + " and converted string length is " + str.Length);
            dataToSave = str;
        }
    }
Exemplo n.º 2
0
        public void Authenticate(System.Action <bool> callback)
        {
            authCB = callback;

            NerdGPG.Instance().init();
            NerdGPG.Instance().signIn(Authresponse);
        }
Exemplo n.º 3
0
        public void LoadAchievementDescriptions(Action <IAchievementDescription[]> callback)
        {
            acDescCB      = callback;
            loadACForDesc = true;

            NerdGPG.Instance().loadAchievements(OnACLoadCB);
        }
 public void _Toggle()
 {
     if (NerdGPG.Instance().isSignedIn())
     {
         Debug.Log("has logined...");
         if (signInButton != null)
         {
             signInButton.active = false;
         }
         if (signOutButton != null)
         {
             signOutButton.active = true;
         }
     }
     else
     {
         Debug.Log("has logouted...");
         if (signInButton != null)
         {
             signInButton.active = true;
         }
         if (signOutButton != null)
         {
             signOutButton.active = false;
         }
     }
 }
Exemplo n.º 5
0
        public void LoadAchievements(Action <IAchievement[]> callback)
        {
            acCB          = callback;
            loadACForDesc = false;

            NerdGPG.Instance().loadAchievements(OnACLoadCB);
        }
Exemplo n.º 6
0
 public void AchivementShow()
 {
     Social.ShowAchievementsUI();
     // See if we have loaded the achievement list
     if (NerdGPG.Instance().acList == null)
     {
         GUI.enabled = false;
     }
     else
     {
         // Check if the achievement we are trying to increment is in the ac list
         foreach (IAchievement ac in NerdGPG.Instance().acList)
         {
             if (ac.id == testIncAchievement)
             {
                 currACPercent = ac.percentCompleted;
             }
         }
     }
     // If we didnt find the achievement or if its already unlocked disable the increment button
     if (currACPercent < 0 || currACPercent >= 100)
     {
         Debug.Log(" Can't find or it's already Unlocked.");
     }
 }
Exemplo n.º 7
0
        void Authresponse(bool result)
        {
            authenticated = result;

            id       = NerdGPG.Instance().getPlayerID();
            userName = NerdGPG.Instance().getPlayerName();

            authCB(result);
        }
Exemplo n.º 8
0
 public void LeaderBoardShow()
 {
     Debug.Log("In Leaderboards");
     if (Social.localUser.authenticated)
     {
         Debug.Log("In Leaderboards");
         NerdGPG.Instance().showLeaderBoards(testLeaderBoard);
     }
 }
Exemplo n.º 9
0
 public void OnSubmitAC(bool result)
 {
     Debug.Log("GPGUI: OnSubmitAchievement " + result);
     if (result == true)
     {
         NerdGPG.Instance().haveLoadedAc = false;
         Social.LoadAchievements(OnLoadAC);
     }
 }
    public void Awake()
    {
        #if UNITY_IPHONE
        clientId = iOSClientId;
        #elif UNITY_ANDROID
        clientId = androidClientId;
        #endif

        NerdGPG.Instance().init(clientId, "GooglePlayServicesManager");
        DontDestroyOnLoad(this.gameObject);
    }
    IEnumerator SignIn()
    {
        yield return(new WaitForSeconds(0.5f));

        #if UNITY_IPHONE
        // ios のときは silent authentication を利用
        NerdGPG.Instance().signInSilently();
        #elif UNITY_ANDROID
        // android はゲーム開始時に自動ログインを行わない
        #endif
    }
Exemplo n.º 12
0
    public static NerdGPG Instance()
    {
        if(m_Instance!=null)
            return m_Instance;
        Debug.Log("NerdGPG instance not found. Creating new one");

        GameObject owner = new GameObject("NerdGPG");
        m_Instance = owner.AddComponent<NerdGPG>();
        DontDestroyOnLoad(m_Instance);
        return m_Instance;
    }
Exemplo n.º 13
0
    public static NerdGPG Instance()
    {
        if (m_Instance != null)
        {
            return(m_Instance);
        }
        Debug.Log("NerdGPG instance not found. Creating new one");

        GameObject owner = new GameObject("NerdGPG");

        m_Instance = owner.AddComponent <NerdGPG>();
        DontDestroyOnLoad(m_Instance);
        return(m_Instance);
    }
Exemplo n.º 14
0
 void OnACLoadCB()
 {
     if (loadACForDesc)
     {
         if (acDescCB != null)
         {
             acDescCB(NerdGPG.Instance().acDescList.ToArray());
         }
     }
     else
     {
         if (acCB != null)
         {
             acCB(NerdGPG.Instance().acList.ToArray());
         }
     }
 }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit rayHit;
         var        ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out rayHit, 100))
         {
             var googleLoginCube = rayHit.collider.gameObject;
             if (googleLoginCube.name != "GoogleLoginCube")
             {
                 return;
             }
             NerdGPG.Instance().signIn();
         }
     }
 }
Exemplo n.º 16
0
    public void loadFromCloud(int keyNum, Action <string> onLoad)
    {
        CBOnCloudLoad = onLoad;
#if UNITY_IPHONE
        try {
            switch (keyNum)
            {
            case 0:
                GCHandle handle = GCHandle.Alloc(key0CloudData, GCHandleType.Pinned);
                NerdGPG.GPG_LoadFromCloud(keyNum, handle.AddrOfPinnedObject(), key0CloudData.Length);
                handle.Free();
                break;

            case 1:
                GCHandle handle1 = GCHandle.Alloc(key1CloudData, GCHandleType.Pinned);
                NerdGPG.GPG_LoadFromCloud(keyNum, handle1.AddrOfPinnedObject(), key1CloudData.Length);
                handle1.Free();
                break;

            case 2:
                GCHandle handle2 = GCHandle.Alloc(key2CloudData, GCHandleType.Pinned);
                NerdGPG.GPG_LoadFromCloud(keyNum, handle2.AddrOfPinnedObject(), key2CloudData.Length);
                handle2.Free();
                break;

            case 3:
                GCHandle handle3 = GCHandle.Alloc(key3CloudData, GCHandleType.Pinned);
                NerdGPG.GPG_LoadFromCloud(keyNum, handle3.AddrOfPinnedObject(), key3CloudData.Length);
                handle3.Free();
                break;
            }
        }
        catch (Exception e) {
            Debug.LogException(e);
        }

        Debug.LogError("Invlaid keynum " + keyNum + " given or gc was unable to pin");
#elif UNITY_ANDROID
        mNerdGPG.Call("loadFromCloud", keyNum);
#endif
    }
Exemplo n.º 17
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit rayHit;
            var        ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out rayHit, 100))
            {
                var go = rayHit.collider.gameObject;
                if (go.name != "LeaderBoardSphere2")
                {
                    return;
                }

                NerdGPG.Instance().showLeaderBoards(
                    GooglePlayServicesManager.Instance.GetLeaderBoardId(
                        (int)GooglePlayServicesManager.LEADER_BOARD.TWO
                        )
                    );
            }
        }
    }
Exemplo n.º 18
0
    void DoMyWindow(int windowID)
    {
        // GUILayout.Label("Tap anywhere to give direction to the pumpkin.\nYou can give direction only after the pumpkin touches the platform.\nYour primary objecive is to prevent pumpkin from falling into the fire.\n");
        //GUI.skin = guiskin;

        //if (windowID == 0)
        {
            if (GUILayout.Button(leaderboardBtn, GUILayout.Height(100)))
            {
                //NerdGPG.GPG_ShowLeaderBoards(testLeaderBoard);
                NerdGPG.Instance().showLeaderBoards(testLeaderBoard);
            }
        }
        //else if(windowID == 1)
        {
            if (GUILayout.Button(achievmentsBtn, GUILayout.Height(100)))
            {
                //	NerdGPG.GPG_ShowAchievements();
                //NerdGPG.Instance().showAchievements();
                Social.ShowAchievementsUI();
            }
            //  else
            {
                if (GUILayout.Button(logoutBtn, GUILayout.Height(100)))
                {
                    //NerdGPG.GPG_SignOut();

                    NerdGPG.Instance().signOut();
                    SceneManager.LoadScene("Win_Scene");
                }
            }
        }/*
          *  if (GUILayout.Button("GPG_UnlockAC", GUILayout.Height(120)))
          *  {
          *      Social.ReportProgress(testAchievement, 100.0, OnUnlockAC);
          *  }*/
    }
Exemplo n.º 19
0
 public void ShowAchievementsUI()
 {
     NerdGPG.Instance().showAchievements();
 }
Exemplo n.º 20
0
    void OnGUI()
    {
        GUILayout.Label("Unity GPG Plugin Demo");
        GUILayout.Space(20);
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Init GPG", GUILayout.Height(60)))
        {
            Debug.Log("Init called");

            //NerdGPG.GPG_SetGameObjectName(name);
            //NerdGPG.GPG_Init(clientId);
            //NerdGPG.Instance().setGameObjectName(name);
            NerdGPG.Instance().init(clientId, name);
        }
        if (GUILayout.Button("Silent SignIn", GUILayout.Height(60)))
        {
            Debug.Log("Silent Signin called");
            //needFullSignin = !NerdGPG.GPG_TrySilentSignIn();
            NerdGPG.Instance().signIn();
        }

        /*
         * if(needFullSignin) {
         *      if(GUILayout.Button("SignIn", GUILayout.Height(60))) {
         *              Debug.Log("Signin called");
         *              NerdGPG.GPG_SignIn();
         *      }
         * }*/
        if (m_loginState == GPLoginState.loggedin)
        {
            if (GUILayout.Button("SignOut", GUILayout.Height(60)))
            {
                //NerdGPG.GPG_SignOut();
                NerdGPG.Instance().signOut();
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (m_loginState == GPLoginState.loggedin)
        {
            // we are logged in. we can do leaderboard and achievement and cloud stuff
            if (GUILayout.Button("GPG_ShowAllLeaderBoards", GUILayout.Height(60)))
            {
                //NerdGPG.GPG_ShowAllLeaderBoards();
                NerdGPG.Instance().showAllLeaderBoards();
            }
            if (GUILayout.Button("GPG_ShowLeaderBoards", GUILayout.Height(60)))
            {
                //NerdGPG.GPG_ShowLeaderBoards(testLeaderBoard);
                NerdGPG.Instance().showLeaderBoards(testLeaderBoard);
            }

            if (GUILayout.Button("GPG_ShowAchievements", GUILayout.Height(60)))
            {
                //	NerdGPG.GPG_ShowAchievements();
                NerdGPG.Instance().showAchievements();
            }

            if (GUILayout.Button("GPG_SubmitScore", GUILayout.Height(60)))
            {
                //	NerdGPG.GPG_SubmitScore(testLeaderBoard,80);
                NerdGPG.Instance().submitScore(testLeaderBoard, 80);
            }
            if (GUILayout.Button("GPG_UnlocAchievement", GUILayout.Height(60)))
            {
                //	NerdGPG.GPG_UnlocAchievement(testAchievement);
                NerdGPG.Instance().unlockAchievement(testAchievement);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            dataToSave = GUILayout.TextField(dataToSave, 100);
            if (GUILayout.Button("GPG_SaveToCloud", GUILayout.Height(60)))
            {
                Debug.Log("Saving to cloud");
                byte[] bytes = new byte[dataToSave.Length * sizeof(char)];
                System.Buffer.BlockCopy(dataToSave.ToCharArray(), 0, bytes, 0, bytes.Length);
                NerdGPG.Instance().saveToCloud(0, bytes);
                //	NerdGPG.GPG_SaveToCloud(0,bytes,bytes.Length);
            }
            if (GUILayout.Button("GPG_LoadFromCloud", GUILayout.Height(60)))
            {
                Debug.Log("Loading from cloud for key 0");
//				NerdGPG.GPG_LoadFromCloud(0,bytes,bytes.Length);
                NerdGPG.Instance().loadFromCloud(0);
//				GCHandle handle = GCHandle.Alloc(key0CloudData,GCHandleType.Pinned);
                //	NerdGPG.GPG_LoadFromCloud(0,handle.AddrOfPinnedObject(),key0CloudData.Length);
                //handle.Free();
            }
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("GPG_HasAuthoriser", GUILayout.Height(60)))
        {
            Debug.Log("HasAuthoriser result " + NerdGPG.Instance().isSignedIn());
        }
        GUILayout.EndVertical();
    }
Exemplo n.º 21
0
        public void ReportProgress(string achievementID, double progress, Action <bool> callback)
        {
            Debug.Log("GPGSocial - ReportProgress");

            NerdGPG gpgInst = NerdGPG.Instance();

            if (gpgInst.acList == null || gpgInst.acList.Count == 0)
            {
                Debug.Log("GPGSocial - ReportProgress failed: " + gpgInst.acList);
                callback(false);
                return;
            }

            bool foundAc = false;

            for (int i = 0; i < gpgInst.acList.Count; i++)
            {
                if (gpgInst.acList[i].id == achievementID)
                {
                    if (gpgInst.acExtraData[i].state == (int)GPGACState.State_Unlocked)
                    {
                        Debug.Log("GPGSocial - ReportProgress failed: AlreadyUnlocked ");
                        callback(false);
                        return;
                    }

                    foundAc = true;

                    if (gpgInst.acExtraData[i].type == (int)GPGACType.Type_Standard)
                    {
                        if (progress != 100)
                        {
                            Debug.LogError("Reported progress other then 100 to a standard achievement. Unlocking Anyways");
                        }
                        else
                        {
                            gpgInst.unlockAchievement(achievementID, callback);
                        }
                    }
                    else if (gpgInst.acExtraData[i].type == (int)GPGACType.Type_Incremental)
                    {
                        int stepsCompleted = (int)(gpgInst.acList[i].percentCompleted * (double)gpgInst.acExtraData[i].totalSteps / 100.0);

                        if (stepsCompleted != gpgInst.acExtraData[i].currSteps)
                        {
                            Debug.LogWarning("Calculated steps for achievement and known steps dont match! Calculated Steps: " + stepsCompleted + " Known: " + gpgInst.acExtraData[i].currSteps);
                        }

                        int newSteps            = (int)(progress * (double)gpgInst.acExtraData[i].totalSteps / 100.0);
                        int finalStepsIncrement = newSteps - stepsCompleted;

                        Debug.Log("PrevSteps: " + stepsCompleted + "  newSteps: " + newSteps + " TotalSteps: " + gpgInst.acExtraData[i].totalSteps);

                        gpgInst.incrementAchievement(achievementID, finalStepsIncrement, callback);
                    }
                }
            }

            if (!foundAc)
            {
                Debug.Log("GPGSocial - ReportProgress failed: DidntFindAC ");
                callback(false);
            }
        }
Exemplo n.º 22
0
 public void ReportScore(long score, string board, Action <bool> callback)
 {
     NerdGPG.Instance().submitScore(board, score, callback);
 }
Exemplo n.º 23
0
 public void LogOutButton()
 {
     NerdGPG.Instance().signOut();
     UserNotSignedIn();
 }
Exemplo n.º 24
0
    void OnGUI()
    {
        GUILayout.Label("Unity GPG Plugin Demo");
        GUILayout.Space(20);
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("SignIn", GUILayout.Height(120)))
        {
            Debug.Log("Signin called");
            //needFullSignin = !NerdGPG.GPG_TrySilentSignIn();
            //NerdGPG.Instance().signIn();

            Social.localUser.Authenticate(OnAuthCB);
        }

        /*
         * if(needFullSignin) {
         *      if(GUILayout.Button("SignIn", GUILayout.Height(60))) {
         *              Debug.Log("Signin called");
         *              NerdGPG.GPG_SignIn();
         *      }
         * }*/
        if (m_loginState == GPLoginState.loggedin)
        {
            if (GUILayout.Button("SignOut", GUILayout.Height(120)))
            {
                //NerdGPG.GPG_SignOut();
                NerdGPG.Instance().signOut();
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (Social.localUser.authenticated)
        {
            // we are logged in. we can do leaderboard and achievement and cloud stuff
            if (GUILayout.Button("GPG_ShowAllLeaderBoards", GUILayout.Height(120)))
            {
                //NerdGPG.GPG_ShowAllLeaderBoards();
                //NerdGPG.Instance().showAllLeaderBoards();
                //NerdGPG.Instance().loadAchievements(true);
                Social.ShowLeaderboardUI();
            }
            if (GUILayout.Button("GPG_ShowLeaderBoards", GUILayout.Height(120)))
            {
                //NerdGPG.GPG_ShowLeaderBoards(testLeaderBoard);
                NerdGPG.Instance().showLeaderBoards(testLeaderBoard);
            }

            if (GUILayout.Button("GPG_SubmitScore", GUILayout.Height(120)))
            {
                //	NerdGPG.GPG_SubmitScore(testLeaderBoard,80);
                //NerdGPG.Instance().submitScore(testLeaderBoard,80, null);
                Social.ReportScore(80, testLeaderBoard, OnSubmitScore);
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("GPG_ShowAchievements", GUILayout.Height(120)))
            {
                //	NerdGPG.GPG_ShowAchievements();
                //NerdGPG.Instance().showAchievements();
                Social.ShowAchievementsUI();
            }

            // See if we have loaded the achievement list
            if (NerdGPG.Instance().acList == null)
            {
                GUI.enabled = false;
            }
            else
            {
                // Check if the achievement we are trying to increment is in the ac list
                foreach (IAchievement ac in NerdGPG.Instance().acList)
                {
                    if (ac.id == testIncAchievement)
                    {
                        currACPercent = ac.percentCompleted;
                    }
                }
            }

            // If we didnt find the achievement or if its already unlocked disable the increment button
            if (currACPercent < 0 || currACPercent >= 100)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("GPG_IncrementAC- " + (currACPercent) + "%", GUILayout.Height(120)))
            {
                Debug.Log("Clicked On Increment Button");
                int stepsCompleted = (int)(currACPercent * (double)testIncACTotalSteps / 100.0f);
                stepsCompleted   += 1;
                onReportACPercent = stepsCompleted * 100.0f / testIncACTotalSteps;
                Debug.Log("Increment by : " + onReportACPercent);
                Social.ReportProgress(testIncAchievement, onReportACPercent, OnSubmitAC);
            }

            GUI.enabled = true;

            if (GUILayout.Button("GPG_UnlockAC", GUILayout.Height(120)))
            {
                Social.ReportProgress(testAchievement, 100.0, OnUnlockAC);
            }

            if (GUILayout.Button("GPG_LoadACDesc", GUILayout.Height(120)))
            {
                Social.LoadAchievementDescriptions(OnLoadACDesc);
            }
            if (GUILayout.Button("GPG_LoadAC", GUILayout.Height(120)))
            {
                Social.LoadAchievements(OnLoadAC);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            dataToSave = GUILayout.TextField(dataToSave, 100);
            if (GUILayout.Button("GPG_SaveToCloud", GUILayout.Height(120)))
            {
                Debug.Log("Saving to cloud");
                byte[] bytes = new byte[dataToSave.Length * sizeof(char)];
                System.Buffer.BlockCopy(dataToSave.ToCharArray(), 0, bytes, 0, bytes.Length);
                NerdGPG.Instance().saveToCloud(0, bytes);
                //	NerdGPG.GPG_SaveToCloud(0,bytes,bytes.Length);
            }
            if (GUILayout.Button("GPG_LoadFromCloud", GUILayout.Height(120)))
            {
                Debug.Log("Loading from cloud for key 0");
//				NerdGPG.GPG_LoadFromCloud(0,bytes,bytes.Length);
                NerdGPG.Instance().loadFromCloud(0);
//				GCHandle handle = GCHandle.Alloc(key0CloudData,GCHandleType.Pinned);
                //	NerdGPG.GPG_LoadFromCloud(0,handle.AddrOfPinnedObject(),key0CloudData.Length);
                //handle.Free();
            }
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("GPG_HasAuthoriser", GUILayout.Height(120)))
        {
            Debug.Log("HasAuthoriser result " + NerdGPG.Instance().isSignedIn());
        }

        if (Social.localUser.authenticated)
        {
            GUILayout.Label(Social.localUser.userName + " is signed in. ID: " + Social.localUser.id);
        }

        GUILayout.EndVertical();
    }
Exemplo n.º 25
0
 public void ShowLeaderboardUI()
 {
     NerdGPG.Instance().showAllLeaderBoards();
 }