<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Paladin Studios</title>
	<atom:link href="http://www.paladinstudios.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paladinstudios.com</link>
	<description>Games that make you smile</description>
	<lastBuildDate>Thu, 02 Feb 2012 10:13:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Happy Holidays!</title>
		<link>http://www.paladinstudios.com/2011/12/23/happy-holidays-2/</link>
		<comments>http://www.paladinstudios.com/2011/12/23/happy-holidays-2/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 10:20:10 +0000</pubDate>
		<dc:creator>Derk</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[chistmas card]]></category>
		<category><![CDATA[holidays]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=2045</guid>
		<description><![CDATA[By now your mailbox is probably full of Christmas cards and season&#8217;s greetings. Here&#8217;s one more, handcrafted with love, to say thanks for your support. (click the image to check out the full-sized version) For us, 2011 has an incredible year &#8211; one of new beginnings, cool projects, and a clear sense of direction. We [...]]]></description>
			<content:encoded><![CDATA[<p>By now your mailbox is probably full of Christmas cards and season&#8217;s greetings. Here&#8217;s one more, handcrafted with love, to say thanks for your support.</p>
<p><a href="http://www.paladinstudios.com/resources/paladin_holidays_2011.jpg"><img class="alignnone size-full wp-image-2046" title="PaladinChristmasCard2011_blogsize" src="http://www.paladinstudios.com/wp-content/uploads/2011/12/PaladinChristmasCard2011_blogsize.jpg" alt="" width="600" height="401" /></a><br />
<em>(click the image to check out the full-sized version)</em></p>
<p>For us, 2011 has an incredible year &#8211; one of new beginnings, cool projects, and a clear sense of direction.</p>
<ul>
<li>We started working on Momonga, a Pinball Adventure game coming out on iOS and Android in 2012.</li>
<li>The paladin <a href="http://www.paladinstudios.com/">website</a> got a complete redesign, with a new focus on our self-published games</li>
<li>Together with our clients and partners we launched the music game <a href="http://www.oorkania.nl/">Oorkania</a>, the augmented reality toolkit <a href="http://www.hom3decorator.com/">Hom3Decorator</a>, and the urban planning toolkit <a href="http://www.ibisapps.nl/producten/metropolis/">Metropolis</a></li>
<li>We started working on a project which involves&#8230; wait for it&#8230; lamas and biofeedback. More on that soon ;-)</li>
</ul>
<p>We also said goodbye to our good friend Dylan Nagel, co-founder of Paladin, who started his consultancy company <a href="http://www.wldcrd.com/">Wildcard</a>. In addition, we &#8220;upgraded&#8221; the corporate structure to a BV with a holding, and signed our first global distribution deals. It has been a rollercoaster ride.</p>
<p>Looking forward to 2012, we see some exciting things around the corner. Next year we will launch our biggest game yet &#8211; Momonga. This is nerve-wracking, as we don&#8217;t have a clue on how this thing will turn out. However, with your enthusiasm and support we got the spirit to push forward and get this game out there. So again, thank you four your support.</p>
<p>All that said, let&#8217;s get ready for some more adventures in 2012! Here&#8217;s to an awesome New Year, may it be all that you hope for.</p>
<p>Cheers :-)<br />
Derk, Niels, Yorick, Tijmen, Lukas, Jimmy, Tedo and Judith</p>
<p>PS: If you want to follow our adventures, be sure to check us out on <a href="http://www.twitter.com/paladinstudios">Twitter</a>, <a href="http://www.facebook.com/paladinstudios">Facebook</a>, our <a href="http://www.paladinstudios.com/blog/">blog</a> and our<a href="http://eepurl.com/hjNq">Newsletter</a> :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/12/23/happy-holidays-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Facebook and Unity Tutorial &#8211; Part Three</title>
		<link>http://www.paladinstudios.com/2011/12/06/facebook-and-unity-tutorial-part-three/</link>
		<comments>http://www.paladinstudios.com/2011/12/06/facebook-and-unity-tutorial-part-three/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 09:37:37 +0000</pubDate>
		<dc:creator>Tijmen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1892</guid>
		<description><![CDATA[A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should check this out. And stay tuned for other blog posts. ;) [...]]]></description>
			<content:encoded><![CDATA[<p><em>A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should <a href="http://cuteoverload.com/" target="_blank">check this out</a>. And stay tuned for other blog posts. ;)</em></p>
<p>The Facebook game we built in <a title="Facebook and Unity Tutorial – Part One" href="http://www.paladinstudios.com/2011/11/15/facebook-and-unity-tutorial-part-one/" target="_blank">part one</a> and <a title="Facebook and Unity Tutorial – Part Two" href="http://www.paladinstudios.com/2011/11/24/facebook-and-unity-tutorial-part-two/" target="_blank">part two</a> works fairly well at the moment, although it&#8217;s not very exciting. Facebook profile pictures are visible, and we can store and retrieve highscores successfully. However we also saw Mark Zuckerberg having a very suspicious highscore by rolling 7 with a 6 sided dice. In this part we&#8217;ll learn how to modify our own scores, and prevent malicious users from doing so.</p>
<p>But first a disclaimer: <strong>Creating a 100% secure application is not possible. </strong>Just look at any major game released the last several years, they all include some copy protection but its just a matter of time before they are hacked. Hackers are a very creative, and they will always find new innovative ways to exploit your program and make your life miserable.  So in a way, the only thing you are doing is making it harder for malicious users to cheat in your game, completely preventing it now and in the future is sadly impossible.</p>
<h2>Hacking your own game</h2>
<p>To understand security you have to step towards the dark side too, and learn how to &#8216;hack&#8217; your application. We&#8217;ll focus on one way how Mark Zuckerberg could have modified his score in this tutorial. There are other subjects of security such as copy protection that arent covered.</p>
<p>Webdevelopers have several tools available to them to debug and test their applications, such as <a href="http://getfirebug.com/">Firebug</a> and the built in <a href="http://code.google.com/chrome/devtools/docs/console.html">Chrome Developer Tools</a>. These tools are vital to a webdeveloper, as they allow insights to websites a normal user wont see. However we, a malicious user, could also use these tools to inspect how an application works and modify its execution, such as modifying scores. I&#8217;ll be using Firebug in the following samples, but any other web-debugger will do.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/inspect.png"><img class="alignright size-medium wp-image-1899" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/inspect-400x424.png" alt="" width="283" height="300" /></a></p>
<p>Start Firebug and go to the net tab. This will show any external calls being made, and resources being loaded. If you load the page with the net tab open you&#8217;ll see the Unity3d file being loaded, facebook images being requested and even our own webservice being called. Anyone can inspect this and find out where your webservice is located and how you use it. Try it out, play the game with the net tab open and you&#8217;ll see the insert_highscore request being made. Malicious users could visit the URL manually, supplying their Facebook id and any score they desire like what we did to test our service!</p>
<p>We need a way to verify that what we send from unity and receive in our backend is untouched and exactly the same. Again, 100% protection is impossible, but we can at least make it harder for the attacker. The way we verify the request is by one-way-hashing the parameters we send, and validating the hash serverside. One way hashing means using a algorithm like MD5 or SHA1 to convert one string in another, but this process is not reversible. For example; the MD5 hash of &#8216;Monkey&#8217; is &#8220;<em>4126964b770eb1e2f3ac01ff7f4fd942</em>&#8220;, but &#8216;Donkey&#8217; will turn into &#8220;<em>046d93852f6419ac27a74b4ebcaa32e4</em>&#8220;. Eventhough the original is very similar their hash is completely different. We can use this to our advantage by calculating the hash of the data we send, send that along the original data to the server and then compare the hash we got with the one we generate again at the server. For example:</p>
<div>
<ol>
<li>Append the Facebook ID and score, use a seperation character and append another secret key for added security. For example: <strong>100000229612727_4_paladinrules</strong>.</li>
<li>Hash the appended data and send it along with the original data. Our sample hash would be <strong>3b707fdc8d8f54c27a543b16a68efcf7</strong>.</li>
<li>On the server do the same process, append the data we recieve and our secret key. Verify the hashes are the same.</li>
</ol>
<p>Now if the evil Mark would attempt to change his score the hashes wont match, and we can reject the request completely. Enough talk; lets implement our theory!</p>
<p>Modify <em>insert_highscore.php</em> to add hashing:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
 mysql_connect('localhost','root',''); //Setup database connection
 mysql_select_db('highscores');
 $score = @$_GET['score'];
 $fbid = @$_GET['fbid'];
 $request_hash = @$_GET['hash'];

 if(!$score || !$fbid || !$request_hash ) //Make sure we get all input
 	die(&quot;No fbid, score or hash&quot;); 	

 $data = $fbid . &quot;_&quot; . $score . &quot;_paladinrules&quot;; //Hash it up using our format fbid_score_paladinrules
 $hash = md5($data); //Hash it up!
 if(strtolower($hash) != strtolower($request_hash)) //The hashes are different, the request is invalid.
 {
  echo &quot;Invalid request!&quot;;
 } else { //it seems legit, lets insert it!
  mysql_query(&quot;INSERT INTO scores (fbid, score) VALUES ('$fbid', $score)&quot;);
} ?&gt;
</pre>
<p>As you can see, we now also expect another GET parameter called `Hash` to be passed and compare that to the hash we calculate. When it matches we happily trust the input and insert it, otherwise we show a message to scare off any attackers. Hashes should be case insensitive because some implementations of MD5 capitalize the output and others dont.</p>
<p>Modify DiceGame&#8217;s submitHighscore to include the hash:</p>
<pre class="brush: csharp; title: ; notranslate">
    IEnumerator submitHighscore(int score, string fbid)
    {
        string hash = md5(fbid + &quot;_&quot; + score + &quot;_paladinrules&quot;);
        WWW webRequest = new WWW(&quot;http://localhost/insert_highscore.php?score=&quot; + score + &quot;&amp;fbid=&quot; + fbid + &quot;&amp;hash=&quot;+ hash);
        yield return webRequest;

        yield return retrieveHighscores(); //After we submit we'd want an update, perhaps someone else played too!
    }
    private string md5(string input)
    {
        // step 1, calculate MD5 hash from input
        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
        byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
        byte[] hash = md5.ComputeHash(inputBytes);

        // step 2, convert byte array to hex string
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i &lt; hash.Length; i++)
        {
            sb.Append(hash[i].ToString(&quot;X2&quot;));
        }
        return sb.ToString();
    }
</pre>
<p>It is very similar, albeit MD5 is a bit more tricky but luckily C# is <a href="http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx">well documented</a>. We hash the parameters using the format we&#8217;ve made up, and send it to the server.</p>
<p>Build your game and play it, then try to alter your score as you&#8217;ve done before. You&#8217;ll see the hashes wont be the same, and your score will be rejected. This approach will keep most script-kiddies out, however its only a matter of time before a malicious user figures your secret format out and would be able to generate the hashes themselves. You could further complicate your security model by for example adding another secret key which is user specific, or using a different hashing algorithm.</p>
<p>Even though we are now secure from some basic forms of attacks, we cant rejoice yet. There are plenty of others ways to hack and cheat in your application, and there are always new ways being explored too. You should be especially scared about <a href="http://en.wikipedia.org/wiki/Sql_injection">SQL Injection</a>, which is the number one most commonly used attack on websites. Although theoretically if you cant alter the values you send to the server, you&#8217;d rather be safe then sorry.</p>
<p>This concludes the tutorial about Facebook and Unity. I hope you enjoyed it! Please let us know what you think in the comments or the <a href="http://forum.unity3d.com/threads/112072-Unity-amp-Facebook-intergration" target="_blank">Unity forum topic</a>.</p>
<p>Tijmen van den Heuvel<br />
Paladin Studios</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/12/06/facebook-and-unity-tutorial-part-three/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Facebook and Unity Tutorial &#8211; Part Two</title>
		<link>http://www.paladinstudios.com/2011/11/24/facebook-and-unity-tutorial-part-two/</link>
		<comments>http://www.paladinstudios.com/2011/11/24/facebook-and-unity-tutorial-part-two/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 09:30:37 +0000</pubDate>
		<dc:creator>Tijmen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1821</guid>
		<description><![CDATA[&#160; A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should check this out. And stay tuned for other blog posts. [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><span class="Apple-style-span" style="font-size: 13px; font-weight: normal;"><em>A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should <a href="http://cuteoverload.com/" target="_blank">check this out</a>. And stay tuned for other blog posts. ;)</em></span></p>
<p><span class="Apple-style-span" style="font-size: 13px; font-weight: normal;"><em></em>In part two of our series about connecting facebook and unity we&#8217;ll learn the following:</span></p>
<ul>
<li>Sending and storing highscores.</li>
<li>Retrieving highscores.</li>
<li>Display scores and facebook profile picture.</li>
</ul>
<div>If you havent already, you should read <a href="http://www.paladinstudios.com/2011/11/11/facebook-and-unity-part-one/">part one</a> first.</div>
<h2>To make a game</h2>
<p>In order to get a highscore we&#8217;ll need to make a game. For the demonstration we&#8217;ll be creating something <em>very</em> simple, but you should be able to use the lessons learned to implement facebook and highscores in your own games. We&#8217;ll be creating a dice rolling game, where the user has to click a button to roll a random number.</p>
<p>Create a new project and add the following script:</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;pre&gt;public class DiceGame : MonoBehaviour
{
    public static string FacebookId = &quot;1&quot;; //We'll link up with FacebookManager later.
    private const int max = 6; //Max score, the sides on the dice
    private string btnText = &quot;Press to roll&quot;;
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 200, 50), btnText))
        {
            int score = UnityEngine.Random.Range(1, max + 1); //Calculate our score.
            btnText = string.Format(&quot;You rolled {0}, \nclick to try again.&quot;, score);

            StartCoroutine(submitHighscore(score, FacebookId));
        }

    }

    IEnumerator submitHighscore(int score, string fbid)
    {
    	yield return null; //We'll implement this later.
    }
}
</pre>
<p>Nothing fancy there, just a button that when clicked generates a random number and starts our mysterious submitHighscore coroutine. This method should do a webrequest to insert the highscores, so lets create the webservice first!</p>
<h2>Creating the webservices</h2>
<p>In order to store our scores we&#8217;ll need a webservice with a database. Luckily we already have a webserver running locally, we can use that to test. Start by creating a simple database.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/dbdesign.png"><img class="alignright size-full wp-image-1824" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/dbdesign.png" alt="" width="176" height="109" /></a>We&#8217;ll need to store our users facebook id, score and it would be nice to know the creationdate too. Create your database by going to <a href="http://localhost/phpmyadmin/">PHPMyadmin</a>, make a new database called `highscores` and run the following SQL to generate the database:</p>
<pre class="brush: sql; title: ; notranslate">

CREATE TABLE `highscores`.`scores` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`fbid` TEXT NOT NULL ,
`score` INT NOT NULL ,
`creation_date` TIMESTAMP NOT NULL
) ENGINE = INNODB;
</pre>
<p>Now we have our database setup lets create the script that will insert our highscores; create a new file called <em>insert_highscore.php </em>in your WWW directory<em>.  </em></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

	mysql_connect('localhost','root',''); //Connect to the databsae
	mysql_select_db('highscores');

	$score = @$_GET['score'];
	$fbid = @$_GET['fbid'];

	if(!$score || !$fbid) //Ensure both parameters are passed
		die(&quot;No fbid or score&quot;);

	mysql_query(&quot;INSERT INTO scores (fbid, score) VALUES ('$fbid', $score)&quot;); //Execute the query
?&gt;
</pre>
<p>The first 2 lines connect to the database server and select the proper database. Next we validate the input, and stop executing if either score or fbid was not supplied. After we&#8217;re sure they exist we insert them in the database using SQL.<br />
Great, visit your page at <a href="http://localhost/insert_highscore.php?fbid=4&amp;score=1">http://localhost/insert_highscore.php?fbid=4&amp;score=1</a>, and verify that there is a new row in the database by going to PhpMyAdmin and clicking on Browse in your scores table.<a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/data.png"><img class="alignright size-full wp-image-1931" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/data.png" alt="" width="354" height="212" /></a></p>
<p>Now we can insert, we&#8217;ll need a way to retrieve the scores too. Create a new page with the name <em>get_highscores.php. </em>We dont want to get all highscores from a user, just the highest one. This is where <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html">GROUP BY</a> comes in handy.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

	mysql_connect('localhost','root','');
	mysql_select_db('highscores');

	$scoresQuery = mysql_query(&quot;SELECT
									MAX(score) as max_score,
									fbid
								FROM
									scores
								GROUP BY
									fbid
								ORDER BY
									max_score DESC&quot;);

	while($scoresRow = mysql_fetch_assoc($scoresQuery))
		echo $scoresRow['fbid'] . ',' . $scoresRow['max_score'] . &quot;\n&quot;;

?&gt;
</pre>
<p>It connects to the database again, and executes the query. It then outputs each row as follows:</p>
<p>fbid,score<br />
fbid,score<br />
etc..</p>
<p>Check it out by going to <em><a href="http://localhost/get_highscores.php">http://localhost/get_highscores.php</a>. </em>If required you can add more highscores by going back to insert_highscore.php. Try using different facebook id&#8217;s too, you&#8217;ll see more rows being displayed by get_highscores.</p>
<h2>Inserting data</h2>
<p>Now we have the webservices ready we should be able to call them from our Unity game.</p>
<pre class="brush: csharp; title: ; notranslate">

private Dictionary&lt;string, int&gt; scores; //The key is the facebook id, value is his score.

void Start()
{
    scores = new Dictionary&lt;string, int&gt;();
    StartCoroutine(retrieveHighscores()); //Start out by getting the current scores.
}
IEnumerator submitHighscore(int score, string fbid)
{
	WWW webRequest = new WWW(&quot;http://localhost/insert_highscore.php?score=&quot; + score + &quot;&amp;fbid=&quot; + fbid);
	yield return webRequest;

	yield return retrieveHighscores(); //After we submit we'd want an update, perhaps someone else played too!
}
IEnumerator retrieveHighscores()
{
	WWW webRequest = new WWW(&quot;http://localhost/get_highscores.php&quot;);
	yield return webRequest;

	string[] lines = webRequest.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); //Split the response by newlines.

	scores = new Dictionary&lt;string, int&gt;(); //Always reset our scores, as we just got new ones.
	foreach (string line in lines) //Parse every line
	{
		string[] parts = line.Split(',');

		string id = parts[0];
		int score = int.Parse(parts[1]);

		scores.Add(id,score);
	}
}
</pre>
<p>Great, we call the webpages using Unity&#8217;s built in <a href="http://unity3d.com/support/documentation/ScriptReference/WWW.html">WWW</a> class with the proper GET parameters. Whenever you post highscores it will automaticly retrieve them too. There is some parsing going on again in <em>retrieveHighscores</em>, namely we split them by each line and then by comma.<br />
Our Dictionary contains the scores, with the facebook id as key and their highest score as value.</p>
<p>Drag the script on a gameobject in your scene and try it out in the Editor. Validate everything is working properly by clicking the button a few times and then check if there are new rows added in the database.</p>
<h2>Linking Facebook</h2>
<p>Our game now stores and retrieves highscores properly , but lets link it up with Facebook. Lets create a FacebookManager to retrieve the ID:</p>
<pre class="brush: csharp; title: ; notranslate">
public class FacebookManager : MonoBehaviour
{
    void Start()
    {
        Application.ExternalCall(&quot;GetCurrentUser&quot;);
    }
    public void GetCurrentUserComplete(string fbid)
    {
        DiceGame.FacebookId = fbid;
    }
}
</pre>
<p>Stick it on a GameObject named FacebookManager and make a web build. Modify the WebPlayer.html to implement the Facebook SDK:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;

&lt;script type='text/javascript'&gt;

	//Fired when the facebook sdk has loaded
	window.fbAsyncInit = function()
	{
		FB.init(
		{
		  appId      : '171298766297727',
		  status     : true, // check login status
		  cookie     : true, // enable cookies to allow the server to access the session
		  oauth      : true, // enable OAuth 2.0
		  xfbml      : false // dont parse XFBML
		});

		//Get the current login status.
		FB.getLoginStatus(function(loginStatusResponse)
		{
			if(!loginStatusResponse.authResponse) //Not logged in, log him in
				FB.login();
		});

	};

	function GetCurrentUser() //When we are logged in this shows our name.
	{
		FB.api('/me', function(meResponse)	//Do a graph request to /me
		{
			getUnity().SendMessage(&quot;FacebookManager&quot;, //Game object name, make sure this exists!
									&quot;GetCurrentUserComplete&quot;, //Method to call
									meResponse.id); //Our serialized facebook data
		});
	}

	//Load the Facebook JS SDK
	(function(d){
	 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	 js = d.createElement('script'); js.id = id; js.async = true;
	 js.src = &quot;//connect.facebook.net/en_US/all.js&quot;;
	 d.getElementsByTagName('head')[0].appendChild(js);
	}(document));

	function getUnity()
	{
		if (typeof unityObject != &quot;undefined&quot;)
		{
			return unityObject.getObjectById(&quot;unityPlayer&quot;);
		}
		return null;
	}
	if (typeof unityObject != &quot;undefined&quot;)
	{
		unityObject.embedUnity(&quot;unityPlayer&quot;, &quot;WebPlayer.unity3d&quot;, 960, 640);
	}
&lt;/script&gt;

&lt;div id='unityPlayer'&gt;&lt;/div&gt;
</pre>
<p>Open the page and press the button a few times, then go to your database and you&#8217;ll see your Facebook ID inserted correctly!</p>
<p>The next step is to do something with the facebook id&#8217;s we store, lets show the user&#8217;s profile image. As per the <a href="https://developers.facebook.com/docs/reference/api/">Facebook Graph API</a> you can get a users image with the following url: <a href="http://graph.facebook.com/4/picture/">http://graph.facebook.com/UID/picture/</a></p>
<p>Change your retrieve highscores to this:</p>
<pre class="brush: csharp; title: ; notranslate">
private Dictionary&lt;string, Texture2D&gt; fbProfileImages = new Dictionary&lt;string, Texture2D&gt;();
    IEnumerator retrieveHighscores()
    {
        WWW webRequest = new WWW(&quot;http://localhost/fbblog/p2/get_highscores.php&quot;);
        yield return webRequest;

        string[] lines = webRequest.text.Split(new string[] { &quot;\n&quot; }, StringSplitOptions.RemoveEmptyEntries);

        scores = new Dictionary&lt;string, int&gt;(); //Always reset our scores, as we just got new ones.
        foreach (string line in lines)
        {
            string[] parts = line.Split(',');

            string id = parts[0];
            int score = int.Parse(parts[1]);

            if (!fbProfileImages.ContainsKey(id)) //Have we already loaded this user before?
            {
                //No, better get our image!
                WWW imageRequest = new WWW(&quot;http://graph.facebook.com/&quot; + id + &quot;/picture&quot;);
                yield return imageRequest;
                fbProfileImages.Add(id, imageRequest.texture);
            }

            scores.Add(id,score);
        }
    }
</pre>
<p>And change your OnGUI to:</p>
<pre class="brush: csharp; title: ; notranslate">
   void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 200, 50), btnText))
        {
            int score = UnityEngine.Random.Range(1, max + 1);
            btnText = string.Format(&quot;You rolled {0}, \nclick to try again.&quot;, score);

            StartCoroutine(submitHighscore(score, FacebookId));
        }

        float h = 10;
        foreach (var score in scores)
        {
            GUI.Label(new Rect(300, h, 200, 50), score.Value.ToString());

            if (fbProfileImages != null &amp;&amp; fbProfileImages.ContainsKey(score.Key))
                GUI.DrawTexture(new Rect(230, h, 50, 50), fbProfileImages[score.Key]);

            h += 60;
        }
    }
