<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7117612757607239790</atom:id><lastBuildDate>Fri, 08 Nov 2024 15:00:54 +0000</lastBuildDate><category>Javascript</category><category>C#</category><category>Game Development</category><category>Projects</category><category>Unity 3D</category><category>LaTeX</category><category>Mathematics</category><category>jQuery</category><category>Vim</category><category>XNA</category><category>C</category><category>Meta</category><category>Other</category><category>ASP.NET</category><category>Brainfuck</category><category>CIL</category><category>Google Chrome Extensions</category><category>Linux</category><category>Microsoft Office</category><category>Ruby</category><category>YouTube</category><category>Arduino</category><category>Electronics</category><category>Gosu</category><category>Haskell</category><category>Java</category><category>NGUI</category><category>Syntax Highlighting</category><category>T4</category><category>Visual Studio</category><category>Cracking</category><category>DFGUI</category><category>Facebook</category><category>Farseer Physics Engine</category><category>Genetic Algorithms</category><category>Kongregate</category><category>Mercurial</category><category>Networks</category><category>Riak</category><category>Scheme</category><category>Security</category><category>Ubuntu</category><category>Windows Phone 7</category><title>Andreas Grech&#39;s Blog</title><description>Coffee, a pack of cigs and a keyboard</description><link>http://blog.dreasgrech.com/</link><managingEditor>noreply@blogger.com (Andreas Grech)</managingEditor><generator>Blogger</generator><openSearch:totalResults>130</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-7598777463612617918</guid><pubDate>Sat, 23 Aug 2014 10:55:00 +0000</pubDate><atom:updated>2014-08-23T12:56:34.523+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><title>Making GalleryView items clickable with FancyBox</title><description>I am currently making use of the &lt;a target=&quot;_blank&quot; href=&quot;http://spaceforaname.com/galleryview/&quot;&gt;GalleryView&lt;/a&gt; jQuery plugin which feels great but it lacks a functionality that I needed: clicking on the images to show them in a modal dialog.&lt;br /&gt;
&lt;br /&gt;
I therefore integrated a separate plugin called &lt;a target=&quot;_blank&quot; href=&quot;http://fancybox.net/&quot;&gt;FancyBox&lt;/a&gt; that handles modal functionality beautifully.&lt;br /&gt;
&lt;br /&gt;
To do this, I first did a minor change to &lt;b&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;jquery.galleryview.js&lt;/span&gt;&lt;/b&gt;, where I added the following underneath &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;var img = $(&#39;&amp;lt;img /&amp;gt;&#39;);&lt;/span&gt;:&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;img.attr(&#39;class&#39;, &#39;clickable&#39;);
img.attr(&#39;alt&#39;, gvImage.attrs.title);
&lt;/pre&gt;&lt;br /&gt;
This is so that I can access the images in the GalleryView image gallery whenever an image is clicked, and I reference them with a class &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;clickable&lt;/span&gt;.  I also fetch the description of the image and store it in the alt tag.&lt;br /&gt;
&lt;br /&gt;
Then I simply hook to those images and open fancy box with the current image that&#39;s displayed on the slideshow:&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;$(&#39;.clickable&#39;).live(&#39;click&#39;, function(e){ 
    var img = $(this);
    var imgSrc = img.attr(&#39;src&#39;);
    var imgDesc = img.attr(&#39;alt&#39;);
    
    $.fancybox.open([ { href : imgSrc, title : imgDesc } ], { padding : 0 });
});
&lt;/pre&gt;&lt;br /&gt;
&lt;a target=&quot;_blank&quot; href=&quot;http://dreasgrech.com/upload/galleryviewfancybox/index.html&quot;&gt;And here&#39;s a demo.&lt;/a&gt;</description><link>http://blog.dreasgrech.com/2014/08/making-galleryview-items-clickable-with.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-7152000664154706363</guid><pubDate>Mon, 21 Jul 2014 19:51:00 +0000</pubDate><atom:updated>2014-07-21T21:51:30.951+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>A workaround for allowing multiple callbacks to Application.RegisterLogCallback</title><description>Unity only supports a single delegate to be registered with &lt;a target=&quot;_blank&quot; href=&quot;http://docs.unity3d.com/ScriptReference/Application.RegisterLogCallback.html&quot;&gt;Application.RegisterLogCallback&lt;/a&gt;, which is unfortunate because it means that two independent plugins can&#39;t make separate use of it.&lt;br /&gt;
&lt;br /&gt;
A bug was filed for this issue last year: http://feedback.unity3d.com/suggestions/change-application-dot-registerlogcallback-to-allow-multiple-callbacks&lt;br /&gt;
&lt;br /&gt;
To get around this, I wrote a class to allow for multiple callbacks to be registered.  Make sure let only this class make the call to Application.RegisterLogCallback.&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;using System.Collections.Generic;
using UnityEngine;

/// &amp;lt;summary&amp;gt;
/// Unity only handles a single delegate registered with Application.RegisterLogCallback
/// http://feedback.unity3d.com/suggestions/change-application-dot-registerlogcallback-to-allow-multiple-callbacks
/// 
/// This class is used to work around that by allowing multiple delegates to hook to the log callback.
/// &amp;lt;/summary&amp;gt;
public static class LogCallbackHandler
{
    private static readonly List&amp;lt;Application.LogCallback&amp;gt; callbacks;

    static LogCallbackHandler()
    {
        callbacks = new List&amp;lt;Application.LogCallback&amp;gt;();

        Application.RegisterLogCallback(HandleLog);
    }

    /// &amp;lt;summary&amp;gt;
    /// Register a delegate to be called on log messages.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;logCallback&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    public static void RegisterLogCallback(Application.LogCallback logCallback)
    {
        callbacks.Add(logCallback);
    }

    private static void HandleLog(string condition, string stackTrace, LogType type)
    {
        for (var i = 0; i &amp;lt; callbacks.Count; i++)
        {
            callbacks[i](condition, stackTrace, type);
        }
    }
}
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2014/07/a-workaround-for-allowing-multiple.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-4571879708361637847</guid><pubDate>Thu, 26 Jun 2014 05:33:00 +0000</pubDate><atom:updated>2014-06-26T07:34:27.111+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Getting rid of the pesky &quot;Uncaught exception in async net callback&quot; Unity message</title><description>After some Unity update a couple of months back, an annoying error started showing in the console unexpectedly:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;Uncaught exception in async net callback: Object reference not set to an instance of an object
UnityEditor.AsyncHTTPClient:Done(State, Int32)

  at UnityEngine.GUISkin.GetStyle (System.String styleName) [0x00010] in C:\BuildAgent\work\aeedb04a1292f85a\artifacts\EditorGenerated\GUISkinBindings.cs:268 
  at UnityEngine.GUIStyle.op_Implicit (System.String str) [0x00020] in C:\BuildAgent\work\aeedb04a1292f85a\artifacts\EditorGenerated\GUIStyleBindings.cs:833 
  at UnityEditor.ProjectBrowser.InitSearchMenu () [0x00014] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ProjectBrowser.cs:460 
  at UnityEditor.ProjectBrowser.AssetStoreSearchEndedCallback () [0x00000] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ProjectBrowser.cs:488 
  at UnityEditor.ObjectListArea+&lt;queryassetstore&gt;c__AnonStorey10.&lt;&gt;m__19 (UnityEditor.AssetStoreSearchResults results) [0x00356] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\ObjectListArea.cs:407 
  at UnityEditor.AssetStoreResultBase`1[Derived].Parse (UnityEditor.AssetStoreResponse response) [0x000fc] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:89 
  at UnityEditor.AssetStoreClient+&lt;searchassets&gt;c__AnonStorey2E.&lt;&gt;m__53 (UnityEditor.AssetStoreResponse ar) [0x00000] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:751 
  at UnityEditor.AssetStoreClient+&lt;wrapjsoncallback&gt;c__AnonStorey2D.&lt;&gt;m__51 (UnityEditor.AsyncHTTPClient job) [0x00012] in C:\BuildAgent\work\aeedb04a1292f85a\Editor\Mono\AssetStore\AssetStoreClient.cs:624 
UnityEditor.AsyncHTTPClient:Done(State, Int32)
&lt;/pre&gt;&lt;br /&gt;
Long story short, this is how you get rid of it:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9g7Eo7Cndl9mVJL2dImHTEyjlc73rQrGCSnKThuxV7VZzL585y78Qr2TNlZ11SYLpDGicHIn3TShaLP57Lt93XmfnECBhPu3VLLdq9ysKa3NCfpZncJCqTpaL5K619aDrGCm5mYb1W1k/s1600/UnityAssetStoreSearchHitsError.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9g7Eo7Cndl9mVJL2dImHTEyjlc73rQrGCSnKThuxV7VZzL585y78Qr2TNlZ11SYLpDGicHIn3TShaLP57Lt93XmfnECBhPu3VLLdq9ysKa3NCfpZncJCqTpaL5K619aDrGCm5mYb1W1k/s1600/UnityAssetStoreSearchHitsError.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2014/06/getting-rid-of-pesky-uncaught-exception.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9g7Eo7Cndl9mVJL2dImHTEyjlc73rQrGCSnKThuxV7VZzL585y78Qr2TNlZ11SYLpDGicHIn3TShaLP57Lt93XmfnECBhPu3VLLdq9ysKa3NCfpZncJCqTpaL5K619aDrGCm5mYb1W1k/s72-c/UnityAssetStoreSearchHitsError.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-5648062038973905896</guid><pubDate>Thu, 13 Feb 2014 14:05:00 +0000</pubDate><atom:updated>2014-02-13T15:05:59.118+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">Riak</category><title>Failed to start a Riak cluster after changing the -name parameter in vm.args</title><description>I am currently in the process of setting up a &lt;a href=&quot;http://basho.com/riak/&quot;&gt;Riak&lt;/a&gt; cluster and I encountered a problem where my cluster would not start if I change the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;-name&lt;/span&gt; parameter in the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;vm.args&lt;/span&gt; file.&lt;br /&gt;
&lt;br /&gt;
After some searching, I found this &lt;a href=&quot;http://docs.basho.com/riak/latest/ops/building/basic-cluster-setup/&quot; target=&quot;_blank&quot;&gt;official link&lt;/a&gt; with this notice: &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBWzpviPtQiom12Y9Y7ZDr-j3ufSybISERPKBrOqDNu-1Zcv-LOazTBv9GM3rO2SiOVFsjaQSpcgr_Uxhis8NiaiMhzhu5Cc5jtVMOiQAkpFhntqxm2IY_2vk07zj0oGn-EaccpFM12k/s1600/RiakVMArgs.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBWzpviPtQiom12Y9Y7ZDr-j3ufSybISERPKBrOqDNu-1Zcv-LOazTBv9GM3rO2SiOVFsjaQSpcgr_Uxhis8NiaiMhzhu5Cc5jtVMOiQAkpFhntqxm2IY_2vk07zj0oGn-EaccpFM12k/s1600/RiakVMArgs.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Following the first option to delete the contents of the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;ring&lt;/span&gt; directory (I built from the source, so my &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;ring&lt;/span&gt; directory was at &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;/riak-1.4.7/rel/riak/data/ring/&lt;/span&gt;), I then managed to successfully restart the cluster with &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;./riak start&lt;/span&gt;.</description><link>http://blog.dreasgrech.com/2014/02/failed-to-start-riak-cluster-after.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBWzpviPtQiom12Y9Y7ZDr-j3ufSybISERPKBrOqDNu-1Zcv-LOazTBv9GM3rO2SiOVFsjaQSpcgr_Uxhis8NiaiMhzhu5Cc5jtVMOiQAkpFhntqxm2IY_2vk07zj0oGn-EaccpFM12k/s72-c/RiakVMArgs.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-767494043825822004</guid><pubDate>Wed, 15 Jan 2014 13:21:00 +0000</pubDate><atom:updated>2014-06-26T07:35:05.402+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Changing Unity&#39;s default MonoBehaviour and Shader templates</title><description>If you find yourself having to delete those default&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;// Use this for initialization&lt;/span&gt; and&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;// Update is called once per frame&lt;/span&gt; comments every time you create a script file, then it&#39;s probably best you modify Unity&#39;s default source file template.&lt;br /&gt;
&lt;br /&gt;
From Unity 4, assuming a default installation directory these templates are found in:&amp;nbsp;&lt;b&gt;C:\Program Files (x86)\Unity\Editor\Data\Resources\ScriptTemplates&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In there, you&#39;ll find the JavaScript, C# and Boo script templates along with the shader and compute shader templates.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s the C# one:&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;using UnityEngine;
using System.Collections;

public class #SCRIPTNAME# : MonoBehaviour {

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }
}
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2014/01/changing-unitys-default-monobehaviour.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-3131527603098781183</guid><pubDate>Fri, 20 Dec 2013 11:08:00 +0000</pubDate><atom:updated>2013-12-20T12:08:55.724+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DFGUI</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Embedding sprites in a dfLabel with DFGUI</title><description>One of &lt;a href=&quot;http://www.daikonforge.com/dfgui/&quot; target=&quot;_blank&quot;&gt;DFGUI&lt;/a&gt;&#39;s cool features is the ability to inline-embed images in a &lt;a href=&quot;http://www.daikonforge.com/docs/df-gui/classdf_label.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dfLabel&lt;/span&gt;&lt;/a&gt; to avoid having separate sprites layered on top of the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dfLabel&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI1d4O1fd2sVgyNrAf118_ZIqvarCzHnwEzKgl3nEiTmZUjPFqyvkldyRjSXPG-mkYEk2dh-PAUAe6sV_hoQTGkn6p1uPizUs8iZhuR_RhwcUaZevqY3QQk4DayrW_HjuHxz16Of7e7BE/s1600/DFGUI_SpriteTag.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI1d4O1fd2sVgyNrAf118_ZIqvarCzHnwEzKgl3nEiTmZUjPFqyvkldyRjSXPG-mkYEk2dh-PAUAe6sV_hoQTGkn6p1uPizUs8iZhuR_RhwcUaZevqY3QQk4DayrW_HjuHxz16Of7e7BE/s1600/DFGUI_SpriteTag.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
To embed sprites in a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dfLabel&lt;/span&gt;, you must first make sure that the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Process Markup&lt;/span&gt; checkbox (Label Properties-&amp;gt;Formatting) is ticked.&lt;br /&gt;
&lt;br /&gt;
Then, embedding sprites is done using the sprite tag: &lt;b&gt;Press [sprite &quot;xbox_a&quot;] to Select&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The sprite that is specified in the sprite tag (in my case it&#39;s &quot;xbox_a&quot;) is fetched from the Atlas that is specified on the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;dfLabel&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlPhUnvDBi9lRgdekNTEObJyG7G1jLa_-kwzO1OC1QpjQPx1UvNXuro3B1bE4jIRYRDpu_KjRT-uBJhJXG2nz2FUc1kegxuRcFdeod0I0klSJZzjtloa9o0K689n4JCqWQ6VPUy7aY9GA/s1600/DFGUI_ProcessMarkupInspector.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlPhUnvDBi9lRgdekNTEObJyG7G1jLa_-kwzO1OC1QpjQPx1UvNXuro3B1bE4jIRYRDpu_KjRT-uBJhJXG2nz2FUc1kegxuRcFdeod0I0klSJZzjtloa9o0K689n4JCqWQ6VPUy7aY9GA/s400/DFGUI_ProcessMarkupInspector.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
</description><link>http://blog.dreasgrech.com/2013/12/embedding-sprites-in-dflabel-with-dfgui.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI1d4O1fd2sVgyNrAf118_ZIqvarCzHnwEzKgl3nEiTmZUjPFqyvkldyRjSXPG-mkYEk2dh-PAUAe6sV_hoQTGkn6p1uPizUs8iZhuR_RhwcUaZevqY3QQk4DayrW_HjuHxz16Of7e7BE/s72-c/DFGUI_SpriteTag.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-8420184160576926402</guid><pubDate>Fri, 13 Dec 2013 16:12:00 +0000</pubDate><atom:updated>2013-12-17T15:01:52.205+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>A 2D Freeform Directional Blend Tree for locomotion in Unity 3D</title><description>This video demonstrates a root-motion driven, 2D Freeform Directional Blend Tree for locomotive states in Unity 3D.&lt;br /&gt;
&lt;br /&gt;
Using such a blend tree, a character can aim and walk in different directions independently and simultaneously.&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;//www.youtube.com/embed/CihmSI7IL0A?rel=0&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/center&gt;&lt;br /&gt;
With a gamepad, I&#39;m moving the character with the left stick and rotating with the right stick.&lt;br /&gt;
&lt;br /&gt;
I am using a total of 9 animations for the blend tree. Four for each axis and the middle one for idle:  &lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Idle&lt;/li&gt;
&lt;li&gt;Forward Walk&lt;/li&gt;
&lt;li&gt;Backward Walk&lt;/li&gt;
&lt;li&gt;Left Strafe Walk&lt;/li&gt;
&lt;li&gt;Right Strafe Walk&lt;/li&gt;
&lt;li&gt;Forward Run&lt;/li&gt;
&lt;li&gt;Backward Run&lt;/li&gt;
&lt;li&gt;Left Strafe Run&lt;/li&gt;
&lt;li&gt;Right Strafe Run&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Here&#39;s a closer look at the blend tree and its motions:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhxojYoNGZj8RtbmkAgD92jTC_BHkR4KjqVCD_Yku04hHcvm3FoimG5RYsylEuqo3pQBiyGrhhMcCXjhd55qnI6QXtACCdptf3EB5mZXb0QFZzF40-83TmybS1UIO73iV6arbHeTBYfs0/s1600/2DFreeformDirectionalBlendTree.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhxojYoNGZj8RtbmkAgD92jTC_BHkR4KjqVCD_Yku04hHcvm3FoimG5RYsylEuqo3pQBiyGrhhMcCXjhd55qnI6QXtACCdptf3EB5mZXb0QFZzF40-83TmybS1UIO73iV6arbHeTBYfs0/s640/2DFreeformDirectionalBlendTree.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This locomotive blend tree exists on an &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Animator Layer&lt;/span&gt; called LowerBody which has has an &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Avatar Mask&lt;/span&gt; applied with only the legs selected (including IK).  By having layers representing different sections of the body, I can combine upper-body animations with lower-body animations.  In my case, the character can walk/run and aim at the same time using a single animation for AIMING (which exists on the upper-body layer).&lt;br /&gt;
&lt;br /&gt;
This is the Avatar Mask I use on the Lower-Body layer on which the locomotion blend tree exists:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaw9yi7S35InNQzVink5crPDn-1n1_vwn8h0Tpta2lfC1jW2-_P2gGmD7glQI5kbn60COvUzsZtfWXmovHvP31j0KFn4IyKwFz10JCAa_npZTLly1XYBqubN6nMH5FuVem-Du8KWonLk0/s1600/LowerBodyAvatarMask.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaw9yi7S35InNQzVink5crPDn-1n1_vwn8h0Tpta2lfC1jW2-_P2gGmD7glQI5kbn60COvUzsZtfWXmovHvP31j0KFn4IyKwFz10JCAa_npZTLly1XYBqubN6nMH5FuVem-Du8KWonLk0/s640/LowerBodyAvatarMask.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
I am controlling the blend tree with two parameters representing a direction vector: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;VelX&lt;/span&gt; and &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;VelZ&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
This direction vector determines the locomotive state of the character i.e. which direction his legs should be moving.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;If (VelX, VelZ) is &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(0, 1)&lt;/span&gt;, the character runs forward in a straight line.&lt;/li&gt;
&lt;li&gt;If (VelX, VelZ) is &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(-1, 0.5)&lt;/span&gt;, the character walks forward while strafing to the left.&lt;/li&gt;
&lt;li&gt;If (VelX, VelZ) is &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(0.5, -1)&lt;/span&gt;, the character runs backwards while slightly strafing to the right&lt;/li&gt;
&lt;li&gt;etc...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
This is the gist of the code which both a) sets the (VelX, VelZ) direction vector [Left Stick] i.e. LOCOMOTION and b) rotates the model to aim [Right Stick] i.e ROTATION:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;private Vector3 lastLeftStickInputAxis;  // stores the axis input from the left stick between frames

private void Update()
{
    /* START LOCOMOTION */

    // Get the axis from the left stick (a Vector2 with the left stick&#39;s direction)
    var leftStickInputAxis = inputManager.LeftAxis;
    
    // Get the angle between the the direction the model is facing and the input axis vector
    var a = SignedAngle(new Vector3(leftStickInputAxis.x, 0, leftStickInputAxis.y), model.transform.forward);
    
    // Normalize the angle
    if (a &amp;lt; 0)
    {
        a *= -1;
    }
    else
    {
        a = 360 - a;
    }
    
    // Take into consideration the angle of the camera
    a += Camera.main.transform.eulerAngles.y;

    var aRad = Mathf.Deg2Rad*a; // degrees to radians
    
    // If there is some form of input, calculate the new axis relative to the rotation of the model
    if (leftStickInputAxis.x != 0 || leftStickInputAxis.y != 0)
    {
        leftStickInputAxis = new Vector2(Mathf.Sin(aRad), Mathf.Cos(aRad));
    }
    
    float xVelocity = 0f, yVelocity = 0f;
    float smoothTime = 0.05f;

    // Interpolate between the input axis from the last frame and the new input axis we calculated
    leftStickInputAxis = new Vector2(Mathf.SmoothDamp(lastLeftStickInputAxis.x, leftStickInputAxis.x, ref xVelocity, smoothTime), Mathf.SmoothDamp(lastLeftStickInputAxis.y, leftStickInputAxis.y, ref yVelocity, smoothTime));
    
    // Update the Animator with our values so that the blend tree updates
    animator.SetFloat(&quot;VelX&quot;, leftStickInputAxis.x);
    animator.SetFloat(&quot;VelZ&quot;, leftStickInputAxis.y);
    
    lastLeftStickInputAxis = leftStickInputAxis;

    /* END LOCOMOTION */



    /* START ROTATION */

    // Get the axis from the right stick (a Vector2 with the right stick&#39;s direction)
    var rightStickInputAxis = inputManager.RightAxis; 
    if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
    {
        float angle2 = 0;
        if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
        {
            angle2 = Mathf.Atan2(rightStickInputAxis.x, rightStickInputAxis.y)*Mathf.Rad2Deg;
            if (angle2 &amp;lt; 0)
            {
                angle2 = 360 + angle2;
            }
        }
    
        // Calculate the new rotation for the model and apply it
        var rotationTo = Quaternion.Euler(0, angle2 + Camera.main.transform.eulerAngles.y, 0);
        model.transform.rotation = Quaternion.Slerp(model.transform.rotation, rotationTo, Time.deltaTime*10);
    }

    /* END ROTATION */
}

private float SignedAngle(Vector3 a, Vector3 b)
{
    return Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).y);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt;The &lt;a target=&quot;_blank&quot; href=&quot;https://www.assetstore.unity3d.com/#/content/122&quot;&gt;soldier model&lt;/a&gt; and animations are from Mixamo.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Fuzzy Duck&quot;,
  name : &quot;A Word From Big D&quot;,
  link : &#39;http://grooveshark.com/s/A+Word+From+Big+D/3EjQzF?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/12/a-2d-freeform-directional-blend-tree.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhxojYoNGZj8RtbmkAgD92jTC_BHkR4KjqVCD_Yku04hHcvm3FoimG5RYsylEuqo3pQBiyGrhhMcCXjhd55qnI6QXtACCdptf3EB5mZXb0QFZzF40-83TmybS1UIO73iV6arbHeTBYfs0/s72-c/2DFreeformDirectionalBlendTree.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-657261398037040549</guid><pubDate>Thu, 12 Dec 2013 13:53:00 +0000</pubDate><atom:updated>2013-12-12T15:36:42.738+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Keeping track of cooldowns with a helper class in Unity 3D</title><description>For my current project, I wrote a simple class to keep track of my cooldowns.  &lt;br /&gt;
&lt;br /&gt;
So for example, my character can fire every 2 seconds, jump every 4 seconds and sprint every 3.142 seconds; and this class takes care of the cooldown timers for me.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s how I use it:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;public class Player : MonoBehaviour 
{
    private CooldownTimer firingCooldown;
    private CooldownTimer sprintCooldown;

    private void Awake() 
    {
        firingCooldown = new CooldownTimer(2f); // the player can fire every 2 seconds
        sprintCooldown = new CooldownTimer(3.142f); // the player can sprint every 3.142 seconds
    }

    private void Update() 
    {
        if (Input.GetButtonDown(&quot;Fire&quot;) &amp;amp;&amp;amp; firingCooldown.CanWeDoAction()) 
        {
            firingCooldown.UpdateActionTime();
            // Do firing logic            
        }

        if (Input.GetButtonDown(&quot;Sprint&quot;) &amp;amp;&amp;amp; sprintCooldown.CanWeDoAction()) 
        {
            sprintCooldown.UpdateActionTime();
            // Do sprinting logic            
        }
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And this here&#39;s the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;CooldownTimer&lt;/span&gt; class:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;using System;

public class CooldownTimer
{
    private float? LastActionDone { get; set; }
    private float IntervalSeconds { get; set; }

    public CooldownTimer(float intervalSeconds)
    {
        IntervalSeconds = intervalSeconds;
    }

    public void UpdateActionTime()
    {
        LastActionDone = Time.time;
    }

    public bool CanWeDoAction()
    {
        var canWeDoAction = true;
        if (LastActionDone.HasValue)
        {
            var secondsSinceLastAction = Time.time - LastActionDone;
            canWeDoAction = secondsSinceLastAction &amp;gt; IntervalSeconds;
        }

        return canWeDoAction;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;h4&gt;
Update 1&lt;/h4&gt;
With a tip from Petr Kolda (Facebook), I&#39;ve now modified the class to use&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Time.time&lt;/span&gt; instead of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;DateTime.Now&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;
&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;AC/DC&quot;,
  name : &quot;Jailbreak&quot;,
  link : &#39;http://grooveshark.com/s/Jailbreak/3F4zeo?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;
</description><link>http://blog.dreasgrech.com/2013/12/keeping-track-of-cooldowns-with-helper.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-9048048887399064603</guid><pubDate>Wed, 11 Dec 2013 13:58:00 +0000</pubDate><atom:updated>2013-12-11T14:58:48.721+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Opening multiple instances of Unity 3D</title><description>To open multiple instances of Unity 3D, go to Edit &gt; Preferences, and from there tick the &quot;Always Show Project Wizard&quot; checkbox:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzxZ-qDtqMydTE5V5gE_DDgMaJ6_z2PMX9YuTe-_vI9ar0jtidUoV0She3OYfRspVgaqon67QD0GtNUL2M8A6KiL76f50f2n3ZgO83l6lmUXmTeq7E5C5LMo9DmKzQ9DF_Hrniwv6mbyk/s1600/Unity3D-AlwaysShowProjectWizard.png&quot; /&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/12/opening-multiple-instances-of-unity-3d.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzxZ-qDtqMydTE5V5gE_DDgMaJ6_z2PMX9YuTe-_vI9ar0jtidUoV0She3OYfRspVgaqon67QD0GtNUL2M8A6KiL76f50f2n3ZgO83l6lmUXmTeq7E5C5LMo9DmKzQ9DF_Hrniwv6mbyk/s72-c/Unity3D-AlwaysShowProjectWizard.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-624651821685836044</guid><pubDate>Wed, 11 Dec 2013 12:07:00 +0000</pubDate><atom:updated>2013-12-11T17:12:04.737+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Pixel Perfect sprites in Unity 2D</title><description>In Unity 4.3, native 2D tools were introduced in Unity 3D.  So, armed with a bunch of 1024x768 sprites from an old game I wrote, I decided to try out the new 2D tools by trying to port the old game to Unity 2D.&lt;br /&gt;
&lt;br /&gt;
But the first issue I encountered when dragging in my first sprite to the scene was this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9AODWlXmaebSmMbt7Gg35AyM7CtPLawbA7VCubVVQ82hS7s3HT-lAOD2MbK1NnuKKVtg2CNq0Q-m5ufQi11YtGLy9C0Lt-0c8K49Mr1BFszjZtYnttdR1FxDBXe709uFCc0dO807ZLeo/s1600/Unity+2013-12-11+12-50-31-71.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9AODWlXmaebSmMbt7Gg35AyM7CtPLawbA7VCubVVQ82hS7s3HT-lAOD2MbK1NnuKKVtg2CNq0Q-m5ufQi11YtGLy9C0Lt-0c8K49Mr1BFszjZtYnttdR1FxDBXe709uFCc0dO807ZLeo/s320/Unity+2013-12-11+12-50-31-71.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Notice how even though my game resolution is set to 1024x768 (top corner) and my water image is 1024x768 and centered on the screen, the sprite (SpriteRenderer) doesn&#39;t fill the screen as it should.&lt;br /&gt;
&lt;br /&gt;
The way to fix this is by changing the Size of your orthographic Camera.&lt;br /&gt;
&lt;br /&gt;
To calculate the Size for your Camera, use this: &lt;b&gt;Camera Size = (GameTargetHeight / 2) / PixelsToUnits&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;By default, Pixels To Units is set to 100.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So, since my game targets a resolution of 1024x768, my Camera Size would be: (768/2)/100 = 3.84&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXMK6rlOpwhtLbKihmtpJImdbIQ-VJT1yw65G-eYAd2_ffeegA-fyXOMJKN1KZmv-IY9MV1JtERptukml0Ls-w5ahIH9EfFJLFde6ljAMKvwWczj891SPWOBx1SONdYPCvqyiJidVLjwg/s1600/Unity2DOrthoCameraSize.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXMK6rlOpwhtLbKihmtpJImdbIQ-VJT1yw65G-eYAd2_ffeegA-fyXOMJKN1KZmv-IY9MV1JtERptukml0Ls-w5ahIH9EfFJLFde6ljAMKvwWczj891SPWOBx1SONdYPCvqyiJidVLjwg/s320/Unity2DOrthoCameraSize.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
And as you can see, that fixes the problem beautifully:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMfdH3VM8Tt4i7Fo3H9Nnb9NwrGljWijRdHa3kRkA2OWfbXBtxM3yvfpxPWgsYB317ed2yFk3RjWdXWJpZ41ZeKrQHEDEWi6yJGsa-R_X-ZJdE9fMIF9kE7Dyar_LDFP2DpJ37GfKHlNE/s1600/Unity+2013-12-11+12-56-54-34.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMfdH3VM8Tt4i7Fo3H9Nnb9NwrGljWijRdHa3kRkA2OWfbXBtxM3yvfpxPWgsYB317ed2yFk3RjWdXWJpZ41ZeKrQHEDEWi6yJGsa-R_X-ZJdE9fMIF9kE7Dyar_LDFP2DpJ37GfKHlNE/s320/Unity+2013-12-11+12-56-54-34.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;C.W. McCall&quot;,
  name : &quot;Convoy&quot;,
  link : &#39;http://grooveshark.com/s/Convoy/18HBFN?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/12/pixel-perfect-sprites-in-unity-2d.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9AODWlXmaebSmMbt7Gg35AyM7CtPLawbA7VCubVVQ82hS7s3HT-lAOD2MbK1NnuKKVtg2CNq0Q-m5ufQi11YtGLy9C0Lt-0c8K49Mr1BFszjZtYnttdR1FxDBXe709uFCc0dO807ZLeo/s72-c/Unity+2013-12-11+12-50-31-71.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-8347738338578715078</guid><pubDate>Thu, 05 Sep 2013 16:26:00 +0000</pubDate><atom:updated>2013-09-05T18:26:45.543+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Unity Helper Methods #4: InvokeInSeconds</title><description>&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;/// &amp;lt;summary&amp;gt;
/// Invokes an action after waiting for a specified number of seconds
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;waitSeconds&amp;quot;&amp;gt;The number of seconds to wait before invoking&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;invoke&amp;quot;&amp;gt;The action to invoke after the time has passed&amp;lt;/param&amp;gt;
public static IEnumerator InvokeInSeconds(float waitSeconds, Action invoke)
{
    yield return new WaitForSeconds(waitSeconds);
    invoke();
}
&lt;/pre&gt;&lt;h4&gt;Typical Usage&lt;/h4&gt;Now I know that Unity already has its own &lt;a target=&quot;_blank&quot; href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.Invoke.html&quot;&gt;Invoke&lt;/a&gt; method but Unity&#39;s method only accepts a string specifying the method name.&lt;br /&gt;
&lt;br /&gt;
I wrote this method to be able to specify an anonymous lambda instead of the string.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Note that the method&#39;s return type is IEnumerator since it yields, therefore we must invoke it with &lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StartCoroutine.html&quot; target=&quot;_blank&quot;&gt;StartCoroutine&lt;/a&gt;.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;StartCoroutine(InvokeInSeconds(0.5f, () =&gt; Destroy(gameObject))); // Destroy the gameObject in 0.5 seconds
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2013/09/unity-helper-methods-4-invokeinseconds.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-8837981101030831004</guid><pubDate>Thu, 05 Sep 2013 16:07:00 +0000</pubDate><atom:updated>2013-09-05T18:07:37.069+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Unity Helper Methods #3: GetRandomEnum</title><description>&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;/// &amp;lt;summary&amp;gt;
/// Returns a random enum from the specified enum type
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;The enum&amp;lt;/typeparam&amp;gt;
public static T GetRandomEnum&amp;lt;T&amp;gt;()
{
    Array values = Enum.GetValues(typeof(T));
    return  (T)values.GetValue(UnityEngine.Random.Range(0, values.Length));
}
&lt;/pre&gt;&lt;h4&gt;Typical Usage&lt;/h4&gt;Fairly simple; returns a random enum value from an enum type.&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;enum EnemyModels
{
    Knight,
    FrailOldLady,
    Copernicus,
    BrianMay,
    MalboroGuy
}

void SpawnEnemy() 
{
    EnemyModels modelType = GetRandomEnum&amp;lt;EnemyModels&amp;gt;();
    // Now we have a random enemy model type.
}
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2013/09/unity-helper-methods-3-getrandomenum.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-7831234451074274197</guid><pubDate>Thu, 05 Sep 2013 15:50:00 +0000</pubDate><atom:updated>2014-03-17T17:26:06.309+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Unity Helper Methods #2: BoxCollider.GetPointInCollider</title><description>&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;/// &amp;lt;summary&amp;gt;
/// Returns a random world point inside the given BoxCollider
/// &amp;lt;/summary&amp;gt;
public static Vector3 GetPointInCollider(this BoxCollider area)
{
    var bounds = area.bounds;
    var center = bounds.center;

    var x = UnityEngine.Random.Range(center.x - bounds.extents.x, center.x + bounds.extents.x);
    var z = UnityEngine.Random.Range(center.z - bounds.extents.z, center.z + bounds.extents.z);

    return new Vector3(x, 0, z);
}
&lt;/pre&gt;&lt;br /&gt;
I normally use this method to get a random spawnpoint within my spawn area represented with a &lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/BoxCollider.html&quot; target=&quot;_blank&quot;&gt;BoxCollider&lt;/a&gt; (set to a trigger of course).&lt;br /&gt;
&lt;br /&gt;
Notice how I hardcode Y to 0 because the Y position is irrelevant to me since that is set by code outside of this method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;public BoxCollider spawnArea;

void SpawnWhatever() 
{
    Vector3 spawnPoint = spawnArea.GetPointInCollider();
    // Spawn something at the random spawnpoint we got
    // ...
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLL-tjlM9zYSwMs82ThCml5VugXXSlZQBN7QkwyjVcOZa_hZNtJaslqQigClQ08PugAaEpc-L5b1GDhguDYema1PuFHk96ynjGgPNlVmBCzoZRdg3mNuoiJJVTsXZQf-ghFpJjgyiyzOg/s1600/BoxColliderSpawn.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLL-tjlM9zYSwMs82ThCml5VugXXSlZQBN7QkwyjVcOZa_hZNtJaslqQigClQ08PugAaEpc-L5b1GDhguDYema1PuFHk96ynjGgPNlVmBCzoZRdg3mNuoiJJVTsXZQf-ghFpJjgyiyzOg/s400/BoxColliderSpawn.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/09/unity-helper-methods-2.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLL-tjlM9zYSwMs82ThCml5VugXXSlZQBN7QkwyjVcOZa_hZNtJaslqQigClQ08PugAaEpc-L5b1GDhguDYema1PuFHk96ynjGgPNlVmBCzoZRdg3mNuoiJJVTsXZQf-ghFpJjgyiyzOg/s72-c/BoxColliderSpawn.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-4949673387749793556</guid><pubDate>Thu, 05 Sep 2013 15:18:00 +0000</pubDate><atom:updated>2013-09-05T17:54:03.626+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Game Development</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Unity Helper Methods #1: Animator.SetLayerWeights</title><description>&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;/// &amp;lt;summary&amp;gt;
/// Sets the weight of all the layers in the specified Animator
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;animator&amp;quot;&amp;gt;The animator&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;totalLayers&amp;quot;&amp;gt;The number of layers this animator contains&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;weight&amp;quot;&amp;gt;The value of the weight&amp;lt;/param&amp;gt;
public static void SetLayerWeights(this Animator animator, int totalLayers, float weight)
{
    for (int i = 0; i &amp;lt; totalLayers; i++)
    {
        animator.SetLayerWeight(i + 1, weight);
    }
}
&lt;/pre&gt;&lt;h4&gt;Description&lt;/h4&gt;Starting with a fairly trivial method; setting the weight of &#39;all&#39; the layers of an &lt;a href=&quot;http://docs.unity3d.com/Documentation/Manual/Animator.html&quot; target=&quot;_blank&quot;&gt;Animator&lt;/a&gt;.  When a game starts, Unity by default sets all the layers of the Animators&#39; Controllers to 0.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, the method needs to be supplied with the number of layers that the Animator contains because I haven&#39;t yet found a way how to get the number of layers programmatically.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Typical Usage&lt;/h4&gt;I use this method at the start of a game to set the weight of all the layers to 1.  &lt;br /&gt;
&lt;br /&gt;
So, if I know that I have 4 layers for a particular Animator:&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;animator.SetLayerWeights(4, 1); // Sets the weight of all (4) the layers of my animator
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2013/09/unity-helper-methods-1-setlayerweights.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-6333369263455524454</guid><pubDate>Tue, 07 May 2013 21:44:00 +0000</pubDate><atom:updated>2013-05-08T00:22:34.667+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">NGUI</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Coloring individual characters in an NGUI UILabel text</title><description>For the game project that I&#39;m currently working on, I needed to find an easy way to color individual characters in the text of an NGUI &lt;a href=&quot;http://www.tasharen.com/?page_id=166&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UILabel&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Fortunately, the solution is pretty simple.  When the &lt;a href=&quot;http://www.tasharen.com/ngui/docs/class_u_i_label.html#a80bac259fe53a893a95f0e576cf69a00&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;supportEncoding&lt;/span&gt;&lt;/a&gt; boolean field on a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UILabel&lt;/span&gt; is set to &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;true&lt;/span&gt;, the text supports color encoding in the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;[RRGGBB]&lt;/span&gt; format.&lt;br /&gt;
&lt;br /&gt;
This means that we can have write text such as the following (&lt;i&gt;the [-] is used to revert to a previous color&lt;/i&gt;):&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;pre&gt;[FF0000]Red[-] [00FF00]Green[-] [0000FF]Blue[-]
&lt;/pre&gt;&lt;/center&gt;&lt;br /&gt;
&lt;center&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD0ictvv080JxTA94zlGM9AsJ120sg-C8A4keWLlQBnI0aU1KQpLo1-w2a16JIjGXXw0hxLQ_9u7d_PZXBO_Y4GUZ-6WG4ArkxT2Fx7ivOdA74X9EBr5Grc3pREFrE_E4ROgiYox_w4Kg/s1600/RGB.png&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
The reason I needed to do this was because we want the leading zeros in the Score &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UILabel&lt;/span&gt; to have a different colour than the actual score.  And for that, I wrote this neat little method to format my current score to a string with a predefined number of leading zeros and then color those leading zeros independent from the main colour of the label text.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;private string FormatScore(int score, string leadingZerosRGBColor, int totalDigits)
{
    var scoreString = score.ToString(CultureInfo.InvariantCulture);
    var zeros = totalDigits - scoreString.Length;
    if (score == 0)
    {
        scoreString = String.Empty;
        zeros++;
    }

    return String.Format(&quot;[{0}]{1}[-]{2}&quot;, leadingZerosRGBColor, new string(&#39;0&#39;, zeros &amp;lt;= 0 ? 0 : zeros), scoreString);
}
&lt;/pre&gt;&lt;br /&gt;
And the end result pretty much looks like our designer intended:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGmvRimSBQlsI64IpYvPI0njTrG4Sz3DbUmW-5YLRsEF9YgALgmgPiOam2Fh9SsvaHMoghMwVSphK9_9NEbaNKvzBaVZFnzoaqnFaxwrdY4c1Sbx6aCqAaguv7xoIAnnCqVDFp43PqIXE/s1600/T3D+Score.png&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Hawkwind&quot;,
  name : &quot;Assault &amp; Battery Part 1&quot;,
  link : &#39;http://grooveshark.com/s/Assult+And+Battery+Part+I/3gqenJ?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/05/coloring-individual-characters-in-ngui.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD0ictvv080JxTA94zlGM9AsJ120sg-C8A4keWLlQBnI0aU1KQpLo1-w2a16JIjGXXw0hxLQ_9u7d_PZXBO_Y4GUZ-6WG4ArkxT2Fx7ivOdA74X9EBr5Grc3pREFrE_E4ROgiYox_w4Kg/s72-c/RGB.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-3679196015459387434</guid><pubDate>Fri, 26 Apr 2013 14:34:00 +0000</pubDate><atom:updated>2013-04-26T16:34:44.809+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">Meta</category><title>Using the Blogger API to search within a post&#39;s HTML content</title><description>A couple of months ago I wanted to switch the syntax highlighter I used to have on this blog to &lt;a href=&quot;http://sunlightjs.com/&quot; target=&quot;_blank&quot;&gt;SunlightJS&lt;/a&gt;.  Thing is though, I didn&#39;t want to go through every individual post I had written before and check whether they are using the (old) syntax highlighter to update their HTML markup.&lt;br /&gt;
&lt;br /&gt;
Another problem was that the only way I would be able to truly know if a particular post is using the old syntax highlighter was by going through it&#39;s HTML content and determine whether the post currently has a tag like the following: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;pre class=&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The issue here is that the normal Google driven searchbox packaged with Blogger (the one you see on the right hand side) does not search through a posts&#39; HTML content but rather through its textual content only which means it was useless for my task.&lt;br /&gt;
&lt;br /&gt;
Because of this, I decided to write a script to semi-automate this task for me.  The reason I say that the script semi-automates the job is because although I wanted it to show me all the posts in which I had used the old highlighter before, I could not risk making it to update the blog post automatically to use the new syntax highlighter because that would have involved HTML parsing and it was not worth the hassle.  Besides, I didn&#39;t want to risk ruining my old posts because of a script fuckup.&lt;br /&gt;
&lt;br /&gt;
So what the script does is it uses the Blogger API to batch-fetch all my previous blog posts, go through each posts&#39; individual HTML content and notify me whether that particular post is using the old syntax highlighter.  Searching is done using the regular expression engine and for my case, the function was pretty trivial:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;getOccurences = function(haystack, needle) {
    var matches = haystack.match(new RegExp(needle, &quot;g&quot;));
    return matches ? matches.length: 0;
}
&lt;/pre&gt;&lt;br /&gt;
The Blogger API url I used to fetch my posts&#39; details is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;https://www.googleapis.com/blogger/v3/blogs/&amp;lt;blogid&amp;gt;/posts?key=&amp;lt;API key&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
For the script to work I needed to provide it with three things:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;My Blogger API key for this project&lt;/li&gt;
&lt;li&gt;My blog&#39;s ID (&lt;a href=&quot;http://support.google.com/blogger/bin/answer.py?hl=en&amp;amp;answer=42191&quot; target=&quot;_blank&quot;&gt;this is how you find yours&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;The search query I wanted to use&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Here&#39;s a demo of the script in action: &lt;a href=&quot;http://jsfiddle.net/ydtuc/77/&quot; target=&quot;_blank&quot;&gt;http://jsfiddle.net/ydtuc/77/&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
And this is how it looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSR2FeBf-Y7TT5aVSbYhyphenhyphenZIJox8Br4e4X-HE_3BDYBerJRKz4hbjI1JAHt0A6hEO0tg-FqEj3E4bAqQHRktsR8TeeX4u2Hg1m7nplsgzPdiqIXXmbinP83WrinC7OubQZQJiiRxfEb2Aw/s1600/BlogScriptsSearcher.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSR2FeBf-Y7TT5aVSbYhyphenhyphenZIJox8Br4e4X-HE_3BDYBerJRKz4hbjI1JAHt0A6hEO0tg-FqEj3E4bAqQHRktsR8TeeX4u2Hg1m7nplsgzPdiqIXXmbinP83WrinC7OubQZQJiiRxfEb2Aw/s320/BlogScriptsSearcher.png&quot; /&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;
From the live demo (or the screenshot), you can see the output of the script in the bottom right pane.  The script nicely formats each of the returned matches in a way that if I click on the #number of the post, it would take me to the actual blog post and clicking on the name of the post takes me to the Blogger editor for that current post so that I can easily update it.  The number in parentheses next to the title of the post is the total number of occurrences the needle appears in the haystack.&lt;br /&gt;
&lt;br /&gt;
This is the full script:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;var key = &#39;AIzaSyCEsBaStg4bOHA2Yp75OqfbjBkk_kq0cMw&#39;,
    blogId = &#39;7117612757607239790&#39;,
    baseMatcher = &#39;JavaScript&#39;, // the needle.
    allPosts = [],
    isProcessing,
    updateButton = $(&quot;#update&quot;),
    update = (function (button) {
        var updateText = function (message, color) {
            button.attr(&quot;value&quot;, message);
            if (color) {
                button.css(&quot;color&quot;, color);
            }

        },
            revertButtonMessage = function () {
                changeButtonMessage(&quot;Update&quot;, &quot;black&quot;);
            },
            changeButtonMessage = function (message, color) {
                var didIt;
                updateText(message, color);
                setTimeout(revertButtonMessage, 1000);
            },
            switchButtonMessage = function (message, color) {
                updateText(message, color);
            };

        return {
            changeButtonMessage: changeButtonMessage,
            switchButtonMessage: switchButtonMessage,
            revertButtonMessage: revertButtonMessage
        };
    }(updateButton)),
    formatLink = function (text, href) {
        return &#39;&amp;lt;a href=&quot;&#39; + href + &#39;&quot; target=&quot;_blank&quot;&amp;gt;&#39; + text + &#39;&amp;lt;/a&amp;gt;&#39;;
    },
    getOccurences = function (haystack, needle) {
        var matches = haystack.match(new RegExp(needle, &quot;g&quot;));
        return matches ? matches.length : 0;
    },
    logger = (function () {
        var logs = $(&quot;#logs&quot;),
            appendLine = function (line) {
                logs.append((line ? line : &quot;&quot;) + &quot;&amp;lt;br/&amp;gt;&quot;);
            };

        return {
            log: function (items) {
                appendLine(&#39;&amp;lt;span class=&quot;logHeader&quot;&amp;gt;Logs #&#39; + new Date().getTime() + &#39;&amp;lt;/span&amp;gt;&#39;);
                appendLine();
                $.each(items, function (i, item) {
                    appendLine(formatLink(&#39;#&#39; + i, item.url) + &#39;: &#39; + formatLink(item.title, &quot;http://www.blogger.com/blogger.g?blogID=&quot; + blogId + &quot;#editor/target=post;postID=&quot; + item.id) + &#39; (&#39; + getOccurences(item.content, baseMatcher) + &#39;)&#39;);
                });
                appendLine();
            },
            clear: function () {
                logs.html(&#39;&#39;);
            }
        };
    }()),
    filter = function (items, predicateForPass) {
        var i = 0,
            j = items.length,
            item, passed = [],
            inc = 0;

        for (; i &amp;lt; j; ++i) {
            item = items[i];
            if (!predicateForPass(item)) {
                continue;
            }

            passed.push(item);
        }

        return passed;
    },
    getPosts = function (pageToken) {
        var url = &#39;https://www.googleapis.com/blogger/v3/blogs/&#39; + blogId + &#39;/posts?key=&#39; + key,
            get = function (token) {
                var pagedUrl = url + (token ? (&quot;&amp;amp;pageToken=&quot; + token) : &quot;&quot;);
                $.get(pagedUrl, function (response) {
                    var token = response.nextPageToken;
                    allPosts = allPosts.concat(response.items);

                    if (token) {
                        return get(token);
                    }

                    isProcessing = false;
                    update.changeButtonMessage(&quot;Finished&quot;, &quot;green&quot;);
                    var filtered = filter(allPosts, function (item) {
                        var preTotal = getOccurences(item.content, baseMatcher),
                            preNewSyntaxHighlighter = getOccurences(item.content, baseMatcher + &quot;sunlight&quot;);
                        return (preTotal - preNewSyntaxHighlighter) &amp;gt; 0;
                    });

                    console.log(filtered);
                    logger.clear();
                    logger.log(filtered);
                    allPosts.length = 0;
                });
            };

        update.switchButtonMessage(&quot;Getting posts...&quot;, &quot;green&quot;);
        isProcessing = true;

        get(pageToken);
    };
updateButton.click(function () {
    if (isProcessing) {
        return update.changeButtonMessage(&quot;Busy; try again later&quot;, &quot;red&quot;);
    }

    getPosts();
});

getPosts();
&lt;/pre&gt;&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Atomic Rooster&quot;,
  name : &quot;Seven Lonely Streets&quot;,
  link : &#39;http://grooveshark.com/s/Seven+Lonely+Streets/345YtP?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/using-blogger-api-to-search-within.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSR2FeBf-Y7TT5aVSbYhyphenhyphenZIJox8Br4e4X-HE_3BDYBerJRKz4hbjI1JAHt0A6hEO0tg-FqEj3E4bAqQHRktsR8TeeX4u2Hg1m7nplsgzPdiqIXXmbinP83WrinC7OubQZQJiiRxfEb2Aw/s72-c/BlogScriptsSearcher.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-2607515549618732889</guid><pubDate>Fri, 19 Apr 2013 21:42:00 +0000</pubDate><atom:updated>2013-05-08T00:19:29.100+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">NGUI</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Fading a UITexture&#39;s opacity within a panel in NGUI</title><description>Here is a common scenario I&#39;m commonly finding myself into: changing a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UITexture&lt;/span&gt;&#39;s opacity using its parent &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UIPanel&lt;/span&gt;&#39;s alpha field.&lt;br /&gt;
&lt;br /&gt;
The first time I tried this out, I couldn&#39;t get it to work.  I was changing the opacity of the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UIPanel&lt;/span&gt; using the alpha field but the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UITexture&lt;/span&gt; inside the panel wasn&#39;t fading.&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPt3y-Rma1XzorEKBH75Y3iyjafFsdSFGkKKMOFINlYIDNY_KXt_o41sP0a8S3D5Ruop2TSCW0-mgAO6s-et9TsArvo3nUL2oZ97TsfSc-fOgFKNStihNB5oY5Uib-8VmHY_g0fvN025o/s1600/NoTransparentUITexture.PNG&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
Long story short, you need to change the Shader of your &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;UITexture&lt;/span&gt; to something like &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Unlit/Transparent Colored&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheQrARhtUP96nwjsYCbKuIzD1Zv_G5DLwN87SrM1dqaaU2NmH_YpO0dbHBQTPULvCPrcqSO_pSm69Eqw2EayMbdubo9lfopuLirlttswj6HKPBjwv-uCnv98BoS-n5QW_aznuDv3ZtzbQ/s1600/UnlitTransparentShader.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheQrARhtUP96nwjsYCbKuIzD1Zv_G5DLwN87SrM1dqaaU2NmH_YpO0dbHBQTPULvCPrcqSO_pSm69Eqw2EayMbdubo9lfopuLirlttswj6HKPBjwv-uCnv98BoS-n5QW_aznuDv3ZtzbQ/s320/UnlitTransparentShader.png&quot; /&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;
And this will give you the result you desired:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEB8s2fgSZl43JRRUuIGmzSsqUTzenpCOdT2PfuZdBULNPuCv3ft3mmiD8Kwc_xPKmKyye4N61dR1050ImrFCQZnuCkJvxWi-jsWf6AuZUGCgFX8G_26LR5piSoWFpc6qh5ICUxPYwMJE/s1600/TransparentUITexture.PNG&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
This is how it can be done programatically in C#:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;var uiTexture = powerupTexture.AddComponent&amp;lt;UITexture&amp;gt;();
uiTexture.shader = Shader.Find(&quot;Unlit/Transparent Colored&quot;);
&lt;/pre&gt;</description><link>http://blog.dreasgrech.com/2013/04/fading-uitextures-opacity-within-panel.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPt3y-Rma1XzorEKBH75Y3iyjafFsdSFGkKKMOFINlYIDNY_KXt_o41sP0a8S3D5Ruop2TSCW0-mgAO6s-et9TsArvo3nUL2oZ97TsfSc-fOgFKNStihNB5oY5Uib-8VmHY_g0fvN025o/s72-c/NoTransparentUITexture.PNG" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-3626673571657228475</guid><pubDate>Fri, 12 Apr 2013 15:24:00 +0000</pubDate><atom:updated>2013-04-12T17:24:25.371+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Clearing the browser cache of the Unity Web Player</title><description>For my current Unity web project, I am downloading scenes as AssetBundles hosted on my server, and now I have found myself constantly uploading the updated scenes whenever I make these (constant) changes.&lt;br /&gt;
&lt;br /&gt;
Problem is, when I try the game online to see how the downloaded scene looks, my main game file which is downloading these scenes keeps on using the cached scenes from before.&lt;br /&gt;
&lt;br /&gt;
That&#39;s because I am downloading the AssetBundles using &lt;a href=&quot;http://docs.unity3d.com/Documentation/ScriptReference/WWW.LoadFromCacheOrDownload.html&quot; target=&quot;_blank&quot;&gt;WWW.LoadFromCacheOrDownload&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
To clear the cache, just head on over to &lt;a href=&quot;http://unity3d.com/webplayer_setup/setup-3.x/&quot; target=&quot;_blank&quot;&gt;http://unity3d.com/webplayer_setup/setup-3.x/&lt;/a&gt; where you will see something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrhubTatq3WQ1H1LeFX-qHmznEzQn6B83WcczbqwHB-4EQpFEnS_Kbqit6Tdh-2lD1ZEIBVQYGcrP0qT3QxZSiqd8nKGiepDO8347ro4OUuMPuCw3VNsQ1W2TpzL6_9FmtM4aA1zOpCaI/s1600/WebPlayerSettings.PNG&quot; imageanchor=&quot;1&quot; &gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrhubTatq3WQ1H1LeFX-qHmznEzQn6B83WcczbqwHB-4EQpFEnS_Kbqit6Tdh-2lD1ZEIBVQYGcrP0qT3QxZSiqd8nKGiepDO8347ro4OUuMPuCw3VNsQ1W2TpzL6_9FmtM4aA1zOpCaI/s320/WebPlayerSettings.PNG&quot; /&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;
And from there, you can simply delete the cache, or even make sure that while you&#39;re still working on the game, don&#39;t keep a cache at all.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Gong&quot;,
  name : &quot;The Isle Of Everywhere&quot;,
  link : &#39;http://grooveshark.com/s/The+Isle+Of+Everywhere/3gqxqq?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/clearing-browser-cache-of-unity-web.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrhubTatq3WQ1H1LeFX-qHmznEzQn6B83WcczbqwHB-4EQpFEnS_Kbqit6Tdh-2lD1ZEIBVQYGcrP0qT3QxZSiqd8nKGiepDO8347ro4OUuMPuCw3VNsQ1W2TpzL6_9FmtM4aA1zOpCaI/s72-c/WebPlayerSettings.PNG" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-6026207097783557381</guid><pubDate>Thu, 11 Apr 2013 15:26:00 +0000</pubDate><atom:updated>2013-04-11T21:20:41.402+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Kongregate</category><category domain="http://www.blogger.com/atom/ns#">Unity 3D</category><title>Showing a Kongregate user&#39;s avatar image in a Unity 3D game</title><description>I decided that the game I&#39;m currently working on is going to be tied to Kongregate, and since I&#39;m doing that, might as well try to use as many features of the API as I can.&lt;br /&gt;
&lt;br /&gt;
One of the features I&#39;m trying to integrate in my game is the ability to render a Kongregate user&#39;s avatar in the game itself.  For this tutorial, I will be using Kongregate&#39;s JSON REST API to fetch user data.&lt;br /&gt;
&lt;br /&gt;
After skimming through the Kongregate API documentation, I found the page about the &lt;a href=&quot;http://developers.kongregate.com/docs/rest/user-info&quot; target=&quot;_blank&quot;&gt;user-info&lt;/a&gt; REST call.&lt;br /&gt;
&lt;br /&gt;
The url for a user-info call is formatted as follows: http://www.kongregate.com/api/user_info.json?username=&lt;b&gt;&amp;lt;username&amp;gt;&lt;/b&gt; where username is obviously the username for the user account you&#39;re searching for.&lt;br /&gt;
&lt;br /&gt;
This provides you with a response such as the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;{
   &quot;friends&quot;:[],
   &quot;muted_users&quot;:[],
   &quot;friend_ids&quot;:[],
   &quot;muted_user_ids&quot;:[],
   &quot;user_id&quot;:3590097,
   &quot;username&quot;:&quot;agnt666&quot;,
   &quot;private&quot;:false,
   &quot;page_num&quot;:1,
   &quot;num_pages&quot;:1,
   &quot;success&quot;:true,
   &quot;user_vars&quot;:{
      &quot;username&quot;:&quot;agnt666&quot;,
      &quot;level&quot;:3,
      &quot;points&quot;:165,
      &quot;avatar_url&quot;:&quot;http://cdn4.kongcdn.com/assets/resize-image/50x50/assets/avatars/defaults/ant.png&quot;,
      &quot;chat_avatar_url&quot;:&quot;http://cdn4.kongcdn.com/assets/resize-image/16x16/assets/avatars/defaults/ant.png&quot;,
      &quot;developer&quot;:false,
      &quot;moderator&quot;:false,
      &quot;admin&quot;:false,
      &quot;gender&quot;:&quot;Male&quot;,
      &quot;age&quot;:25,
      &quot;game_title&quot;:&quot;Typocalypse 3D&quot;,
      &quot;game_url&quot;:&quot;http://www.kongregate.com/games/agnt666/typocalypse-3d&quot;
   }
}
&lt;/pre&gt;&lt;br /&gt;
And the above response provides me with what I needed; the avatar url:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-javascript&quot; name=&quot;code&quot;&gt;&quot;avatar_url&quot; : &quot;http://cdn4.kongcdn.com/assets/resize-image/50x50/assets/avatars/defaults/ant.png&quot;
&lt;/pre&gt;&lt;br /&gt;
&lt;center&gt;&lt;img src=&quot;http://cdn4.kongcdn.com/assets/resize-image/50x50/assets/avatars/defaults/ant.png&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
&lt;h5&gt;Getting the avatar url in C#&lt;/h5&gt;Getting the username of the current Kongregate logged-in user is beyond the scope of this post (TODO: maybe in another one), so for this code I&#39;m assuming you already have it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;public UITexture kongregateTexture;

IEnumerator FetchUserDetails(string username) {
    // Build the url for the REST call
    var detailsUrl = String.Format(&quot;/api/user_info.json?username={0}&quot;, username);

    // Do the call 
    var www = new WWW(detailsUrl);

    // ...and wait until we get back a response
    yield return www;

    // Get the JSON response text
    var responseText = www.text;

    // Deserialize it into a statically typed object to read to be able to read it&#39;s contents
    // For this demo, I&#39;m using this JSON deserializer script: https://raw.github.com/gist/1411710/MiniJSON.cs
    var deserialized = MiniJSON.Json.Deserialize(responseText) as Dictionary&amp;lt;string,object&amp;gt;;

    //// TODO: a null check would be nice here

    // Get the user_vars object
    var userVars = deserialized[&quot;user_vars&quot;] as Dictionary&amp;lt;string,object&amp;gt;;

    // Read the avatar url
    var avatar_url = user_vars[&quot;avatar_url&quot;].ToString(); // http://cdn4.kongcdn.com/assets/resize-image/50x50/assets/avatars/defaults/ant.png

    //// Do the same routine to fetch the image
    var wwwAvatar = new WWW(avatar_url);
    yield return wwwAvatar;

    // And now we have the texture!
    Texture2D avatarTexture = wwwAvatar.texture;

    // Render the texture (I&#39;m using an NGUI SimpleTexture widget)
    kongregateTexture.mainTexture = avatarTexture;
}
&lt;/pre&gt;&lt;br /&gt;
And this is the result &lt;i&gt;with a shitty border I made around it&lt;/i&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH1bzwRpBeSsE0Y2rHnIpIXBWS7_kWin7yh7EWccZ1RXQ-K87j000EN3JGEgYqOCSDA5-JX3tHaq7WOTO7KmcTQw1bkK4N_w0AUz2drlYQafo-CX6gTrFAKd3pi0T2wqR-k92yRCJ_9jI/s1600/AntAvatar.PNG&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH1bzwRpBeSsE0Y2rHnIpIXBWS7_kWin7yh7EWccZ1RXQ-K87j000EN3JGEgYqOCSDA5-JX3tHaq7WOTO7KmcTQw1bkK4N_w0AUz2drlYQafo-CX6gTrFAKd3pi0T2wqR-k92yRCJ_9jI/s1600/AntAvatar.PNG&quot; /&gt;&lt;/a&gt;&lt;/center&gt;&lt;br /&gt;
&lt;h5&gt;Possible exception: &lt;span style=&quot;color: red;&quot;&gt;Security Exception: No valid crossdomain policy available to allow access&lt;/span&gt;&lt;/h5&gt;Notice that in the above code, to build the url of the REST call, I used Kongregate&#39;s relative url: &quot;/api/user-info.json...&quot;.&lt;br /&gt;
&lt;br /&gt;
If I had used this instead &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;String.Format(&quot;http://www.kongregate.com/api/user_info.json?username={0}&quot;, username);&lt;/span&gt;, I would have received this exception when running the game and looking at the debug log (console):&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyISD4PS91sks6GiutcDt4Xe23HdGEZazGFbDv0fxnR7u-MuEsETqOKA7_dYR_DpRKBGgrBl5J2N_i-jcB7rre7FaUEPBALGNvj4Ae5WFimrX-L3g-s-kTXBUyti58M9EB3T9RqAnnQFU/s1600/SecurityException.PNG&quot; /&gt;&lt;/center&gt;&lt;br /&gt;
This error is thrown when reading the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;text&lt;/span&gt; field of the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;WWW&lt;/span&gt; instance (&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;get_text&lt;/span&gt;).&lt;br /&gt;
&lt;br /&gt;
So be very careful about that when doing the REST calls; always use relative urls! &lt;i&gt;...and this of course works because the game is hosted on http://www.kongregate.com.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Gong&quot;,
  name : &quot;Fohat Digs Holes in Space&quot;,
  link : &#39;http://grooveshark.com/s/Fohat+Digs+Holes+In+Space/3gqECc?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/showing-kongregate-users-avatar-image.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH1bzwRpBeSsE0Y2rHnIpIXBWS7_kWin7yh7EWccZ1RXQ-K87j000EN3JGEgYqOCSDA5-JX3tHaq7WOTO7KmcTQw1bkK4N_w0AUz2drlYQafo-CX6gTrFAKd3pi0T2wqR-k92yRCJ_9jI/s72-c/AntAvatar.PNG" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-4845959405375034691</guid><pubDate>Mon, 08 Apr 2013 15:25:00 +0000</pubDate><atom:updated>2013-04-08T17:30:12.602+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">T4</category><title>Auto-Generating generic Tuple classes with T4 in C#</title><description>And yet again, here&#39;s another perfect example for using the T4 code generation toolkit in Visual Studio.&lt;br /&gt;
&lt;br /&gt;
For a recent project, I wanted to use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.tuple.aspx&quot; target=&quot;_blank&quot;&gt;Tuple&lt;/a&gt; class provided in the .NET Framework...problem was, I was stuck with .NET 3.5 and the Tuple class was introduced in version 4 of the framework.  So, instead of writing a single Tuple class by hand (which would have been very trivial to do), I decided to write a T4 template which would generate all the Tuple classes I needed automatically.&lt;br /&gt;
&lt;br /&gt;
The template itself is very trivial and the number of Tuple classes it generates is dependent on the value that I specify in the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;max&lt;/span&gt; variable at the top of the template.&lt;br /&gt;
&lt;br /&gt;
For each of the Tuple classes the template generates, it creates a contructor which accepts all of the properties that the tuple will contain and also the actual properties that will be accessed from the outside.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s an example of what the template autogenerates for me when using &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;max = 3&lt;/span&gt; (granted, the first class it generates is a bit pointless but that can be easily omitted from within the template if it bothers you):&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;namespace FunWithTuples
{
    /// &amp;lt;summary&amp;gt;
    /// Represents a 1-tuple
    /// &amp;lt;/summary&amp;gt;
    public class Tuple&amp;lt;T1&amp;gt;
    {
        public T1 Item1 { get; set; }

        public Tuple(T1 item1) 
        {
            Item1 = item1;
        }
    }

    /// &amp;lt;summary&amp;gt;
    /// Represents a 2-tuple
    /// &amp;lt;/summary&amp;gt;
    public class Tuple&amp;lt;T1, T2&amp;gt;
    {
        public T1 Item1 { get; set; }
        public T2 Item2 { get; set; }

        public Tuple(T1 item1, T2 item2) 
        {
            Item1 = item1;
            Item2 = item2;
        }
    }

    /// &amp;lt;summary&amp;gt;
    /// Represents a 3-tuple
    /// &amp;lt;/summary&amp;gt;
    public class Tuple&amp;lt;T1, T2, T3&amp;gt;
    {
        public T1 Item1 { get; set; }
        public T2 Item2 { get; set; }
        public T3 Item3 { get; set; }

        public Tuple(T1 item1, T2 item2, T3 item3) 
        {
            Item1 = item1;
            Item2 = item2;
            Item3 = item3;
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
And this is the full T4 Template:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;&lt;#@ template debug=&quot;false&quot; hostspecific=&quot;false&quot; language=&quot;C#&quot; #&gt;
&lt;#@ assembly name=&quot;System.Core&quot; #&gt;
&lt;#@ import namespace=&quot;System.Linq&quot; #&gt;
&lt;#@ import namespace=&quot;System.Text&quot; #&gt;
&lt;#@ import namespace=&quot;System.Collections.Generic&quot; #&gt;
&lt;#@ output extension=&quot;.cs&quot; #&gt;

&lt;#
var max = 3; // The total number of classes to generate
#&gt;
namespace FunWithTuples
{
&lt;#
max += 1;
for (var i = 1; i &lt; max; ++i) {
#&gt;
    /// &lt;summary&gt;
    /// Represents a &lt;#=i#&gt;-tuple
    /// &lt;/summary&gt;
    public class Tuple&lt;#=GetGenericTypesSignature(i)#&gt;
    {
&lt;#
for (var j = 1; j &lt; i + 1; ++j) {
#&gt;
        public T&lt;#=j#&gt; Item&lt;#=j#&gt; { get; set; }
&lt;#
}
#&gt;

        public Tuple(&lt;#=GetConstructorArguments(i)#&gt;) 
        {
&lt;#
for (var j = 1; j &lt; i + 1; ++j) {
#&gt;
            Item&lt;#=j#&gt; = item&lt;#=j#&gt;;
&lt;#
}
#&gt;
        }
    }

&lt;#
}
#&gt;
}
&lt;#+
    public string GetGenericTypesSignature(int total) {
        return String.Format(&quot;&lt;{0}&gt;&quot;, String.Join(&quot;, &quot;, Enumerable.Range(1, total).Select(n =&gt; &quot;T&quot; + n).ToArray()));
    }

    public string GetConstructorArguments(int total) {
        return String.Join(&quot;, &quot;, Enumerable.Range(1, total).Select(n =&gt; String.Format(&quot;T{0} item{0}&quot;, n)).ToArray());
    }
#&gt;

&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Falcon&#39;s Flying Circus&quot;,
  name : &quot;On the side of the road&quot;,
  link : &#39;http://grooveshark.com/s/On+The+Side+Of+The+Road/2qW7G9?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/auto-generating-generic-tuple-classes.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-3922856598899264686</guid><pubDate>Fri, 05 Apr 2013 10:17:00 +0000</pubDate><atom:updated>2013-04-05T12:17:33.701+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">LaTeX</category><title>Absolute value bars for fractions in LaTeX</title><description>The simplest way on how to include |absolute value| bars in LaTeX is to use the this notation: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;\left|&lt;/span&gt; and &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;\right|&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s an example: &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;y = &lt;b&gt;\left|&lt;/b&gt;\frac{1}{x}&lt;b&gt;\right|&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And that would be rendered as:&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://latex.codecogs.com/gif.latex?y=\left|\frac{1}{x}\right|&quot; title=&quot;y=\left|\frac{1}{x}\right|&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Herbie Mann&quot;,
  name : &quot;Bitch&quot;,
  link : &#39;http://grooveshark.com/s/Bitch/3AVJOw?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/absolute-value-bars-for-fractions-in.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-4619887384037024724</guid><pubDate>Fri, 05 Apr 2013 10:01:00 +0000</pubDate><atom:updated>2013-04-05T12:02:08.403+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">CIL</category><title>Common CIL incantations</title><description>Since I recently decided to try my hand at CIL by writing assemblies by hand, I&#39;m now writing this post where I will list down a couple of basic CIL routines.&lt;br /&gt;
&lt;br /&gt;
I am of course primarily writing this post for myself so that future me will have a reference if he (I?) decides to do something with it again.&lt;br /&gt;
&lt;br /&gt;
&lt;h5&gt;&lt;i&gt;Hello World&lt;/i&gt;&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.assembly helloworld {}
.assembly extern mscorlib {}

.method public static void Main () {
    .entrypoint
    ldstr &quot;Hello World!&quot;
    call void [mscorlib]System.Console::WriteLine(string)
    ret
}&lt;/pre&gt;&lt;h5&gt;Including external assemblies&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.assembly extern mscorlib {}
&lt;/pre&gt;&lt;h5&gt;Pushing a 32 bit integer constant to the stack&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;ldc.i4 42
&lt;/pre&gt;&lt;h5&gt;Pushing a 64 bit integer constant to the stack&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;ldc.i8 829190
&lt;/pre&gt;&lt;h5&gt;Pushing a string constant to the stack&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;ldstr &quot;Andreas&quot;
&lt;/pre&gt;&lt;h5&gt;Declaring and loading unnamed variables (popping elements off the stack)&lt;br /&gt;
&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.locals init (int32, string) // init specifies that the variables must be initialized to the default types
ldc.i4 42
stloc.0 // storing the 32 bit integer at position 0 by popping it off the stack
ldstr &quot;CIL&quot;
stloc.1
&lt;/pre&gt;&lt;h5&gt;Defining a class&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.class MathHelpers extends [mscorlib]System.Object {
    .method void .ctor() { // Constructor
        ldarg.0
        call instance void [mscorlib]System.Object::.ctor()
    }

    .method public instance int32 Inc(int32) { // Instance method; the instance keyword can be omitted
        ldarg.0
        ldc.i4.1
        add
        ret
    }
    
    .method public static int32 Add(int32 n, int32 m) {  // Static method
        ldarg n
        ldarg m
        add
        ret
    }
}&lt;/pre&gt;&lt;h5&gt;Invoking methods from external assemblies&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.assembly extern mscorlib {}

// ...

ldstr &quot;Writelining&quot;
call void [mscorlib]System.Console::WriteLine(string)&lt;/pre&gt;&lt;h5&gt;Invoking an instance method&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.locals init (class MathHelpers mh)

newobj instance void MathHelpers::.ctor()
stloc mh

call instance void MathHelpers::Show()
&lt;/pre&gt;&lt;h5&gt;Invoking a static method&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;call void MyNamespace.MyClass::StaticMethod()&lt;/pre&gt;&lt;h5&gt;Using an array&lt;/h5&gt;&lt;pre class=&quot;sunlight-highlight-msil&quot; name=&quot;code&quot;&gt;.locals init (string[] names);

.ldc.i4.4 // the int32 constant that&#39;s used for the size of the array: new string[4]
newarr string
stloc names

// Add element 0
ldloc names
ldc.i4.0 // array index
ldstr &quot;Dreas&quot;
stelem.ref

// Add element 1
ldloc names
ldc.i4.1 // array index
ldstr &quot;John&quot;
stelem.ref&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Falcon&#39;s Flying Circus&quot;,
  name : &quot;No Returns&quot;,
  link : &#39;http://grooveshark.com/s/No+Returns/2qW91C?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/common-cil-incantations.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-5752784885250076564</guid><pubDate>Fri, 05 Apr 2013 09:27:00 +0000</pubDate><atom:updated>2013-04-05T11:27:12.169+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Adding a line break for IntelliSense in XML documentation comments</title><description>This is a quick post on how to insert a line break for XML documentation comments in C#.&lt;br /&gt;
&lt;br /&gt;
The easiest way I&#39;ve found is to use a &lt;a href=&quot;http://www.theasciicode.com.ar/extended-ascii-code/non-breaking-space-no-break-space-ascii-code-255.html&quot; target=&quot;_blank&quot;&gt;non breaking space&lt;/a&gt; (ASCII code 255) in combination with the paragraph tags: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;para&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To insert the non breaking space, press ALT + 255 (from the numeric keypad).&lt;br /&gt;
&lt;br /&gt;
Here&#39;s an example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;/// &amp;lt;summary&amp;gt;
/// &amp;lt;para&amp;gt;This method does everything.&amp;lt;/para&amp;gt;
/// &amp;lt;para&amp;gt;&amp;nbsp;&amp;lt;/para&amp;gt;
/// &amp;lt;para&amp;gt;...and I mean everything.&amp;lt;/para&amp;gt;
/// &amp;lt;/summary&amp;gt;
private void DoEverything() {
&lt;/pre&gt;&lt;br /&gt;
And this is how it looks in IntelliSense:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi44OR6pH5eEycmcOl6-C07AUiRhnZVsTvgCwIEuXQ337eRBY1Vq35p3LOOTYsrZTi6OFNG7rkcXSQIAqaYtrdCiQk_OcGH1i16s3bcI3pB7yYy9YngPy44CCg783Cqa0tFq33er-W4Kgk/s1600/IntelliSenseBreakingLine.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi44OR6pH5eEycmcOl6-C07AUiRhnZVsTvgCwIEuXQ337eRBY1Vq35p3LOOTYsrZTi6OFNG7rkcXSQIAqaYtrdCiQk_OcGH1i16s3bcI3pB7yYy9YngPy44CCg783Cqa0tFq33er-W4Kgk/s320/IntelliSenseBreakingLine.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Falcon&#39;s Flying Circus&quot;,
  name : &quot;Living Free&quot;,
  link : &#39;http://grooveshark.com/s/Living+Free/2qWaEI?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/04/adding-line-break-for-intellisense-in.html</link><author>noreply@blogger.com (Andreas Grech)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi44OR6pH5eEycmcOl6-C07AUiRhnZVsTvgCwIEuXQ337eRBY1Vq35p3LOOTYsrZTi6OFNG7rkcXSQIAqaYtrdCiQk_OcGH1i16s3bcI3pB7yYy9YngPy44CCg783Cqa0tFq33er-W4Kgk/s72-c/IntelliSenseBreakingLine.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-178369281218745809</guid><pubDate>Tue, 26 Feb 2013 15:08:00 +0000</pubDate><atom:updated>2013-02-26T16:08:04.539+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Vim</category><title>Preventing Vim from automatically inserting line breaks</title><description>I recently had a very frustrating issue with Vim where it was inserting a line break automatically for me whenever a line exceeded the 80 character mark.&lt;br /&gt;
&lt;br /&gt;
After some searching around, I realized that I had &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;textwidth&lt;/span&gt; (&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tw&lt;/span&gt;) set to 79 in my &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;_vimrc&lt;/span&gt; file.  From the documentation:&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;blockquote&gt;textwidth.&lt;br /&gt;
Maximum width of text that is being inserted.  A longer line will be broken after white space to get this width.  A zero value disables this.&lt;/blockquote&gt;&lt;/center&gt;&lt;br /&gt;
So as you can see from the documentation, fixing it was very trivial: &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set tw = 0&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;Jimi Hendrix&quot;,
  name : &quot;Love Or Confusion&quot;,
  link : &#39;http://grooveshark.com/s/Love+Or+Confusion/38HQ54?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2013/02/preventing-vim-from-automatically.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7117612757607239790.post-1896368516371084412</guid><pubDate>Wed, 19 Dec 2012 13:18:00 +0000</pubDate><atom:updated>2012-12-19T14:31:19.340+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">T4</category><title>Auto-Generating EventArgs classes with T4</title><description>T4 is a code generator built into Visual Studio.  In this post, I will present a T4 template file which I&#39;ve used to help auto-generate Event Arguments classes in C#.&lt;br /&gt;
&lt;br /&gt;
Normally, event arguments classes always follow the same structure.  You typically have a set of public properties in a class which extends &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.eventargs.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;EventArgs&lt;/span&gt;&lt;/a&gt; and a constructor which takes in the same number of formal arguments.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s a typical event arguments class:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;public class OperationCompletedEventArgs : EventArgs
{
    public bool Result { get; private set; }

    public OperationCompletedEventArgs(bool result)
    {
        Result = result;
    }
}
&lt;/pre&gt;&lt;br /&gt;
Given the repetitive nature of how typical event arguments classes are structured, they make a perfect fit for an example of code generation.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
The intent of my template file for generating event arguments classes is to be able to define a declaration of what classes I want to be generated and then let the template generate those classes for me.&lt;br /&gt;
&lt;br /&gt;
The declaration part of the template looks something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;var collection = new List&amp;lt;EventArgumentsRepresentation&amp;gt;
                 {
                     new EventArgumentsRepresentation(&quot;OperationCompleted&quot;)
                     {
                         Members = new Dictionary&amp;lt;string, string&amp;gt; { 
                             {&quot;Result&quot;, &quot;bool&quot;}
                         }
                     },
                     new EventArgumentsRepresentation(&quot;GenericAndPartial&quot;)
                         {
                             AccessModifier = &quot;internal&quot;,
                             IsPartial = true,
                             GenericTypes = new List&amp;lt;string&amp;gt;() { &quot;T&quot;, &quot;TK&quot;},
                             Members = new Dictionary&amp;lt;string, string&amp;gt; { 
                                 {&quot;GenericMember1&quot;, &quot;T&quot;},
                                 {&quot;GenericMember2&quot;, &quot;TK&quot;}
                             }
                         }
                 };

&lt;/pre&gt;&lt;br /&gt;
Given the above structure, the template would then generate the following two classes for me:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;public class OperationCompletedEventArgs : EventArgs
{
    public bool Result { get; private set; }

    public OperationCompletedEventArgs(bool result) 
    {
        Result = result;
    }
}

internal partial class GenericAndPartialEventArgs&amp;lt;T, TK&amp;gt; : EventArgs
{
    public T GenericMember1 { get; private set; }
    public TK GenericMember2 { get; private set; }

    public GenericAndPartialEventArgs(T genericMember1, TK genericMember2) 
    {
        GenericMember1 = genericMember1;
        GenericMember2 = genericMember2;
    }
}
&lt;/pre&gt;&lt;br /&gt;
The next I would want a new event arguments class, I would just add a new instance of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;EventArgumentsRepresentation&lt;/span&gt; to the list and let the template do the work.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
And now, for the entire template file.  If you want to use it for your own projects, create a new &quot;Text Template&quot; (.tt file) in Visual Studio and copy the below template into it.  Once you then save the template file, the classes will be generated into a .cs file.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;sunlight-highlight-csharp&quot; name=&quot;code&quot;&gt;&amp;lt;#@ template debug=&amp;quot;false&amp;quot; hostspecific=&amp;quot;false&amp;quot; language=&amp;quot;C#&amp;quot; #&amp;gt;
&amp;lt;#@ assembly name=&amp;quot;System.Core&amp;quot; #&amp;gt;
&amp;lt;#@ import namespace=&amp;quot;System.Linq&amp;quot; #&amp;gt;
&amp;lt;#@ import namespace=&amp;quot;System.Collections.Generic&amp;quot; #&amp;gt;
&amp;lt;#@ output extension=&amp;quot;.cs&amp;quot; #&amp;gt;

&amp;lt;#
var namespaceName = &amp;quot;EventArgumentsGenerationDemo&amp;quot;;
var usings = new List&amp;lt;string&amp;gt; {
    &amp;quot;System&amp;quot;,
};

var collection = new List&amp;lt;EventArgumentsRepresentation&amp;gt;
                 {
                     new EventArgumentsRepresentation(&amp;quot;OperationCompleted&amp;quot;)
                     {
                         Members = new Dictionary&amp;lt;string, string&amp;gt; { 
                             {&amp;quot;Result&amp;quot;, &amp;quot;bool&amp;quot;},
                         },
                     },
                     new EventArgumentsRepresentation(&amp;quot;GenericAndPartial&amp;quot;)
                         {
                             AccessModifier = &amp;quot;internal&amp;quot;,
                             IsPartial = true,
                             GenericTypes = new List&amp;lt;string&amp;gt;() { &amp;quot;T&amp;quot;, &amp;quot;TK&amp;quot;},
                             Members = new Dictionary&amp;lt;string, string&amp;gt; { 
                                 {&amp;quot;GenericMember1&amp;quot;, &amp;quot;T&amp;quot;},
                                 {&amp;quot;GenericMember2&amp;quot;, &amp;quot;TK&amp;quot;},
                             },
                         },
                     
                 };
#&amp;gt;
namespace &amp;lt;#=namespaceName#&amp;gt;
{
&amp;lt;#
foreach (var usingDirective in usings) {
#&amp;gt;
    using &amp;lt;#=usingDirective#&amp;gt;;
&amp;lt;#
}
#&amp;gt;

    /*
     * This file is autogenerated.  
     *
     * If you want to edit anything from here, use the EventArgumentsClasses.tt file.
     */

&amp;lt;#
foreach (var eventArgsRepresentation in collection) {
#&amp;gt;
    &amp;lt;#=eventArgsRepresentation.ClassSignature#&amp;gt;
    {
&amp;lt;#
foreach (var member in eventArgsRepresentation.Members) {
#&amp;gt;
        public &amp;lt;#=member.Value#&amp;gt; &amp;lt;#=EventArgumentsRepresentation.ToPascalCase(member.Key)#&amp;gt; { get; private set; }
&amp;lt;#
}
#&amp;gt;

        public &amp;lt;#=eventArgsRepresentation.ClassName#&amp;gt;(&amp;lt;#=eventArgsRepresentation.GetConstructorArguments()#&amp;gt;) 
        {
&amp;lt;#
foreach (var member in eventArgsRepresentation.Members) {
#&amp;gt;
            &amp;lt;#=EventArgumentsRepresentation.ToPascalCase(member.Key)#&amp;gt; = &amp;lt;#=EventArgumentsRepresentation.ToCamelCase(member.Key)#&amp;gt;;
&amp;lt;#
}
#&amp;gt;
        }
    }

&amp;lt;#
}
#&amp;gt;
}

&amp;lt;#+
internal class EventArgumentsRepresentation
{
    public string ClassName { get; private set; }

    public string AccessModifier { get; set; }
    public bool IsPartial { get; set; }
    public List&amp;lt;string&amp;gt; GenericTypes {get; set;}
    public Dictionary&amp;lt;string, string&amp;gt; Members { get; set; }
    public string ClassSignature {
        get {
            return String.Format(&amp;quot;{0} {1}class {2}{3} : EventArgs&amp;quot;, AccessModifier, IsPartial ? &amp;quot;partial &amp;quot; : &amp;quot;&amp;quot;, ClassName, GetGenericTypesSignature());
        }
    }

    public EventArgumentsRepresentation(string name)
    {
        ClassName = String.Format(&amp;quot;{0}EventArgs&amp;quot;, ToPascalCase(name));
        AccessModifier = &amp;quot;public&amp;quot;;
        GenericTypes = new List&amp;lt;string&amp;gt;();
        Members = new Dictionary&amp;lt;string, string&amp;gt;();
    }

    public string GetGenericTypesSignature() {
        if (GenericTypes.Count &amp;lt; 1) {
            return &amp;quot;&amp;quot;;
        }

        return String.Format(&amp;quot;&amp;lt;{0}&amp;gt;&amp;quot;, string.Join(&amp;quot;, &amp;quot;, GenericTypes.ToArray()));
    }

    public string GetConstructorArguments() {
        if (Members == null || Members.Count &amp;lt; 1) {
            return &amp;quot;&amp;quot;;
        }

        return String.Join(&amp;quot;, &amp;quot;, Members.Select(k =&amp;gt; String.Format(&amp;quot;{0} {1}&amp;quot;, k.Value, ToCamelCase(k.Key))).ToArray());
    }

    public static string ToPascalCase(string text) {
        return char.ToUpper(text[0]) + text.Substring(1);
    }

    public static string ToCamelCase(string text) {
        return char.ToLower(text[0]) + text.Substring(1);
    }
}
#&amp;gt;
&lt;/pre&gt;&lt;div class=&quot;blogmusic&quot;&gt;&lt;script&gt;
kaholic.blogmusic([
{ artist : &quot;The Jimi Hendrix Experience&quot;,
  name : &quot;Wait Until Tomorrow&quot;,
  link : &#39;http://grooveshark.com/s/Wait+Until+Tomorrow/1MO3hd?src=5&#39;
}
]);
&lt;/script&gt;&lt;/div&gt;</description><link>http://blog.dreasgrech.com/2012/12/auto-generating-eventargs-classes-with.html</link><author>noreply@blogger.com (Andreas Grech)</author><thr:total>0</thr:total></item></channel></rss>