Monday, April 20, 2015

How to set up google play services with unity plugin for android



below notes are taken directly from https://github.com/playgameservices/play-games-plugin-for-unity  webpage. here I copied that article,  only making a quick access for myself. Also I wrote some extra notes. For full page please goto https://github.com/playgameservices/play-games-plugin-for-unity website.

how to google play services with unity plugin:

First of all, build your game and upload it to google play services.



1) goto https://github.com/playgameservices/play-games-plugin-for-unity and clone git repository, or download and unzip the zip file.
2) find latest unity package, it is under the current_build directory, its name is something like "current-build/GooglePlayGamesPluginForUnity-X.YY.ZZ.unitypackage"
3) open the Android SDK manager and verify that you have downloaded the Google Play Services package. The Android SDK manager is usually available in your SDK installation directory, under the "tools" subdirectory, and is called android (or android.exe on Windows). The Google Play Services package is available under the Extras folder. If it is not installed or is out of date, install or update it before proceeding.
4) set up the path to your Android SDK installation in Unity. This is located in the preferences menu, under the External Tools section.
5) configure your game's package name. To do this, click File | Build Settings, select the Android platform and click Player Settings to show Unity's Player Settings window. In that window, look for the Bundle Identifier setting under Other Settings. Enter your package name there (for example com.example.my.awesome.game).
6) click the Window |Google Play Games|Setup - Android setup menu item. This will display the Android setup screen, where you must input your Application ID (e.g. 12345678012). You will get your application id from google services page. click the Setup button.

Important: The application ID and package name settings must match exactly the values you used when setting up your project on the Developer Console.


=======================


How to manage with your code:
-------------------------------
The Google Play Games plugin implements a subset of Unity's social interface. The standard API calls can be accessed through the Social.Active object, which is a reference to an ISocialPlatform interface. The non-standard Google Play Games extensions can be accessed by casting the Social.Active object to the PlayGamesPlatform class, where the additional methods are available.



Sign in:
------------------------------------------
To sign in, call Social.localUser.Authenticate, which is part of the standard Unity social platform interface.

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // authenticate user:
    Social.localUser.Authenticate((bool success) => {
        // handle success or failure
    });
Authentication will show the required consent dialogs. If the user has already signed into the game in the past, this process will be silent and the user will not have to interact with any dialogs.

Note that you cannot make any games API calls (unlock achievements, post scores, etc) until you get a successful return value from Authenticate, so it is good practice to put up a standby screen until the callback is called, to make sure the user can't start playing the game until the authentication process completes.

WARNING: dont forget to set googleplayservices ad default social platform!!!

void Awake () {
// Select the Google Play Games platform as our social platform implementation
GooglePlayGames.PlayGamesPlatform.Activate();
}
how to check if an user is logged in or not?
public bool isLoggedInGooglePlayServices() {
bool sonuc = false;
if(Social.localUser.authenticated) {
sonuc = true;
}
return sonuc;
}


Sign out
------------------------------------------
To sign the user out, use the PlayGamesPlatform.SignOut method.

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;

    // sign out
    PlayGamesPlatform.Instance.SignOut();
After signing out, no further API calls can be made until the user authenticates again.




Revealing/Unlocking an Achievement
------------------------------------------
To unlock an achievement, use the Social.ReportProgress method with a progress value of 100.0f:

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // unlock achievement (achievement ID "Cfjewijawiu_QA")
    Social.ReportProgress("Cfjewijawiu_QA", 100.0f, (bool success) => {
      // handle success or failure
    });
Notice that according to the expected behavior of Social.ReportProgress, a progress of 0.0f means revealing the achievement and a progress of 100.0f means unlocking the achievement. Therefore, to reveal an achievement (that was previously hidden) without unlocking it, simply call Social.ReportProgress with a progress of 0.0f.


If your achievement is incremental, the Play Games implementation of Social.ReportProgress will try to behave as closely as possible to the expected behavior according to Unity's social API, but may not be exact. For this reason, we recommend that you do not use Social.ReportProgress for incremental achievements. Instead, use the PlayGamesPlatform.IncrementAchievement method, which is a Play Games extension.

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // increment achievement (achievement ID "Cfjewijawiu_QA") by 5 steps
    PlayGamesPlatform.Instance.IncrementAchievement(
        "Cfjewijawiu_QA", 5, (bool success) => {
            // handle success or failure
    });