</pre>
<p>The fbProfileImages dictionary keeps track of the profile Textures, they get loaded whenever a new user is found. Build and run the project again, and be amazed how easy it is to retrieve someone&#8217;s Facebook profile picture.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/result1.png"><img class="aligncenter size-full wp-image-1930" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/result1.png" alt="" width="322" height="249" /></a></p>
<blockquote><p>A great result, but there&#8217;s something fishy. Mark Zuckerberg has rolled 7 with a 6 sided dice! In the next part we&#8217;ll find out how he did it, and protect ourself against several common attacks used by malicious users.</p></blockquote>
<p><a href="http://paladinstudios.com/facebook_blogpost/paladin_facebook_parttwo.zip">Download complete project.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/11/24/facebook-and-unity-tutorial-part-two/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Level Designs for Momo</title>
		<link>http://www.paladinstudios.com/2011/11/18/level-designs-for-momo/</link>
		<comments>http://www.paladinstudios.com/2011/11/18/level-designs-for-momo/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 12:41:41 +0000</pubDate>
		<dc:creator>Derk</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[level design]]></category>
		<category><![CDATA[momo]]></category>
		<category><![CDATA[momonga]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1976</guid>
		<description><![CDATA[By now you know that we are working hard on our new game, Momo Pinball. We follow the adventures of our hero Momo, a little momonga who has to rescue his friends from a bunch of evil owls. This is not your regular flipper game: instead of playing a traditional cabinet with lots of lights, bells and [...]]]></description>
			<content:encoded><![CDATA[<p>By now you know that we are working hard on our new game, <em>Momo Pinball</em>. We follow the adventures of our hero Momo, a little <a href="http://www.google.nl/search?q=momonga" target="_blank">momonga</a> who has to rescue his friends from a bunch of evil owls.</p>
<p>This is not your regular flipper game: instead of playing a traditional cabinet with lots of lights, bells and whistles, you play through different levels in an epic adventure. There is a storyline, enemies, end bosses &#8211; the whole enchilada!</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip.png"><img class="size-full wp-image-1999 alignnone" title="ScreenClip" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-e1321617886497.png" alt="" width="600" height="421" /></a></p>
<p><em>Above: A part of level 4, viewed from the Unity editor</em></p>
<p>All these levels are great, but they all need to be designed. To raise the stakes, the quality of the levels determines if this game is going to be any good. So how do you tackle this? How do you go from a simple idea to a level that is both fun and good-looking?</p>
<h1>Doodles</h1>
<p>In the early parts of development, we start with a blank sheet of paper (or Photoshop canvas) and simply start doodling. You can see some doodles below. They are simple sketches, a platform for ideas. We start with the abstract layout and add the level visuals on top of that.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/Mockup-Level-3-01.jpg"><img class="size-full wp-image-1981 alignnone" title="Mockup - Level 3 - 01" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/Mockup-Level-3-01.jpg" alt="" width="202" height="145" /></a><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/Level-1-Mockup-1.jpg"><img class="size-full wp-image-1982 alignnone" title="Level 1 - Mockup 1" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/Level-1-Mockup-1.jpg" alt="" width="113" height="184" /></a><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/Mockup-Tutorial-Level-01.jpg"><img class="alignnone" title="Mockup - Tutorial Level 01" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/Mockup-Tutorial-Level-01-1024x771.jpg" alt="" width="239" height="179" /></a></p>
<p>This is a fairly solid start &#8211; you have some basic ideas and a sketch conveys most information you need for building the level. However, as we progress in the level design process, it we need a more formal approach to make sure the quality of the levels is consistent.</p>
<h1>Patterns</h1>
<p>The problem with pinball games is that the level design is heavily focused around the spatial quality of the level. The ball has blind spots and sweet spots, and the way you shape your level outlines determines the difficulty of the level. This is essential for the player experience: If you don&#8217;t get that right, the level will be a failure. You need to be tweaking an infinite number of parameters: It can be a matter of changing the slope angle, size of the level, or obstacle positions. Even small changes can have big effects.</p>
<p>You can&#8217;t sketch this out, because it requires experimentation. Along the way we have discovered some basic &#8220;rules&#8221; of how a level should be constructed. This is why we started working with <em>patterns</em>: Little pieces of a level that we have found to work well. To discover a pattern, we execute small, focused experiments that should result in good gameplay. When an experiment passes the test, we add it to our pattern library.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/pattern1.jpg"><img title="pattern1" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/pattern1.jpg" alt="" width="264" height="189" /></a><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-8.png"><img class="size-full wp-image-2002 alignnone" title="Pattern 1 in action" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-8-e1321618541337.png" alt="" width="300" height="196" /></a></p>
<p><em>Above: A pattern test sketch, and the pattern test in action.</em></p>
<p>Think of it as a lego construction kit. Patterns are like simple blueprints that have proven to give good effects, and by stringing these blueprints together, you can create longer levels with more complex gameplay. Once you have the basic rules in place, you can play around and modify things to make each level a different experience.</p>
<h1>Piecing it together</h1>
<p>When you have the collision models and layout ready, the next step is to add the visuals. We look at the storyline, in particular in which part of the world this level should play out. There is a balance here, where the levels we create shape the world, but the world also shapes the levels. There is an overarching storyline that we use as a guideline, but this is not carved in stone. The fun factor is much more important, so if we have a good idea we will build it and adjust the storyline if necessary.</p>
<p>Here are some screenshots of some of the levels, made by Jimmy de Meza, the lead artist for Momo Pinball. Enjoy! :)</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-2.png"><img class="size-full wp-image-2005 alignnone" title="Level 4 end area" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-2-e1321618851249.png" alt="" width="600" height="388" /></a></p>
<p><em>Above: The end section of level 4 as seen from the Unity editor</em></p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-1.png"><img class="size-full wp-image-2008 alignnone" title="Level 1 Start" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/ScreenClip-1.png" alt="" width="600" height="450" /></a></p>
<p><em>Above: The start of level 1, viewed from a distance</em></p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/Momonga-screenie-1.jpg"><img class="alignnone size-full wp-image-2009" title="Momonga - screenie 1" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/Momonga-screenie-1-e1321619200334.jpg" alt="" width="600" height="452" /></a></p>
<p><em>Above: The start of level 1, as seen from inside the game (with the old user interface)</em></p>
<p>What do you think so far? Are we on the right track? Please let us know in the comments!</p>
<p>PS: We are going to publish a public alpha soon! Stay tuned by signing up to our <a href="http://eepurl.com/hjNq" target="_blank">newsletter</a> (make sure you select the preview option) - or follow us on <a href="http://www.twitter.com/paladinstudios" target="_blank">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/11/18/level-designs-for-momo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Facebook and Unity Tutorial &#8211; Part One</title>
		<link>http://www.paladinstudios.com/2011/11/15/facebook-and-unity-tutorial-part-one/</link>
		<comments>http://www.paladinstudios.com/2011/11/15/facebook-and-unity-tutorial-part-one/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 09:36:08 +0000</pubDate>
		<dc:creator>Tijmen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1789</guid>
		<description><![CDATA[Introduction A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should check this out. And stay tuned for other blog [...]]]></description>
			<content:encoded><![CDATA[<h1></h1>
<h1></h1>
<h1></h1>
<h1></h1>
<h1></h1>
<h1><span class="Apple-style-span" style="font-size: 20px">Introduction</span></h1>
<p><em>A note before you start: This is a Unity tutorial about implementing Facebook in Unity projects. It&#8217;s a technical how-to guide for Unity developers who want to use Facebook Connect in their web-apps. If that sounds interesting, read on! If it does not, you should <a href="http://cuteoverload.com/" target="_blank">check this out</a>. And stay tuned for other blog posts. ;)</em></p>
<p>Paladin&#8217;s games allow players to play with their friends, using  Facebook. In this 3-part series we&#8217;ll learn how to connect our Unity application with Facebook, show highscores of our friends and how to secure our application.</p>
<blockquote><p><strong>Warning!</strong> Tech up ahead, this is not for the feint of heart!</p></blockquote>
<p>In this introductory post we&#8217;ll create a FB application, use the Javascript SDK to retrieve the current user&#8217;s friends and display their name in Unity. This task requires some familiarity with webdevelopment, and good understanding of Unity and C#. A sneak preview of the final game we&#8217;ll be making can be <a href="http://teampaladin.com/facebook_blogpost/final.html" target="_blank">viewed here</a>.</p>
<h2>Setting up your application and development environment</h2>
<p>To get started, register your application over at <a href="https://developers.facebook.com/apps">Facebook</a>. Do note you need to have a &#8220;developer account&#8221;, which means you have to supply your phone number. After creating your application you have to tell Facebook its a webpage, by clicking on Website at <strong>Select how your  app intergrates with Facebook</strong>. For now you can set your Site URL to <em>http://localhost/</em>. This allows you to test your application locally. Another notable setting is Sandbox mode, in the Advanced tab. When this is on only developers can view the application, this is useful when developing the application. Dont forget to turn it off though!</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/setup.png"><img class="size-medium wp-image-1800 alignright" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/setup-400x162.png" alt="" width="300" height="121" /></a></p>
<p>Because we want to develop locally, we want to run a webserver on our own machine. If you dont have one installed, you can use a simple package like <a href="http://www.wampserver.com/">Wampserver</a> or <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a>. Ensure your webserver is working properly by visiting <a href="http://localhost">http://localhost</a> in your browser. We at Paladin mainly use PHP for our backend, but if you feel more comfortable using any other technology (ASP, RoR etc) feel free to use that.</p>
<h2>Exploring the Facebook SDK</h2>
<p>Now we have that setup, lets play around with the Facebook API. To familiarise ourselfs with the Facebook Graph lets create a sample page that gets all information we want. Facebook works using <a href="https://developers.facebook.com/docs/reference/api/">Graph</a> which allows easy access to all information of a user, as long as he is logged in and has granted you enough permissions. We strongly encourage you to read the documentation thoroughly. We&#8217;ll be using the Javascript SDK, you should <a href="https://developers.facebook.com/docs/reference/javascript/">read through</a> the documentation. For our sample we want to get the current user&#8217;s id and name, and his friends. Create an html page in your www-root with the following contents:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt; &lt;!-- Required by Facebook --&gt;

&lt;script type='text/javascript'&gt;

	//Fired when the facebook sdk has loaded
	window.fbAsyncInit = function()
	{
		FB.init(
		{
		  appId      : '171298766297727',
		  status     : true, // check login status
		  cookie     : true, // enable cookies to allow the server to access the session
		  oauth      : true, // enable OAuth 2.0
		  xfbml      : false // dont parse XFBML
		});

		//Get the current login status.
		FB.getLoginStatus(function(loginStatusResponse)
		{
			if(loginStatusResponse.authResponse) //There is an authresponse, the user is already logged in and authenticated
			{
				logUserName();
				logFriends();

			} else { //The user was not logged in, allow him to.
				FB.login(function(loginResponse)
				{
					if(loginResponse.authRespsonse) //Did he login successfully?
					{
						logUserName();
						logFriends();
					}
				});
			}
		});

		function logUserName() //When we are logged in this shows our name.
		{
			FB.api('/me', function(meResponse)	//Do a graph request to /me
			{
				alert(meResponse.id + &quot; &quot; + meResponse.first_name); //Show the response
			});
		}

		function logFriends()	//When we are logged in this shows our friends.
		{
			FB.api('/me/friends', function(friendResponse) //Do a graph request to my friends.
			{
				for(var i = 0; i &lt; friendResponse.data.length; i++) //Loop over all my friends
					alert(friendResponse.data[i].id + &quot; &quot; + friendResponse.data[i].name);
			});
		}

	};

	//Load the Facebook JS SDK
	(function(d){
	 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	 js = d.createElement('script'); js.id = id; js.async = true;
	 js.src = &quot;//connect.facebook.net/en_US/all.js&quot;;
	 d.getElementsByTagName('head')[0].appendChild(js);
	}(document));

&lt;/script&gt;
</pre>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/login.png"><img class="size-medium wp-image-1807 alignright" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/login-400x156.png" alt="" width="300" height="117" /></a>After loading the Facebook library it will check the current user&#8217;s login status, and offer a login if he isnt already. When we&#8217;re sure we are logged we use the graph request to <strong>/me</strong> to get information about the current user. Then we request the user&#8217;s friends by doing a request to <strong>/me/friends. </strong>Use a Javascript Debugger such as Firebug and step through the code to understand how it works, and what responses the Facebook api requests give.</p>
<h2>Bringing it to Unity</h2>
<p>Now we have the information we want in our webpage, lets pass it on to Unity! Unity&#8217;s excellent <a href="http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html">reference manual</a> describes how to send basic messages from and to your game. Lets create a button that will ask the HTML page to get the facebook info. Create a new Unity project and create a new script called FacebookManager. Add the following code:</p>
<pre class="brush: csharp; title: ; notranslate">
void OnGUI()
{
    if (GUI.Button(new Rect(10, 10, 100, 24), &quot;Get info&quot;))
         Application.ExternalCall(&quot;GetCurrentUser&quot;)
    if (GUI.Button(new Rect(10, 44, 100, 24), &quot;Get friends&quot;))
         Application.ExternalCall(&quot;GetUserFriends&quot;)
}
</pre>
<p>When the user clicks the button the Javascript function <em>GetCurrentUser</em> is called, simple as that. We already know how to get the information from Facebook, now all we need to do is pass it on to our game. We do this by calling <a href="http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html">SendMessage</a> to the proper GameObject and Method.  There is however a drawback, SendMessage only supports sending a single parameter to Unity, which is insufficient because we want to send a user&#8217;s facebook id and name. Therefore we have to come up with some format to pass both parameters. For larger data structures i&#8217;d strongly recommend using JSON, and interpeting it in your game. However, since this is a simple sample, we&#8217;ll just come up with our own format as such:</p>
<p><strong>id,name; id, name;</strong></p>
<p>Lets rewrite our basic page into something we can use.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;

&lt;script type='text/javascript'&gt;

	//Fired when the facebook sdk has loaded
	window.fbAsyncInit = function()
	{
		FB.init(
		{
		  appId      : '171298766297727',
		  status     : true, // check login status
		  cookie     : true, // enable cookies to allow the server to access the session
		  oauth      : true, // enable OAuth 2.0
		  xfbml      : false // dont parse XFBML
		});

		//Log the user in when the page loads.
		FB.getLoginStatus(function(loginStatusResponse)
		{
			if(!loginStatusResponse.authResponse) //Not logged in, log him in
				FB.login();
		});

		function GetCurrentUser() //When we are logged in this shows our name.
		{
			FB.api('/me', function(meResponse)	//Do a graph request to /me
			{
				var fbdata = meResponse.id + &quot;,&quot; + meResponse.first_name; //As per our format, 'id,name;'

				getUnity().SendMessage(&quot;FacebookManager&quot;, //Game object name, make sure this exists!
										&quot;GetCurrentUserComplete&quot;, //Method to call
										fbdata); //Our serialized facebook data
			});
		}

		function GetUserFriends()
		{
			FB.api('/me/friends', function(friendResponse)
			{
				var fbdata;

				for(var i = 0; i &lt; friendResponse.data.length; i++) //Loop over all my friends
					fbdata += friendResponse.data[i].id + &quot;,&quot; + friendResponse.data[i].name + ';';

				getUnity().SendMessage(&quot;FacebookManager&quot;,
										&quot;GetFriendsComplete&quot;,
										fbdata);
			});
		}
	};

	//Load the Facebook JS SDK
	(function(d){
	 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	 js = d.createElement('script'); js.id = id; js.async = true;
	 js.src = &quot;//connect.facebook.net/en_US/all.js&quot;;
	 d.getElementsByTagName('head')[0].appendChild(js);
	}(document));

	function getUnity() //Default unity functions
	{
		if (typeof unityObject != &quot;undefined&quot;)
		{
			return unityObject.getObjectById(&quot;unityPlayer&quot;);
		}
		return null;
	}
	if (typeof unityObject != &quot;undefined&quot;)
	{
		unityObject.embedUnity(&quot;unityPlayer&quot;, &quot;WebPlayer.unity3d&quot;, 960, 640);
	}
&lt;/script&gt;

&lt;div id='unityPlayer'&gt;&lt;/div&gt;
</pre>
<p>Please note additional work has to be done in case the user declines the request or graph requests fail, but that is outside the scope of the tutorial.</p>
<p>Now we&#8217;ve retrieved the data in our page, lets make sure we can accept it in our game. Add this to your script, and attach it to a GameObject called FacebookManager.</p>
<pre class="brush: csharp; title: ; notranslate">
    private string user_id; //Facebook id
    private string user_name; //User name
    private Dictionary&lt;string, string&gt; friends; //All the users friends key = id, value = name

    public void GetCurrentUserComplete(string fbdata) //Called by js when the userinfo was retrieved. fbdata looks like 1234,name
    {
        string[] parts = fbdata.Split(',');
        user_id = parts[0];
        user_name = parts[1];
    }
    public void GetFriendsComplete(string fbdata) //Called by js when the friends are retrieved. fbdata looks like 1234,name;5678,name;..
    {
        friends = new Dictionary&lt;string, string&gt;();

        string[] parts = fbdata.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); //we've seperated each user, now get their id and name

        foreach (string user in parts)
        {
            string[] userInfo = user.Split(','); //Split each user on ',' first should be id then name.

            friends.Add(userInfo[0], userInfo[1]);
        }
    }

    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 100, 24), &quot;Get info&quot;))
            Application.ExternalCall(&quot;GetCurrentUser&quot;);
        if (GUI.Button(new Rect(10, 44, 100, 24), &quot;Get friends&quot;))
            Application.ExternalCall(&quot;GetUserFriends&quot;);

        GUI.Label(new Rect(200, 10, 200, 24), user_name); //Display name

        if (friends != null) //If we retrieved our friends already
        {
            float h = 10;
            foreach (var friend in friends)
            {
                GUI.Label(new Rect(200, 10 + i * 24, 200, 24), friend.Value);
                h += 24;
            }
        }
     }
