Monday 8 May 2017

How to integrate google play services using unity

How to integrate google play service in a game successfully?

  1. Download the following for the future to use :-
    1. Download current build google play service plugin from github (https://github.com/playgameservices/play-games-plugin-for-unity)
      
     2. Open build settings from file menu - Switch to android so as to use google play service

     3. Then in the same build settings menu - open player setting it will be opened on the inspector in the right .
  1. Company name : TheRedAndBlack
  2. Product name : ActOfGod
  3. Go to other settings - type this in identification block
    1. Bundle Identifier : com.theredandblack.actofgod
    2. Bundle Version : 1.0.9(according to your current build version)
    3. API Level : 4.1(API level 16)
      d.  Go to publishing settings - create new keystore or if already there use existing keystore
i. Press browse keystore button and select the keystore then type the given keystore password
Ii. select alias from the key panel and create a new key. And select that key
Iii. then type the given password.
Note : to install a new keystore check the youtube video..
Please don’t copy the code provided in the video..

Now create a new c# script and type the following to just initiate the google play service authentication..
And attach it to the main camera.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class Login : MonoBehaviour {

void Awake(){
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate ();

}

// Use this for initialization
void Start () {
Social.localUser.Authenticate ((bool success) => {
});
}   }
Now you need to configure the plugin so as to use it for the present game .

>>Go to the windows - google play games - setup - android setup
>>In the resource definition box delete the previous code and constant class name and
paste the new code which you get in the google developer console by uploading your apk in the
google play services for more details check the video listed below.
After adding the app in the google developer console - now go to game services in the left -
go to achievements in the current game apk - add achievements and finally click on the
get resources - copy the code to the google play games
android configuration menu or also called resource definition in there .
Check this video for more clarity (https://www.youtube.com/watch?v=BhSJK-Kn8Uw&t=1268s)
Note : no need to give client id it creates a file GPGSId’s of that name thats it..
>>then click setup it will create a new GPGSId in the assets folder .. and so it is done..

Now build and check the system.


For deeper understanding check the following link:
https://codelabs.developers.google.com/codelabs/playservices_unity/index.html? index=..%2F..%2Findex#0

Monday 27 February 2017

Java installation process with path setting for unity

Firstly, This installation is for 64-bit, windows 10 OS.
For others also it is basically the same. But be sure with OS in your system[32 bit or 64 bit] while downloading JDK and JRE(These comes in Java file).

1) Now download the java installer from the web. Better from the site. Make sure the installer is supported in the os.

2) Install the java package but be aware of the location where you are installing it. Generally it is in C://Program Files/Java...

3) After installation is done, open the java folder and in which you will find 2 folders JDK and JRE.

4) now minimize the folder and open Control panel.

5) In "control panel" go to "System and Security" in which you will find "System" .

6) Inside the "System" you need to click on the "Advanced System Settings" which are generally on the left panel.

7) After you click on the panel you will see a window, Search for the "Environment Variable" button, in which you will find 2 sections a) user variable and b) system variable

8) Path Setting :-
                                 a) In "User Variable" table, Double click on the "path" and  there you will see a window with 2 input options.Now open the java folder which you have minimized and open "bin" file in "Jdk" folder, now copy the the location address from the on the top panel just below view button.And paste it in the "Variable value"  input text region and click ok.

                                 b) In "System Variables" table, Double click on the "CLASSPATH" row and you will see another window poping up named as "Edit Environment Variable".Now open the java folder which you have minimized and open "lib" file in the "jre" folder and copy the "location address".Now click on the "New" button in "Edit Environment Variable" and paste the location address copied from "lib" in "jre" folder into the new row and click on "ok".

9) Click on "ok" in the "Environmental Variables" and close "control panel".

10) Now try to compile and run the ".java" program that you wrote from "command prompt" to check whether its working or not.


here is the screenshots :-














Sunday 1 January 2017

Hoe to get user data from facebook unity CSharp



Here is script for getting user data like first_name, last_name, gender, email and photo from facebook

you can also get friend data from this...

Here is link to get Unity facebook SDK and more detail process :-
 https://developers.facebook.com/docs/unity/gettingstarted


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Facebook.Unity;