Showing the Achievements UI
------------------------------------------
To show the built-in UI for all achievements, call Social.ShowAchievementsUI.

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // show achievements UI
    Social.ShowAchievementsUI();
This will show a standard UI appropriate for the look and feel of the platform (Android or iOS).




Posting a Score to a Leaderboard
------------------------------------------
To post a score to a leaderboard, call Social.ReportScore.

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // post score 12345 to leaderboard ID "Cfji293fjsie_QA")
    Social.ReportScore(12345, "Cfji293fjsie_QA", (bool success) => {
        // handle success or failure
    });
Note that the platform and the server will automatically discard scores that are lower than the player's existing high score, so you can submit scores freely without any checks to test whether or not the score is greater than the player's existing score.




To show the built-in UI for all leaderboards, call Social.ShowLeaderboardUI.
------------------------------------------
    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // show leaderboard UI
    Social.ShowLeaderboardUI();
If you wish to show a particular leaderboard instead of all leaderboards, you can pass a leaderboard ID to the method. This, however, is a Play Games extension, so the Social.Active object needs to be cast to a PlayGamesPlatform object first:

    using GooglePlayGames;
    using UnityEngine.SocialPlatforms;
    ...
    // show leaderboard UI
    PlayGamesPlatform.Instance.ShowLeaderboardUI("Cfji293fjsie_QA");



There are more data about cloud saving, reading from cloud or multiplayer issues on https://github.com/playgameservices/play-games-plugin-for-unity page. Since I dont need them yet, I did not gather data for them here.


Wednesday, March 11, 2015

How to Increase Unity Game Performance

I found a nice article giving some tips to optimize your game made with Unity.

for the audio performance here is a rule of thumb:

  • Short Clips – Native
  • Longer (or looping) clips – compressed in memory
  • Music – Stream from disc
  • Files which consistently cause CPU spikes – Decompress on load
sÄ°NCE only one hardware audio stream can be decompressed at a time. Follow the rules above to cause CPU spikes. 


also be sure to check the full article on:
http://www.paladinstudios.com/2012/07/30/4-ways-to-increase-performance-of-your-unity-game/








Tuesday, March 10, 2015

mobile device screen resolutions for unity editor aspect ratios

iphone 4 portrait: 640x960
iphone 4 landscape: 960x640
iphone 6 landscape: 1136x640



for publishing to google game play here are the resolutions ofr 7 " tablet and 10 " tablet screen shots:

To help you target some of your designs for different types of devices, here are some numbers for typical screen widths:
  • 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
  • 480dp: a tweener tablet like the Streak (480x800 mdpi).
  • 600dp: a 7” tablet (600x1024 mdpi).
  • 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).

(from http://developer.android.com/guide/practices/screens_support.html#NewQualifiers)



well found a good site explaining all picture dimensions:
look at : http://xayin.com/thisisatest.html for more info.



more to come in time...

Monday, February 16, 2015

SOLVED: Error building Player: CommandInvokationFailure: Unable to retrieve device properties. Please make sure the Android SDK is installed and is properly configured in the Editor.

If you got an error saying "Error building Player: CommandInvokationFailure: Unable to retrieve device properties. Please make sure the Android SDK is installed and is properly configured in the Editor." well it is simple to solve that.

Just open windows Task Manager, and find "adb.exe".
 Right click on adb.exe and press "End Task" at the bottom of the window.

This will kill process adb.exe, and that is it.

Just  open unity and try to rebuild your game.

This happens especially if you are using a HTC mobile device.


If killing adb.exe process won't solve your problem, there is also a program  named as adbfix, but I did not tried it, try it at your own risk, here is the link:

http://visualgdb.com/adbfix/


anyway I have a HTC mobile device and with unity it sometimes says  "Error building Player: CommandInvokationFailure: Unable to retrieve device properties. Please make sure the Android SDK is installed and is properly configured in the Editor." When this happens I just reopen the task manager and kill adb.exe process then I will be able to build my game on my htc device.


Hope this helps someone.





Sunday, January 4, 2015

voxel art for games

voxel art is what minecrafting games look like. they are 3d but with pixels, like od style pixel arts but in 3d.

there are programs to do voxel art games like http://www.crossyroad.com/press game. They used voxelshop porgram called qubicle at the url : http://www.minddesk.com/.  You can also search for free options , a quick gogole search

1)  https://www.google.com.tr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=voxel+draw

2) https://www.google.com.tr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=best+voxel+drawing+tool

a free voxel art program : voxelshop :  http://blackflux.com/node/11