</pre>
<p>The code should be fairly self-explanatory, the parsing part can be a bit tricky as it is very error prone. Any unexpected input will break your application. If you arent sure whats going on, try setting breakpoints and using our friendly Debug.Log method to make some sence of it. All our hard work leads us to this; a screen with our current name and the names of our friends:</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/result.png"><img class="aligncenter size-full wp-image-1919" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/result.png" alt="" width="425" height="262" /></a></p>
<p>Great, now you know how to setup your Facebook development environment, make basic calls to the Graph API and pass the response to Unity. With the knowledge you&#8217;ve gained, think you can open a <a href="https://developers.facebook.com/docs/reference/dialogs/">post to wall dialog</a> from unity?</p>
<blockquote><p>Stay tuned for the next part where we&#8217;ll learn how to post highscores, and show the scores and profile pictures of our friends!</p></blockquote>
<p><a href="http://paladinstudios.com/facebook_blogpost/paladin_facebook_partone.zip">Download complete project.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/11/15/facebook-and-unity-tutorial-part-one/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Animations Are Evil, Performance Rules</title>
		<link>http://www.paladinstudios.com/2011/11/11/animations-are-evil-performance-rules/</link>
		<comments>http://www.paladinstudios.com/2011/11/11/animations-are-evil-performance-rules/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 08:36:27 +0000</pubDate>
		<dc:creator>Lukas</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[momonga]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1819</guid>
		<description><![CDATA[While working at our upcoming game Momo, I am keeping a close eye on performance. It needs to run smoothly (60fps) on an iPhone 3GS, and that is a constant challenge. While its great to develop for mobile platforms, it can get tricky when you don&#8217;t obey the Golden Performance Rules of Lukas. ;) There are [...]]]></description>
			<content:encoded><![CDATA[<p>While working at our upcoming game Momo, I am keeping a close eye on performance. It needs to run smoothly (60fps) on an iPhone 3GS, and that is a constant challenge.</p>
<p>While its great to develop for mobile platforms, it can get tricky when you don&#8217;t obey the Golden Performance Rules of Lukas. ;)</p>
<p>There are a some simple rules like:</p>
<ul>
<li>Forget about pixellights, too expensive (although the new hardware is looking promising!)</li>
<li>Keep your drawcall count low as graphic state changes are cpu expensive</li>
<li>Mark objects that don&#8217;t move as static</li>
<li>If they move, try to keep &#8216;em below 300 vertices, it will then be dynamicly batched</li>
<li>Don&#8217;t instantiate or destroy objects in runtime as memory is slow and it will create hiccups</li>
<li>Don&#8217;t alpha reject pixels on iOS devices because its slow on tile based rendering, use alpha blend instead</li>
<li>Don&#8217;t talk about polygon count but vertex count</li>
<li>Don&#8217;t rely on the 3D modelings package for your total vertex count, use the 3D engine instead as a number of things can influence this number</li>
<li>Don&#8217;t non-uniform scale your objects in an animation as they won&#8217;t be batched</li>
</ul>
<p>On this last one I have a good example, with some pictures. (yay pictures!)</p>
<p>So here we have a nice cracked rock</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/rock_before.png"><img class="alignnone size-thumbnail wp-image-1826" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/rock_before-150x150.png" alt="" width="150" height="150" /></a></p>
<p>In the game it will crack and fall apart</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/rock_after.png"><img class="alignnone size-thumbnail wp-image-1825" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/rock_after-150x150.png" alt="" width="150" height="150" /></a></p>
<p>But wait, 2 drawcalls?</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/stats_before.png"><img class="alignnone size-full wp-image-1829" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/stats_before.png" alt="" width="331" height="248" /></a></p>
<p>The complete asset is only 176 vertices and it should batch! Well it is batched, partially. Lets investigate it. The rock consists of 6 pieces. All using the same material? Check. All under 300 vertices? Check. All scales are uniform? Check. Or is it? Well on start it is but <strong>in the animation one of the rocks is slightly scaled in the x and y axis</strong>.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/scale.png"><img class="alignnone size-medium wp-image-1827" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/scale-400x177.png" alt="" width="300" height="132" /></a></p>
<p>Okay, so walk to the artist, I tell him, he frowns, I explain, he frowns, he fixes, all happy.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/stats_after.png"><img class="alignnone size-full wp-image-1828" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/stats_after.png" alt="" width="312" height="218" /></a></p>
<p>At the bottomline: performance isn&#8217;t only a programmers thing anymore. For mobile, a lot depends on <span style="text-decoration: underline;">how</span> game assets are created, you can&#8217;t get away with sloppyness anymore.</p>
<p>Oh and by the way, if you are an artist and you want to go up a few levels, <em>please please please</em> read the book <a title="Creating 3D Game Art for the iPhone" href="http://www.amazon.com/Creating-Game-Art-iPhone-Unity/dp/0240815637/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1287013870&amp;sr=8-1" target="_blank">Creating 3D Game Art for the iPhone with Unity</a>. It will make your and my life a lot easier. It has been written by and for the game artist but even I enjoyed reading it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/11/11/animations-are-evil-performance-rules/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A New Day, A New Website</title>
		<link>http://www.paladinstudios.com/2011/11/09/a-new-day-a-new-website/</link>
		<comments>http://www.paladinstudios.com/2011/11/09/a-new-day-a-new-website/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 15:26:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/?p=1765</guid>
		<description><![CDATA[After months of hard work by the talented gentlemen from Red Factory, our new website has finally gone live! With the new design, we have made a major focus shift &#8211; while the old website was focused on B2B customers, the new website is much more geared towards our players. We wanted to give people [...]]]></description>
			<content:encoded><![CDATA[<p>After months of hard work by the talented gentlemen from <a title="Red Factory" href="http://www.redfactory.nl" target="_blank">Red Factory</a>, our new website has finally gone live!</p>
<p>With the new design, we have made a major focus shift &#8211; while the old website was focused on B2B customers, the new website is much more geared towards our players. We wanted to give people a place to play games and have some fun.</p>
<p><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/websiteold.jpg"><img class="alignnone size-medium wp-image-1766" title="websiteold" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/websiteold-400x276.jpg" alt="" width="300" height="207" /></a><a href="http://www.paladinstudios.com/wp-content/uploads/2011/11/websitenew.jpg"><img class="alignnone size-medium wp-image-1767" title="websitenew" src="http://www.paladinstudios.com/wp-content/uploads/2011/11/websitenew-400x276.jpg" alt="" width="300" height="207" /></a></p>
<p>The biggest feature is the new &#8220;Game Bar&#8221;, which shows all games we have available. As you can see we only list our own titles here, not our work-for-hire projects. Right now you can see EnerCities, Jimmy Pataya, and our upcoming game Momo. As we create new games, you will find them here. On the right side of the game bar you can see two wooden swords. This is a little something we have been working on, called Paladin Arena. More on that soon ;)</p>
<p>Have a look around, I hope you like it. And please let us know what you think of it in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/11/09/a-new-day-a-new-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jimmy, Meet Admob</title>
		<link>http://www.paladinstudios.com/2011/08/04/jimmy-meet-admob/</link>
		<comments>http://www.paladinstudios.com/2011/08/04/jimmy-meet-admob/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 12:34:20 +0000</pubDate>
		<dc:creator>Derk</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/cms/?p=1301</guid>
		<description><![CDATA[Yesterday, one of my colleagues was ill, and the project we work on was paused for a day. So here I was being stuck for a day and having nothing to do. Then an idea popped up in the studio: Why not finally make the Android version of Jimmy Pataya for the Android Market? We decided [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, one of my colleagues was ill, and the project we work on was paused for a day. So here I was being stuck for a day and having nothing to do.</p>
<p>Then an idea popped up in the studio: Why not finally make the Android version of <a title="Jimmy Pataya" href="http://www.jimmypataya.com" target="_blank">Jimmy Pataya</a> for the Android Market? We decided to do so and we went for a free-version-with-ads business model.</p>
<p>We already converted the iOS version to Android for the <a title="Korean Marketplace" href="http://www.tstore.co.kr/userpoc/game/viewProduct.omp?insDpCatNo=DP01003&amp;insProdId=0000250849&amp;prodGrdCd=PD004401&amp;t_top=DP000501" target="_blank">Korean Marketplace</a>, which was a little different from the Google Android Marktplace in terms of DRM.</p>
<p>So my to-do list for that day was:<br />
- Change the language textures to english<br />
- Integrate an advertisement program<br />
- Figure out the Google Android Marktplace DRM<br />
- Make it all work</p>
<p>After several hours the result was this beauty:<br />
<img class="alignnone size-medium wp-image-1302" src="http://www.paladinstudios.com/cms/wp-content/uploads/JimmyAndroidAdMob-540x330.png" alt="" width="540" height="330" /></p>
<p>We used <a href="http://www.admob.com">AdMob</a> as the advertisement provider and to simplify the integration into <a href="http://www.unity3d.com">Unity</a> we went with the AdMob plugin from <a href="http://prime31.com/unity/">Prime31</a>, which I highly recommend.</p>
<p>I know it may sound lame to say this, but I am very happy with ads inside Jimmy! ;)</p>
<p>You can download Jimmy Pataya for free from the Android Market soon, very soon. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/08/04/jimmy-meet-admob/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Quest for Great Pinball Physics</title>
		<link>http://www.paladinstudios.com/2011/07/28/the-quest-for-great-pinball-physics/</link>
		<comments>http://www.paladinstudios.com/2011/07/28/the-quest-for-great-pinball-physics/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 10:47:48 +0000</pubDate>
		<dc:creator>Derk</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[momonga]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/cms/?p=1269</guid>
		<description><![CDATA[I am making the Game Physics for Project Momonga. The game will have pinball mechanics, which means we are dealing with very high speeds and collisions. So when I started, I knew this wasn&#8217;t going to be an easy task. The fact that it needs to perform well on a mobile device only makes it [...]]]></description>
			<content:encoded><![CDATA[<p>I am making the Game Physics for Project Momonga. The game will have pinball mechanics, which means we are dealing with very high speeds and collisions. So when I started, I knew this wasn&#8217;t going to be an easy task. The fact that it needs to perform well on a mobile device only makes it harder. Here&#8217;s how I did it:</p>
<p>The basics are simple. You take a ball and flippers, set up a table at an angle and let gravity do the rest.<br />
So it wasn&#8217;t long before I got a basic setup working and I was able to shoot some balls.<br />
But the tricky part in physics is always in the details&#8230; and this is where you go one step forward and then 2 steps back.</p>
<p><a href="http://www.paladinstudios.com/cms/wp-content/uploads/lev3-flipper-screenie.png"><img class="alignleft size-full wp-image-1276" src="http://www.paladinstudios.com/cms/wp-content/uploads/lev3-flipper-screenie.png" alt="" width="472" height="303" /></a></p>
<p>When I had the basics working I started to create the first level. We had made some design on paper and I was trying to implement them in the game. In an ideal world, you have full control over where you want the ball to go, and the ball can go just about anywhere. However, we quickly found out that some places were impossible to reach. The angle of the ball was limited: It was very hard to flip the ball to the sides of the level.</p>
<p>How to solve such a problem?</p>
<p>There are a lot of variables you can tweak:<br />
- Flipper rest angle<br />
- Flipper maximum angle<br />
- Flipper strength<br />
- Flipper material (friction, bounciness)<br />
- Ball material<br />
- Ball weight<br />
- Ball drag<br />
- Table material<br />
- Gravity strength<br />
- &#8230;and many more.</p>
<p>Of course changing any of them affects the whole game&#8230; and this is where Game Physics starts to hover between science and art :-)</p>
<p>I created an isolated test setup to determine exactly how all these things influence the ball trajectory. In this test a ball gets spawned every couple of miliseconds, and the flipper is activated automatically. We then trace the ball to see where it goes.<br />
<a href="http://www.paladinstudios.com/cms/wp-content/uploads/flipperangles.png"><img class="alignleft size-large wp-image-1270" src="http://www.paladinstudios.com/cms/wp-content/uploads/flipperangles-1024x635.png" alt="" width="614" height="381" /></a><br />
Now I could change one setting at a time, and see clearly how it affects the ball trajectory.<br />
Using this way of testing I came up with settings that gives the player a lot of control.</p>
<p>Now we have this one off the list, we can make more crazy and exciting levels!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/07/28/the-quest-for-great-pinball-physics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trailer: Oorkania</title>
		<link>http://www.paladinstudios.com/2011/07/22/trailer-oorkania/</link>
		<comments>http://www.paladinstudios.com/2011/07/22/trailer-oorkania/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 10:00:42 +0000</pubDate>
		<dc:creator>Derk</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[oorkania]]></category>
		<category><![CDATA[trailer]]></category>

		<guid isPermaLink="false">http://www.paladinstudios.com/cms/?p=1263</guid>
		<description><![CDATA[Project Momonga is not the only thing keeping us busy. Check out this trailer for the game Oorkania which we&#8217;ve been working on the past months. It&#8217;s a cultural exploration game about music. Go on a quest to free the seven planets of Oorkania! Then collect all sound orbs and mix the music styles and [...]]]></description>
			<content:encoded><![CDATA[<p>Project Momonga is not the only thing keeping us busy. Check out this trailer for the game<a href="http://www.oorkania.nl"> Oorkania</a> which we&#8217;ve been working on the past months. It&#8217;s a cultural exploration game about music. Go on a quest to free the seven planets of Oorkania! Then collect all sound orbs and mix the music styles and sounds to create your own crazy composition :) </p>
<p><a href="http://www.oorkania.nl" target="_blank">Oorkania</a> is created by a collective of some amazing people:<br />
Willem Lagerwaard, an <a href="http://www.willemlagerwaard.nl/" target="_blank">illustrator</a>,<br />
Vuurrood Junior, a <a href="http://www.vuurroodjunior.nl" target="_blank">design company</a>,<br />
Oorkaan, a <a href="http://www.oorkaan.nl" target="_blank">theatre group</a> and<br />
Joey Roukens, a <a href="http://www.joeyroukens.com/" target="_blank">classical composer</a>.<br />
Not to mention the amazing artists who perform the music &#8211; it&#8217;s really an experience to jump from planet to planet and discover custom-created soundtracks.</p>
<p>Release is scheduled in September, so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paladinstudios.com/2011/07/22/trailer-oorkania/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