public class FBLoginScript : MonoBehaviour {

public Image photo_base;
public Text id_base;
public Text fname_base;
public Text lname_base;
public Text gender_base;
public Text email_base;

void Awake () {
if (!FB.IsInitialized) {
FB.Init(InitCallback, OnHideUnity);
} else {
FB.ActivateApp();
}
}
private void InitCallback ()
{
if (FB.IsInitialized) {
FB.ActivateApp();
} else {
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void OnHideUnity (bool isGameShown)
{
if (!isGameShown) {
Time.timeScale = 0;
} else {
Time.timeScale = 1;
}
}


List<string> perms = new List<string>(){"public_profile", "email", "user_friends"};


private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
Debug.Log(aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log(perm);
}
} else {
Debug.Log("User cancelled login");
}
}

public void LogInButton()
{
FB.LogInWithReadPermissions(perms, AuthCallback);
}
public void LogOutButton()
{
FB.LogOut ();
Debug.Log("User logged out");
}
public void GetMailIDButton()
{
FB.API("/me?fields=id,first_name,last_name,gender,email", HttpMethod.GET, graphCallback);
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, ProfilePhotoCallback);
//FB.API("/me/friends?fields=id,name", HttpMethod.GET, FriendInfoCallback);
FB.API("/me/friends?fields=id,first_name,picture.width(128).height(128)&limit=100", HttpMethod.GET, FriendInfoCallback);
//FB.API("/me?fields=email,friends.limit(10).fields(first_name,id)", HttpMethod.GET, FriendInfoCallback);

}
void FriendInfoCallback(IGraphResult result)
{
Debug.Log("hi= "+result.RawResult);
object dataList;
if (result.ResultDictionary.TryGetValue("data", out dataList))
{
var friendsList = (List<object>)dataList;
CacheFriends(friendsList);
Debug.Log("friendsList= "+Friends);

for(int i=0;i < Friends.Count;i++)
{
Debug.Log(Friends[i]);
}
}

}
public static List<object> Friends;
public static Dictionary<string, Texture> FriendImages = new Dictionary<string, Texture>();

private static void CacheFriends (List<object> newFriends)
{
if (Friends != null && Friends.Count > 0)
{
Friends.AddRange(newFriends);
}
else
{
Friends = newFriends;
}
}

void ProfilePhotoCallback(IGraphResult result)
{
photo_base.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0),125);
}
private void graphCallback(IGraphResult result)
{
Debug.Log("hi= "+result.RawResult);
string id;
string firstname;
string lastname;
string gender;
string email;
if (result.ResultDictionary.TryGetValue("id", out id))
{
id_base.text = "ID = " + id.ToString();
}
if (result.ResultDictionary.TryGetValue("first_name", out firstname))
{
fname_base.text = "firstname= "+firstname.ToString();
}
if (result.ResultDictionary.TryGetValue("last_name", out lastname))
{
lname_base.text = "lastname= "+lastname.ToString();
}
if (result.ResultDictionary.TryGetValue("gender", out gender))
{
gender_base.text = "gender= "+gender.ToString();
}
if (result.ResultDictionary.TryGetValue("email", out email))
{
email_base.text = "email= "+email.ToString();
}

}
}




You can get FB_user_Access token by clicking the "Find Access Token" then paste into field
Click Send Success 

Above testing process is for unity editor... you can login directly form your mobile ... 

Thursday 29 December 2016

How to Delete Canvas Panel Child Objects

1. You need to calculate the number of child objects
2. Use loops to get child one by one delete the using Destroy method.



Method 1 :-
========
if (InfoButtonPanel.transform.childCount >= 0) {
     Transform[] allChildren = InfoButtonPanel.transform.GetComponentsInChildren<Transform>();
foreach (var item in allChildren) {
Destroy (item.transform.gameObject);
}
}


Method 2 :-
========
if (InfoButtonPanel.transform.childCount >= 0) {
     for (int i = 0; i < InfoButtonPanel.transform.childCount; i++) {
    GameObject.Destroy(InfoButtonPanel.transform.GetChild(i).gameObject);
}
}

Canvas Button On Click Code

Button.onClick.AddListener


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ButtonController : MonoBehaviour {
public Button myButton;

void Awake()
{
myButton = GetComponent<Button>();
myButton.onClick.AddListener( () => {myFunctionForOnClickEvent("stringValue", 4.5f);} );
}

void myFunctionForOnClickEvent(string arg1, float arg2)
{
print(arg1 + ", " + arg2.ToString());
}
}



You can also remove Listener() using below code on Destroy Function

void Destroy()
{
myButton.onClick.RemoveListener(() => {myFunctionForOnClickEvent("stringValue", 4.5f);});
}



Monday 26 December 2016

how to get key-hashes for android facebook app


Here is the command :-
=================
Open you Command Prompt  and run below command to get keyhash
Note* :- You need to enter your key store password

keytool -exportcert -alias bowmen -keystore "C:\Users\Red&Black\Downloads\bowmenuserkeystore.keystore" | "C:\openssl\bin\openssl" sha1 -binary |"C:\openssl\bin\openssl" base64

You can get openssl from below link :-
===============================
https://code.google.com/archive/p/openssl-for-windows/downloads



Thursday 28 July 2016

How to delete persistent Data Path file




1.  Attack ClearSaveButton function to your delete Button.


Name Spaces maybe requires :-

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Runtime.Serialization.Formatters.Binary;
using System;
using System.IO;

public void ClearSaveButton()
{
ClearDataCanvas.enabled = false;
if (File.Exists (Application.persistentDataPath + "/playerInfo.dat"))
{
 
File.Delete(Application.persistentDataPath + "/playerInfo.dat");

Application.Quit ();
}
}