how to check google play services sha1 value - setting up google play services


find more info here: https://developers.google.com/games/services/console/enabling

here are some quck notes:
To get the release certificate fingerprint:
keytool -exportcert \
-alias <your-key-name> \
-keystore <path-to-production-keystore> \
-list -v
To get the debug certificate fingerprint:
keytool -exportcert \
-alias androiddebugkey \
-keystore <path-to-debug-keystore> \
-list -v


other links : 



https://developers.google.com/games/services/android/quickstart#step_3_modify_your_code


https://code.google.com/p/google-plus-platform/issues/detail?id=554


http://stackoverflow.com/questions/16580885/google-play-game-services-unable-to-sign-in

http://gmc.yoyogames.com/index.php?showtopic=581853&page=7

Friday, September 19, 2014

What is Vector2D, Vector2D magnitude, Vector2d.normalized? Learn all about Vectors and their normalized vectors, dot product and other necessary stuff.

Hi,

Today I will explain a little bit of Vectors and their properties. We have to learn a few things about Vectors, both in 2D and 3D because we do need them in Unity. By the way, I will give Vector2D functions and try to explain using them but these rules and functions also apply to Vector3 counterparts. Just replace Vector2D with "Vector3D" , the rest is all the same.

tip: learn this basic vector knowledge well, these will help you in the long run of Unity and game making business.

Lets summarry the main parts:
1) Vector2d logic and What Vector2.normalized and Vector2d magnitude value means?
2) Dot vector product.
3) How to and Why to compare them?

I will try to explain them step by step.


First of all, what is a normalized Vector means? 
By saying normalized vector, we are talking about a vector which has a length of 1 unit. It makes a vector bigger if it has a length smaller than 1 or makes a vector smaller if it's  original length bigger than 1.

Lets say we have a Vector2D named A, which is 2 points in x and 3 points in y, like this:
Vector2D A = new Vector2D(2,3);

if we get its normalized vector, we will use "normalized" function of Vector2D. Like this:
Vector2D B = A.normalized;

Now we get a B vector, which is just a smaller copy of the original A vector. BOTH vectors have the SAME DIRECTION! this is important to know. But normalized one is just a smaller copt of the original.

Because a normalized vector has a magnitude of 1. Always. Period.

Btw, is you dont know the term "magnitede" dont worry. Magnitude is just a fancy word for "length" in mathematics. So when you hear the word "magnitude" of a vector, just think it's LENGTH.

Lets be more clear, a normalized Vector has a length of 1, and has the same direction of the original vector.

here is a picture of a vector (shown as original vector) and it's normalized vector:



Lastly, some well-known normalized Vectors:

Vector2D.right : Vector2(1, 0) : a normalized vector to the right.
Vector2D.up : Vector2(0, 1) : a normalized vector to the up.

here is an imaginary images of  static normalized Vectors.



Now to the second step...

2) Vector DOT product: 

Dont tnik too much about this term. It just compares (usually) 2 normalized vectors. This is that dot product goodness is all about. You give 2 normalized (which means 2 vectors with a length of 1) to the dot function of Vector2D, and you get a comparizon of those 2 vectors. Since they do have the same lenght (they both have 1 unit lenght remember?) the only think that they can be compared to is their direction. When you Vector.Dot 2 vectors, you get a float number! So what does that float number symbolize, how can a comparison function gives you a float number and expects you to get that comparison from that number?

Well, The main trick here is how to read that float number.

First of all, dot function always gives a float number between -1 and +1. What ever you do, whichever 2 vectors you give, you will always get a  number between -1 and 1. So here comes the magic:

a) if 2 vectors  both do have exactly the same direction, then you get number +1;
b) if 2 vectors  have completely opposite directions, , then you get number -1;
c) if 2 vectors are perpendicular, then you get number 0.
d) you get different number  between +1 and -1 for other cases which gives us a clue of their position to each other.

are you getting the point?

You can compare two vectors directions by looking at Vector2D.Dot function, which the term comes "getting a dot product of two vectors".

An example image of Dot Product Results and different two vectors:




So you learned what s a magnitude, how to get a vectors normalized value, and how to compare two normalized vectors using Vector's Dot method (getting dot product and examining the float number) now you can do some neat stuff with this knowledge, like handlind and managing  SLIDE controllers.

On my next article, I will explain how can you capture slide gestures, tap and click on mobile screen and how to optimize slide and how to get which way user slides from and slides through.. Wont last long, so hope to see you soon.