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

<channel>
	<title>Chris Danielson&#039;s Blog</title>
	<atom:link href="http://www.chrisdanielson.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdanielson.com</link>
	<description>Trials and Tribulations of a Software Developer</description>
	<lastBuildDate>Tue, 10 Apr 2012 17:15:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Linux Firmware Keyspan USB to Serial</title>
		<link>http://www.chrisdanielson.com/2012/04/10/linux-firmware-keyspan-usb-to-serial/</link>
		<comments>http://www.chrisdanielson.com/2012/04/10/linux-firmware-keyspan-usb-to-serial/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 17:15:23 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=613</guid>
		<description><![CDATA[I'm a huge fan of the old Keyspan USB to Serial product.  Looking for the difficult to find USB to Serial Keyspan firmware driver kit for Linux?]]></description>
			<content:encoded><![CDATA[<p>Just wanted to share the difficult to find firmware that works between Linux and the awesome Keyspan USB to Serial devices.  I love these old Keyspan devices!  Anyways, here is the &#8216;dmesg&#8217; signature for your perusal.</p>
<blockquote><p>New USB device found, idVendor=06cd, idProduct=012a<br />
New USB device strings: Mfr=1, Product=2, SerialNumber=0<br />
Product: Keyspan USA-49WLC<br />
Manufacturer: Keyspan, a division of InnoSys Inc.</p></blockquote>
<p>On Debian 6, &#8220;squeeze&#8221;, and on Ubuntu images I simply copy the &#8220;keyspan.zip&#8221; file to the /lib/firmware/ folder, uncompress it and plug back in the device.  Everything works like a champ from that point on.</p>
<p>Firmware included for:</p>
<blockquote><p>keyspan/mpr.fw<br />
keyspan/usa18x.fw<br />
keyspan/usa19.fw<br />
keyspan/usa19qi.fw<br />
keyspan/usa19qw.fw<br />
keyspan/usa19w.fw<br />
keyspan/usa28.fw<br />
keyspan/usa28xa.fw<br />
keyspan/usa28xb.fw<br />
keyspan/usa28x.fw<br />
keyspan/usa49w.fw<br />
keyspan/usa49wlc.fw</p></blockquote>
<p>Happy coding!</p>
<p><a href="http://www.chrisdanielson.com/wp-content/uploads/2012/04/keyspan.zip">keyspan.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2012/04/10/linux-firmware-keyspan-usb-to-serial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ePub Submission Got You Down?</title>
		<link>http://www.chrisdanielson.com/2011/09/13/epub-submission-got-you-down/</link>
		<comments>http://www.chrisdanielson.com/2011/09/13/epub-submission-got-you-down/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 00:00:51 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[ePub]]></category>
		<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=598</guid>
		<description><![CDATA[Trouble uploading via iTunes Producer an ePub file.]]></description>
			<content:encoded><![CDATA[<p>Today I released my new interactive digital children&#8217;s book, <em>Riley and the Magical Laundry Basket</em> iPhone/iPad application.  I wanted to take the story to the next level by releasing an ePub version into Apple&#8217;s iBookstore.  The story is about Riley as she is transported away to an imaginary world via her magical laundry basket.  In this world she is trying to get to the cupcake palace. <strong>iTunes Link</strong>: <a title="iOS application Riley and the Magical Laundry Basket" href="http://itunes.apple.com/us/app/riley-magical-laundry-basket/id456764124?mt=8" target="_blank">http://itunes.apple.com/us/app/riley-magical-laundry-basket/id456764124?mt=8</a></p>
<div id="attachment_600" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.chrisdanielson.com/wp-content/uploads/2011/09/title1.png"><img class="size-medium wp-image-600" title="Riley and the Magical Laundry Basket" src="http://www.chrisdanielson.com/wp-content/uploads/2011/09/title1-300x225.png" alt="The cover/title of Riley and the Magical Laundry Basket" width="300" height="225" /></a><p class="wp-caption-text">Riley and the Magical Laundry Basket</p></div>
<p>I wanted to release <em>Riley and the Magical Laundry Basket</em> as an ePub book.  I was absolutely ecstatic as my final &#8220;.epub&#8221; file worked flawlessly and looked beautifully in my initial tests on iPad and iPhone.  Today, I decided I was going to move ahead and upload the file using iTunes Producer.  I became frantic as I discovered a host of errors produced by iTunes Producer and when I searched online, I didn&#8217;t find much help!  I&#8217;m going to take the esoteric &#8220;errors&#8221; you see and translate them for any/all people.  If you need help just add in a comment, but these were my basic errors and how I solved them today.</p>
<p>My first error encountered.  This error made me go cross eyed trying to figure out what exactly the trouble was.</p>
<h2>&#8220;length of first filename in archive must be 8, but was 9&#8243;</h2>
<p><strong>Chris&#8217; Translation &amp; Solution</strong>:  make sure that the &#8220;mimetype&#8221; file is the first one compressed into your epub archive file.  Don&#8217;t worry I&#8217;ll show you how to fix it near the end of this post.</p>
<p>My second error:</p>
<h2>&#8220;extra field length for first filename must be 0, but was 28&#8243; at Book (MZItmspBookPackage)</h2>
<p><strong>Chris&#8217; Translation &amp; Solution</strong>: the zip command or tool you are using is adding additional file attributes into the archive or compressed file.</p>
<p>Using the command line (terminal) on my Macbook I was able to fix both these issues.  I changed directory to the root of my epub book and ran the following command.</p>
<p><strong>zip -X -r rmlb.epub mimetype *</strong></p>
<p>The -X listed removes the extra file attributes (from issue #2) shown.  Explicitly defining that the mimetype file is the first file to compress fixes issue #1.  A little further explanation of the command shown&#8230;  The -r means &#8220;recursively&#8221;, basically add everything within the current directory including other sub-directories.  The rmlb.epub is the final name of the .epub file.  The * is a wildcard character telling the zip command to put everything into the archive.</p>
<p>My directory structure looked as follows.</p>
<div id="attachment_603" class="wp-caption aligncenter" style="width: 201px"><a href="http://www.chrisdanielson.com/wp-content/uploads/2011/09/Screen-Shot-2011-09-13-at-11.37.13-AM.png"><img class="size-full wp-image-603" title="Screenshot of my directory structure for Riley and the Magical Laundry Basket the ePub version." src="http://www.chrisdanielson.com/wp-content/uploads/2011/09/Screen-Shot-2011-09-13-at-11.37.13-AM.png" alt="" width="191" height="195" /></a><p class="wp-caption-text">Screenshot of ePub directory structure.</p></div>
<p>I saw many references to using the OEBPS folder, but in this case it is not necessary.  You just have to make sure that you add the &#8220;mimetype&#8221; file first into the archive.</p>
<p>After I did the following command, iTunes Producer accepted my ePub book and now I&#8217;m waiting for Apple&#8217;s approval.</p>
<p>Happy coding and I hope this helps you if you had an issue!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/09/13/epub-submission-got-you-down/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Timer Manager for Unity3D</title>
		<link>http://www.chrisdanielson.com/2011/07/09/timer-manager-for-unity3d/</link>
		<comments>http://www.chrisdanielson.com/2011/07/09/timer-manager-for-unity3d/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 15:49:39 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Time.time]]></category>
		<category><![CDATA[Timer]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=558</guid>
		<description><![CDATA[It&#8217;s been a nearly a month since my last blog entry. Typically people disappear for long periods of time because they&#8217;ve either just begun a romantic charade or they just became insanely busy with work. Well in my case, I&#8217;m already happily married with a sweet little daughter so it&#8217;s clearly a work issue. If [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a nearly a month since my last blog entry.  Typically people disappear for long periods of time because they&#8217;ve either just begun a romantic charade or they just became insanely busy with work.  Well in my case, I&#8217;m already happily married with a sweet little daughter so it&#8217;s clearly a work issue.  If you haven&#8217;t guessed it yet from this site, I&#8217;m actually starting a new company named <a href="http://monkeyprism.com" title="Monkey Prism Home Page" target="_blank">Monkey Prism</a>.  At Monkey Prism we&#8217;re in the midst of an up and coming <a href="http://unity3d.com" title="Unity 3D web site" target="_blank">Unity 3D</a> iOS release.  During our development cycle we were in need of a basic timer object.  This example really serves as an object to learn from on how to use <a href="http://unity3d.com/support/documentation/ScriptReference/Time-time.html" title="Time.time Unity 3D Script Reference" target="_blank">Time.time</a> in your code to create a basic timer.  Feel free to use this code in anyway that you like!</p>
<p>Here is how you call this MPTimer object.<br />
<strong>Example 1</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p558code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5584"><td class="code" id="p558code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//Example 1:</span>
<span style="color: #0600FF; font-weight: bold;">private</span> MPTimer monkeyPrismTimer<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">void</span> Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">/*
   Creates a timer object that will wait 5 seconds before calling 
   the ToggleExample method.  The false flag signifies that this object
   will not start the timer until the 
      monkeyPrismTimer.Active = true;
   has been set.
   */</span>
   monkeyPrismTimer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MPTimer<span style="color: #008000;">&#40;</span>
      <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MPTimerObject<span style="color: #008000;">&#40;</span>gameObject, <span style="color: #666666;">&quot;ToggleExample&quot;</span>, 5<span style="color: #008000;">.</span>0f<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ToggleExample<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ToggleExample() called!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//daisy chain the timer running.  Every time it inactivates, we'll re-activate it.</span>
   <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>monkeyPrismTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Active</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Enabling the timer!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      monkeyPrismTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Active</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
   <span style="color: #008000;">&#125;</span>
&nbsp;
   <span style="color: #008080; font-style: italic;">//drive the timer</span>
   monkeyPrismTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">DoTimer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Example 2 (auto-start the timer)</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p558code5'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5585"><td class="code" id="p558code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> MPTimer monkeyPrismTimer<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">void</span> Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//create a 3 second timer that repeats 10 times.</span>
   MPTimerObject mpTimerObject <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MPTimerObject<span style="color: #008000;">&#40;</span>gameObject, <span style="color: #666666;">&quot;ToggleExample&quot;</span>, 3<span style="color: #008000;">.</span>0f<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
   mpTimerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">repeatCount</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">// repeat it 10 times.</span>
&nbsp;
   <span style="color: #008080; font-style: italic;">//creates a timer object without auto-starting it.</span>
   monkeyPrismTimer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MPTimer<span style="color: #008000;">&#40;</span>mpTimerObject, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ToggleExample<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ToggleExample() called!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//drive the timer</span>
   monkeyPrismTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">DoTimer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The file on my system is named: &#8220;<strong>MPTimer.cs</strong>&#8220;.  Here it is!  The meat and potatoes we&#8217;ve been talking about!</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left2">Download <a href="http://www.chrisdanielson.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=558&amp;download=MPTimer.cs">MPTimer.cs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5586"><td class="code" id="p558code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// A timer object that will be passed into the MPTimer class.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MPTimerObject
<span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The target GameObject that contains the onCompleteMethod specified.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> GameObject target<span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A string representing the method to call when the timer expires.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> onCompleteMethod<span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A float value in seconds representing how often you would like the timer to trigger.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> runForSeconds<span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// An integer value representing the number of times you would like this timer to trigger before becoming inactive.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> repeatCount<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> MPTimerObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Creates a basic Monkey Prism timer object.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;targetCompleteMethodObject&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;GameObject&quot;/&gt; that is the targeted object that contains the &quot;completeMethod&quot; string parameter.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;completeMethod&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;String&quot;/&gt; representing a method named contained within the GameObject specified.  Example:  &quot;myMethod&quot;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;triggerTime&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;System.Single&quot;/&gt; float value in seconds.  5.0f would be 5 seconds.  This tells the timer to trigger in 5 seconds.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> MPTimerObject<span style="color: #008000;">&#40;</span>GameObject targetCompleteMethodObject, <span style="color: #6666cc; font-weight: bold;">String</span> completeMethod, <span style="color: #6666cc; font-weight: bold;">float</span> triggerTime<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		Init<span style="color: #008000;">&#40;</span>targetCompleteMethodObject, completeMethod, triggerTime, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Init<span style="color: #008000;">&#40;</span>GameObject targetCompleteMethodObject, <span style="color: #6666cc; font-weight: bold;">String</span> completeMethod, <span style="color: #6666cc; font-weight: bold;">float</span> runForSeconds, <span style="color: #6666cc; font-weight: bold;">int</span> repeatCount<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">target</span> <span style="color: #008000;">=</span> targetCompleteMethodObject<span style="color: #008000;">;</span>
		onCompleteMethod <span style="color: #008000;">=</span> completeMethod<span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">runForSeconds</span> <span style="color: #008000;">=</span> runForSeconds<span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">repeatCount</span> <span style="color: #008000;">=</span> repeatCount<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// A Monkey Prism timer object that allows for a user to trigger a method based on a time specified.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MPTimer
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> MPTimerObject timerObject<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span> startTime<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span> endTime<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> active<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> count<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Create a new MPTimer object.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;mpTimerObject&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;MPTimerObject&quot;/&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> MPTimer<span style="color: #008000;">&#40;</span>MPTimerObject mpTimerObject<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		Init<span style="color: #008000;">&#40;</span>mpTimerObject, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Create a new MPTimer object.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;mpTimerObject&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;MPTimerObject&quot;/&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;activeState&quot;&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;System.Boolean&quot;/&gt; representing whether to start the timer immediately or to wait.  If true, the timer will kick-off immediately.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/param&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> MPTimer<span style="color: #008000;">&#40;</span>MPTimerObject mpTimerObject, <span style="color: #6666cc; font-weight: bold;">bool</span> activeState<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		Init<span style="color: #008000;">&#40;</span>mpTimerObject, activeState<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Init<span style="color: #008000;">&#40;</span>MPTimerObject mpTimerObject, <span style="color: #6666cc; font-weight: bold;">bool</span> activeState<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>mpTimerObject <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> 
		    mpTimerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">onCompleteMethod</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> mpTimerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">target</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MPTimer Error: Invalid MPTimerObject specified.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		timerObject <span style="color: #008000;">=</span> mpTimerObject<span style="color: #008000;">;</span>
		Active <span style="color: #008000;">=</span> activeState<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The MPTimerObject get/set helper.  Setting a new timer object will inactivate the current timer.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> MPTimerObject TimerObject
	<span style="color: #008000;">&#123;</span>
		get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> timerObject<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
		set <span style="color: #008000;">&#123;</span>
			active <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
			timerObject <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The Active get/set helper.  By setting this to &quot;Active&quot; you will instantly cause this method to be called.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Active
	<span style="color: #008000;">&#123;</span>
		get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> active<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
		set <span style="color: #008000;">&#123;</span> 
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">!=</span> active<span style="color: #008000;">&#41;</span> 
				count <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
			active <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>active<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				startTime <span style="color: #008000;">=</span> Time<span style="color: #008000;">.</span><span style="color: #0000FF;">time</span><span style="color: #008000;">;</span>
				endTime <span style="color: #008000;">=</span> startTime <span style="color: #008000;">+</span> timerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">runForSeconds</span><span style="color: #008000;">;</span>
				<span style="color: #008080; font-style: italic;">//Debug.Log(&quot;Start= &quot; + startTime + &quot;, End= &quot; + endTime);</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// A method used for the &quot;Update&quot; call in your calling library.  If this method is not called, the timer is not automatically driven.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> DoTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>active<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Time<span style="color: #008000;">.</span><span style="color: #0000FF;">time</span> <span style="color: #008000;">&gt;=</span> endTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">//Debug.Log(&quot;timer fired!&quot;);</span>
			timerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">target</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendMessage</span><span style="color: #008000;">&#40;</span>timerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">onCompleteMethod</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">++</span>count <span style="color: #008000;">&gt;=</span> timerObject<span style="color: #008000;">.</span><span style="color: #0000FF;">repeatCount</span><span style="color: #008000;">&#41;</span>
				active <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//toggle off.</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/07/09/timer-manager-for-unity3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity3D Projects, Version Control and Git</title>
		<link>http://www.chrisdanielson.com/2011/06/04/unity3d-projects-version-control-git/</link>
		<comments>http://www.chrisdanielson.com/2011/06/04/unity3d-projects-version-control-git/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 16:47:42 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[Asset Server]]></category>
		<category><![CDATA[CVS]]></category>
		<category><![CDATA[GIT]]></category>
		<category><![CDATA[GitX]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=534</guid>
		<description><![CDATA[Remember when CVS was a pretty neat version control system for one guy working out of his garage? Then many of us became enamored with SVN, which was a nice upgrade offering many additional options than your standard CVS. There are many other version control software packages on the market as well, some cost money [...]]]></description>
			<content:encoded><![CDATA[<p>Remember when CVS was a pretty neat version control system for one guy working out of his garage?  Then many of us became enamored with SVN, which was a nice upgrade offering many additional options than your standard CVS.  There are many other version control software packages on the market as well, some cost money and others are free.  When it comes to the Unity3D Pro game engine there really are two version control systems that come to mind.</p>
<ul>
<li>Unity3D Asset Server  - Costs $500.00 (as of June 4, 2011).  It&#8217;s an add-on component that requires additional hardware resources to run on.  It doesn&#8217;t appear that you can run this thing in the cloud (i.e. Amazon ec2, or pick your favorite virtual flavor).</li>
<li>SVN &#8211; FREE, but a real pain to setup with your Unity3D project.  What folders and data do you not upload into your repository?  Unity has a how-to, but it still stinks when you have those .svn folders peppered throughout your project.</li>
</ul>
<p>As of June 4, 2011 Unity3D Pro shares these two options on their website (including the HOW-TO).  <a href="http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.html" target="_blank">http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.html</a></p>
<p>What if there was one more option that wasn&#8217;t discussed by Unity3D?  What if this option was as easy as SVN, if not easier to implement?</p>
<p>Enter in <strong>Git</strong>.  I have personally setup my Unity3D projects using SVN in the past and after using Git, I can&#8217;t stress how great this product is for your Unity3D projects.  No more nasty .svn folders incidentally getting distributed in your software or irritatingly peppered throughout.  Also, branches, tags and the ominous merges are handled inherently much better in Git.  As a side note, Git was created for one of the most popular open source projects on the planet earth&#8230; Linux.  And it was started by the king of handling merges&#8230; Linus Torvalds himself.  Not that that should steer your thinking much, but I have to admit I was slow to begin using Git.  Now that I&#8217;m using Git, I&#8217;ve already converted all my latest projects over to it because I just can&#8217;t seem to live without it&#8217;s simplicity and power.</p>
<p>So how do I integrate Git?   I&#8217;m not going to go into detail on setting up your own Git repository here.  You can easily set one up over at <a href="http://github.com" target="_blank">github.com</a>.  Or for the more adventurous, you can create your own Git repository and integrate a authentication/permissions or use straight SSH.  BTW, I recommend to use <a href="https://github.com/sitaramc/gitolite" target="_blank">gitolite</a> for authentication/permissions.  Gitolite, will make integration a snap without forcing you to create a handful of accounts on your Linux server.  It also doesn&#8217;t hurt that Fedora and a few other big systems use and support Gitolite.</p>
<p>You still have to follow some of the Unity3D directions for creating an SVN friendly Unity3D project.  More specifically, you need to follow the first 3 directions they list.  Well here is my recipe&#8230;</p>
<p><em>Please note, this only applies to Unity Pro Licenses</em>.</p>
<ol>
<li>Create a new project inside Unity and lets call it InitialUnityProject. You can add any initial assets here or add them later on.</li>
<li>Enable Meta files in <strong>Edit->Project Settings->Editor</strong>  <-- NOTE: THIS IS VERY IMPORTANT</li>
<li>Quit Unity (We do this to assure that all the files are saved).</li>
<li>(My addition) Create a new Git repository for your project.  Setup git on your local workstation and pull the empty repository down to a folder</li>
<li>(My addition) Copy your new Unity3D project over to that local repository project folder.</li>
<li>(My addition) Create a .gitignore using my recipe or a modification as shown below.</li>
<li>(My addition) Startup Unity3D and open the project from the new local repository project folder.</li>
</ol>
<p>Tools I use:<br />
<a href="http://git-scm.com/" target="_blank">Git</a><br />
<a href="http://gitx.frim.nl/" target="_blank">GitX</a></p>
<p>See below for a <strong>.gitignore</strong> file which is stored at the root of your local repository location.  It will take care of helping you avoid storing the wrong files into your Git repository!</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p534code8'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5348"><td class="code" id="p534code8"><pre class="text" style="font-family:monospace;"># Unity3D .gitignore file.
#     Store this file at the root of your local repository.
.DS_Store
Library/AssetImportState
Library/AssetServerCacheV3
Library/FailedAssetImports.txt
Library/ScriptAssemblies
Library/ScriptMapper
Library/assetDatabase3
Library/cache
Library/expandedItems
Library/metadata
Library/previews
Library/guidmapper
Temp
*.csproj
*.pidb
*.sln
build</pre></td></tr></table></div>

<p>Remember with Git, that you are operating on your local repository until you perform the <em>git push origin master</em>.  This means you can bundle your commits into the parent version control!</p>
<p>Finally, I feel like I discovered a happy medium of finding a free alternative that works better than SVN with the Unity3D game environment.</p>
<p>Good luck with your projects and happy game developing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/06/04/unity3d-projects-version-control-git/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Unity3D Joystick Script</title>
		<link>http://www.chrisdanielson.com/2011/05/17/unity3d-joystick-script/</link>
		<comments>http://www.chrisdanielson.com/2011/05/17/unity3d-joystick-script/#comments</comments>
		<pubDate>Tue, 17 May 2011 19:11:26 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Converted]]></category>
		<category><![CDATA[Joystick]]></category>
		<category><![CDATA[Joystick.js]]></category>
		<category><![CDATA[Penelope]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=524</guid>
		<description><![CDATA[Here we are again. 3 cups of coffee later and another script conversion. I&#8217;ve taken the time to convert the Penelope Joystick.cs JavaScript script into C-Sharp. Why would someone do this? I did it because I am getting tired of anything that is not strongly typed in Unity3D. If you are writing your engine in [...]]]></description>
			<content:encoded><![CDATA[<p>Here we are again.  3 cups of coffee later and another script conversion.  I&#8217;ve taken the time to convert the Penelope Joystick.cs JavaScript script into C-Sharp.  Why would someone do this?  I did it because I am getting tired of anything that is not strongly typed in Unity3D.  If you are writing your engine in JavaScript, you&#8217;re probably making variables with or without typos that don&#8217;t have the scope you thought they did and worse, you might have a 6-8 hour hot date with your code when you can&#8217;t figure out why it&#8217;s crashing due to some strange &#8220;type assumptions&#8221;.  Don&#8217;t get me wrong, hot dates are a blast, especially when they aren&#8217;t with your computer.</p>
<p>In my usual way, here is the Joystick script converted over into C-Sharp.</p>
<p>May 17, 2011: Oh one more thing, I&#8217;m posting this early, call it jumping the gun, I haven&#8217;t tested it yet.  I&#8217;ll be testing in the next 24 hours.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p524code10'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p52410"><td class="code" id="p524code10"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/**
 * File: MPJoystick.cs
 * Author: Chris Danielson of (monkeyprism.com)
 * 
// USED TO BE: Joystick.js taken from Penelope iPhone Tutorial
//
// Joystick creates a movable joystick (via GUITexture) that 
// handles touch input, taps, and phases. Dead zones can control
// where the joystick input gets picked up and can be normalized.
//
// Optionally, you can enable the touchPad property from the editor
// to treat this Joystick as a TouchPad. A TouchPad allows the finger
// to touch down at any point and it tracks the movement relatively 
// without moving the graphic
*/</span>
&nbsp;
<span style="color: #008000;">&#91;</span>RequireComponent<span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>GUITexture<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MPJoystick <span style="color: #008000;">:</span> MonoBehaviour
<span style="color: #008000;">&#123;</span>
	<span style="color: #6666cc; font-weight: bold;">class</span> Boundary <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 min <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 max <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> MPJoystick<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> joysticks<span style="color: #008000;">;</span>					<span style="color: #008080; font-style: italic;">// A static collection of all joysticks</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> enumeratedJoysticks <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">float</span> tapTimeDelta <span style="color: #008000;">=</span> 0<span style="color: #008000;">.</span>3f<span style="color: #008000;">;</span>				<span style="color: #008080; font-style: italic;">// Time allowed between taps</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> touchPad<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 position <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> Rect touchZone<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 deadZone <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>						<span style="color: #008080; font-style: italic;">// Control when position is output</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> normalize <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> 							<span style="color: #008080; font-style: italic;">// Normalize output after the dead-zone?</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> tapCount<span style="color: #008000;">;</span>	
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> lastFingerId <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>								<span style="color: #008080; font-style: italic;">// Finger last used for this joystick</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span> tapTimeWindow<span style="color: #008000;">;</span>							<span style="color: #008080; font-style: italic;">// How much time there is left for a tap to occur</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Vector2 fingerDownPos<span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">//private float fingerDownTime;</span>
	<span style="color: #008080; font-style: italic;">//private float firstDeltaTime = 0.5f;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> GUITexture gui<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Rect defaultRect<span style="color: #008000;">;</span>								<span style="color: #008080; font-style: italic;">// Default position / extents of the joystick graphic</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Boundary guiBoundary <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Boundary<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>			<span style="color: #008080; font-style: italic;">// Boundary for joystick graphic</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Vector2 guiTouchOffset<span style="color: #008000;">;</span>						<span style="color: #008080; font-style: italic;">// Offset to apply to touch input</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> Vector2 guiCenter<span style="color: #008000;">;</span>							<span style="color: #008080; font-style: italic;">// Center of joystick</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		gui <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>GUITexture<span style="color: #008000;">&#41;</span>GetComponent<span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>GUITexture<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		defaultRect <span style="color: #008000;">=</span> gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span><span style="color: #008000;">;</span>
		defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">+=</span> transform<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">*</span> Screen<span style="color: #008000;">.</span><span style="color: #0000FF;">width</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">// + gui.pixelInset.x; // -  Screen.width * 0.5;</span>
    	defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">+=</span> transform<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">*</span> Screen<span style="color: #008000;">.</span><span style="color: #0000FF;">height</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">// - Screen.height * 0.5;</span>
&nbsp;
		transform<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span> <span style="color: #008000;">=</span> Vector3<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchPad<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// If a texture has been assigned, then use the rect ferom the gui as our touchZone</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> gui<span style="color: #008000;">.</span><span style="color: #0000FF;">texture</span> <span style="color: #008000;">&#41;</span>
				touchZone <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>	
			guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">width</span> <span style="color: #008000;">*</span> 0<span style="color: #008000;">.</span>5f<span style="color: #008000;">;</span>
			guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">height</span> <span style="color: #008000;">*</span> 0<span style="color: #008000;">.</span>5f<span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// Cache the center of the GUI, since it doesn't change</span>
			guiCenter<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span><span style="color: #008000;">;</span>
			guiCenter<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// Let's build the GUI boundary, so we can clamp joystick movement</span>
			guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">min</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">-</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span><span style="color: #008000;">;</span>
			guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">max</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span><span style="color: #008000;">;</span>
			guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">min</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">-</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span><span style="color: #008000;">;</span>
			guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">max</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 getGUICenter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> guiCenter<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> Disable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		gameObject<span style="color: #008000;">.</span><span style="color: #0000FF;">active</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008080; font-style: italic;">//enumeratedJoysticks = false;	</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ResetJoystick<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span> <span style="color: #008000;">=</span> defaultRect<span style="color: #008000;">;</span>
		lastFingerId <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
		position <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
		fingerDownPos <span style="color: #008000;">=</span> Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>	
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsFingerDown<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>lastFingerId <span style="color: #008000;">!=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> LatchedFinger<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> fingerId<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// If another joystick has latched this finger, then we must release it</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> lastFingerId <span style="color: #008000;">==</span> fingerId <span style="color: #008000;">&#41;</span>
			ResetJoystick<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>enumeratedJoysticks<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Collect all joysticks in the game, so we can relay finger latching messages</span>
			joysticks <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>MPJoystick<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>FindObjectsOfType<span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>MPJoystick<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>	
			enumeratedJoysticks <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #6666cc; font-weight: bold;">int</span> count <span style="color: #008000;">=</span> Input<span style="color: #008000;">.</span><span style="color: #0000FF;">touchCount</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> tapTimeWindow <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#41;</span>
			tapTimeWindow <span style="color: #008000;">-=</span> Time<span style="color: #008000;">.</span><span style="color: #0000FF;">deltaTime</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span>
			tapCount <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> count <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#41;</span>
			ResetJoystick<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">for</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> count<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				Touch touch <span style="color: #008000;">=</span> Input<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTouch</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>			
				Vector2 guiTouchPos <span style="color: #008000;">=</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span> <span style="color: #008000;">-</span> guiTouchOffset<span style="color: #008000;">;</span>
&nbsp;
				<span style="color: #6666cc; font-weight: bold;">bool</span> shouldLatchFinger <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchPad<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchZone<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>touch<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
						shouldLatchFinger <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
				<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>gui<span style="color: #008000;">.</span><span style="color: #0000FF;">HitTest</span><span style="color: #008000;">&#40;</span>touch<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					shouldLatchFinger <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
&nbsp;
				<span style="color: #008080; font-style: italic;">// Latch the finger if this is a new touch</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>shouldLatchFinger <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>lastFingerId <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> lastFingerId <span style="color: #008000;">!=</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">fingerId</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchPad<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
						<span style="color: #008080; font-style: italic;">//gui.color.a = 0.15;</span>
						lastFingerId <span style="color: #008000;">=</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">fingerId</span><span style="color: #008000;">;</span>
						<span style="color: #008080; font-style: italic;">//fingerDownPos = touch.position;</span>
						<span style="color: #008080; font-style: italic;">//fingerDownTime = Time.time;</span>
					<span style="color: #008000;">&#125;</span>
&nbsp;
					lastFingerId <span style="color: #008000;">=</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">fingerId</span><span style="color: #008000;">;</span>
&nbsp;
					<span style="color: #008080; font-style: italic;">// Accumulate taps if it is within the time window</span>
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> tapTimeWindow <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&#41;</span>
						tapCount<span style="color: #008000;">++;</span>
					<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
						tapCount <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
						tapTimeWindow <span style="color: #008000;">=</span> tapTimeDelta<span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span>
&nbsp;
					<span style="color: #008080; font-style: italic;">// Tell other joysticks we've latched this finger</span>
					<span style="color: #008080; font-style: italic;">//for (  j : Joystick in joysticks )</span>
					<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>MPJoystick j <span style="color: #0600FF; font-weight: bold;">in</span> joysticks<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
						<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>j <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span> 
							j<span style="color: #008000;">.</span><span style="color: #0000FF;">LatchedFinger</span><span style="color: #008000;">&#40;</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">fingerId</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span>		
				<span style="color: #008000;">&#125;</span>				
&nbsp;
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> lastFingerId <span style="color: #008000;">==</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">fingerId</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>	
					<span style="color: #008080; font-style: italic;">// Override the tap count with what the iPhone SDK reports if it is greater</span>
					<span style="color: #008080; font-style: italic;">// This is a workaround, since the iPhone SDK does not currently track taps</span>
					<span style="color: #008080; font-style: italic;">// for multiple touches</span>
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">tapCount</span> <span style="color: #008000;">&gt;</span> tapCount <span style="color: #008000;">&#41;</span>
						tapCount <span style="color: #008000;">=</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">tapCount</span><span style="color: #008000;">;</span>
&nbsp;
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> touchPad <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
						<span style="color: #008080; font-style: italic;">// For a touchpad, let's just set the position directly based on distance from initial touchdown</span>
						position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Clamp</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">-</span> fingerDownPos<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span> touchZone<span style="color: #008000;">.</span><span style="color: #0000FF;">width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">&#41;</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
						position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Clamp</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">-</span> fingerDownPos<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span> touchZone<span style="color: #008000;">.</span><span style="color: #0000FF;">height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">&#41;</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>					
						<span style="color: #008080; font-style: italic;">// Change the location of the joystick graphic to match where the touch is</span>
						Rect r <span style="color: #008000;">=</span> gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span><span style="color: #008000;">;</span>
						r<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span>  Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Clamp</span><span style="color: #008000;">&#40;</span> guiTouchPos<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span>, guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">min</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span>, guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">max</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
						r<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span>  Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Clamp</span><span style="color: #008000;">&#40;</span> guiTouchPos<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span>, guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">min</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span>, guiBoundary<span style="color: #008000;">.</span><span style="color: #0000FF;">max</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		
						gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span> <span style="color: #008000;">=</span> r<span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span>
&nbsp;
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touch<span style="color: #008000;">.</span><span style="color: #0000FF;">phase</span> <span style="color: #008000;">==</span> TouchPhase<span style="color: #008000;">.</span><span style="color: #0000FF;">Ended</span> <span style="color: #008000;">||</span> touch<span style="color: #008000;">.</span><span style="color: #0000FF;">phase</span> <span style="color: #008000;">==</span> TouchPhase<span style="color: #008000;">.</span><span style="color: #0000FF;">Canceled</span><span style="color: #008000;">&#41;</span>
						ResetJoystick<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>					
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>touchPad<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Get a value between -1 and 1 based on the joystick graphic location</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span> gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">-</span> guiCenter<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span><span style="color: #008000;">;</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span> gui<span style="color: #008000;">.</span><span style="color: #0000FF;">pixelInset</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">+</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">-</span> guiCenter<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> guiTouchOffset<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Adjust for dead zone	</span>
		var absoluteX <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		var absoluteY <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>absoluteX <span style="color: #008000;">&lt;</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Report the joystick as being at the center if it is within the dead zone</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>normalize<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Rescale the output after taking the dead zone into account</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Sign</span><span style="color: #008000;">&#40;</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span> absoluteX <span style="color: #008000;">-</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">-</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>absoluteY <span style="color: #008000;">&lt;</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Report the joystick as being at the center if it is within the dead zone</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>normalize<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Rescale the output after taking the dead zone into account</span>
			position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> Mathf<span style="color: #008000;">.</span><span style="color: #0000FF;">Sign</span><span style="color: #008000;">&#40;</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span> absoluteY <span style="color: #008000;">-</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">-</span> deadZone<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/05/17/unity3d-joystick-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using Apple Property List Files with Unity3D</title>
		<link>http://www.chrisdanielson.com/2011/05/09/using-apple-property-list-files-with-unity3d/</link>
		<comments>http://www.chrisdanielson.com/2011/05/09/using-apple-property-list-files-with-unity3d/#comments</comments>
		<pubDate>Mon, 09 May 2011 15:01:14 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[persistent storage]]></category>
		<category><![CDATA[plist]]></category>
		<category><![CDATA[Property List]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=505</guid>
		<description><![CDATA[Unity3D C-Sharp PList load and save tool.  Code included in this post.]]></description>
			<content:encoded><![CDATA[<p>Persistent storage and data retrieval can be troubling without a reference in your environment to the SQLite library.  In the case of Unity3D, there is no direct SQLite library wrappers offered out of the box.  One can write a device specific SQLite wrapper (or purchase one) that bridges the gap into the Unity3D JavaScript and CSharp world or one can decide on a simpler method for storing and managing data.  Enter Apple&#8217;s .plist or property list files.  These files can be saved in binary and also in a standard text format.  For our situation, we&#8217;re going to manage these files that are stored in standard text format.  It is arguable that using a custom plist parser is going to be slower than using SQLite, but with a small enough subset of data I believe that plist should be an adequate solution.</p>
<p>The unity community has a free version of a <a href="http://www.unifycommunity.com/wiki/index.php?title=PropertyListSerializer">PropertyListSerializer.js</a> file.  I copied this code outright and converted it into the strongly typed C-Sharp environment.  My reasoning was simple, I found that using JavaScript wasn&#8217;t going to work with my current project for a few reasons so I decided to convert this file over into C-Sharp code.  I did attempt to upload my changes to that site, but it continued to complain that I was getting blocked by the spam check functions.</p>
<p>Enjoy!</p>
<p>Edit: May 13, 2011  After testing on the actual iOS device I discovered that DTD validation is not implemented in Unity.  I&#8217;ve now disabled the XmlDocument forced validation.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p505code11'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50511"><td class="code" id="p505code11"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/**
 * 
 * Converted By: Chris Danielson of http://MonkeyPrism.com
 * Converted Date: May 8, 2011
 * Original JavaScript Auther: capnbishop
 * 
 * Conversion of a Unity 3D Community script from JavaScript to type controlled C# Mono.Net.
 * 
 * Please note, that the original object was named PropertyListSerializer.  I renamed it to prevent any conflicts with the original script.
 * 
 * The PropertyListSerializer.js (CD: renamed now to PListManager) script is used to load and save an XML property list file to and from a hierarchical hashtable 
 * (in which the root hashtable can contain child hashtables and arrays). This can provide a convenient and dynamic means of serializing 
 * a complex hierarchy of game data into XML files.
 * When loading, the resulting hashtable can include 8 different types of values: string, integer, real, date, data, boolean, dictionary, and array. 
 * Data elements are loaded as strings. Dictionaries are loaded as hashtables. Arrays are loaded as arrays. Each value is loaded with an 
 * associating key, except for elements of an array. Thus, each child hashtable and array also have associating keys, and can be combined to 
 * create a complex hierarchy of key value pairs and arrays.
 * When saving, the resulting XML file will contain the same hierarchy of data. All data will end up being stored as a string, but with an 
 * associated value type. Strings, integers, and decimals values are stored as such. Dates are stored in ISO 8601 format. Hashtables are stored 
 * as a plist key/value dictionary, and arrays as a series of keyless values.
 * The loader passes a lot of values by reference, and performs a considerable amount of recursion. Primitive values had to be passed by reference. 
 * Unity's JavaScript only passes objects by reference, and cannot explicitly pass a primitive by reference. As such, we've had to create a 
 * special ValueObject, which is just an abstract object that holds a single value. This object is then passed by reference, and the primitive 
 * value is set to its val property.
 * This plist loader conforms to Apple's plist DOCTYPE definition: http://www.apple.com/DTDs/PropertyList-1.0.dtd
 * 
 * Original JavaScript URL:  http://www.unifycommunity.com/wiki/index.php?title=PropertyListSerializer
 * 
 * Example Saving:
&nbsp;
 		Hashtable playerData = new Hashtable();
		playerData.Add(&quot;Health&quot;,100);
		playerData.Add(&quot;TestObject&quot;, 1.5f);
		ArrayList guns = new ArrayList();
		guns.Add(&quot;AK-47&quot;);
		guns.Add(&quot;Pistol&quot;);
	    playerData.Add(&quot;Guns&quot;, guns);
		Hashtable grenades = new Hashtable();
		grenades.Add(&quot;FragmentationCount&quot;, 1);
		grenades.Add(&quot;IncendiaryCount&quot;, 1);
		playerData.Add(&quot;Grenades&quot;, grenades);
&nbsp;
		//save outside the current project (same folder as Assets and Library)
		String xmlFile = Application.dataPath + &quot;/../ExampleSaveFile.plist&quot;; 
		PListManager.SavePlistToFile(xmlFile, playerData);
 * 
 */</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Xml</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Globalization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PListManager <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> PListManager<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> SUPPORTED_VERSION <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;1.0&quot;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ParsePListFile<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> xmlFile, <span style="color: #0600FF; font-weight: bold;">ref</span> Hashtable plist<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>                       
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>xmlFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File doesn't exist: &quot;</span> <span style="color: #008000;">+</span> xmlFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> 
		<span style="color: #008000;">&#125;</span>
&nbsp;
		StreamReader sr <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #008000;">&#40;</span>xmlFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span> txt <span style="color: #008000;">=</span> sr<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		sr<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		XmlDocument xml <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                xml<span style="color: #008000;">.</span><span style="color: #0000FF;">XmlResolver</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//Disable schema/DTD validation, it's not implemented for Unity.</span>
		xml<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadXml</span><span style="color: #008000;">&#40;</span>txt<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		XmlNode plistNode <span style="color: #008000;">=</span> xml<span style="color: #008000;">.</span><span style="color: #0000FF;">LastChild</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>plistNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;plist&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;plist file missing &lt;plist&gt; nodes.&quot;</span> <span style="color: #008000;">+</span> xmlFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #6666cc; font-weight: bold;">string</span> plistVers <span style="color: #008000;">=</span> plistNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;version&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>plistVers <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span>plistVers<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>SUPPORTED_VERSION<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;This is an unsupported plist version: &quot;</span> <span style="color: #008000;">+</span> plistVers <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;. Required version:a &quot;</span> <span style="color: #008000;">+</span> SUPPORTED_VERSION<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		XmlNode dictNode <span style="color: #008000;">=</span> plistNode<span style="color: #008000;">.</span><span style="color: #0000FF;">FirstChild</span><span style="color: #008000;">;</span>
    	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>dictNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dict&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Missing root dict from plist file: &quot;</span> <span style="color: #008000;">+</span> xmlFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> 
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">return</span> LoadDictFromPlistNode<span style="color: #008000;">&#40;</span>dictNode, <span style="color: #0600FF; font-weight: bold;">ref</span> plist<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #008080;">#region LOAD_PLIST_PRIVATE_METHODS</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> LoadDictFromPlistNode<span style="color: #008000;">&#40;</span>XmlNode node, <span style="color: #0600FF; font-weight: bold;">ref</span> Hashtable dict<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load a null plist dict node.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dict&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load an dict from a non-array node type: &quot;</span> <span style="color: #008000;">+</span> node <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>dict <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			dict <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Hashtable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #6666cc; font-weight: bold;">int</span> cnodeCount <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i<span style="color: #008000;">+</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">&lt;</span> cnodeCount<span style="color: #008000;">;</span> i<span style="color: #008000;">+=</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        	<span style="color: #008080; font-style: italic;">// Select the key and value child nodes</span>
			XmlNode keynode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			XmlNode valuenode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// If this node isn't a 'key'</span>
        	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>keynode<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;key&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #008080; font-style: italic;">// Establish our variables to hold the key and value.</span>
				<span style="color: #6666cc; font-weight: bold;">string</span> key <span style="color: #008000;">=</span> keynode<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span><span style="color: #008000;">;</span>
				ValueObject value <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ValueObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	            <span style="color: #008080; font-style: italic;">// Load the value node.</span>
	            <span style="color: #008080; font-style: italic;">// If the value node loaded successfully, add the key/value pair to the dict hashtable.</span>
	            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LoadValueFromPlistNode<span style="color: #008000;">&#40;</span>valuenode, <span style="color: #0600FF; font-weight: bold;">ref</span> value<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	                <span style="color: #008080; font-style: italic;">// This could be one of several different possible data types, including another dict.</span>
	                <span style="color: #008080; font-style: italic;">// AddKeyValueToDict() handles this by replacing existing key values that overlap, and doing so recursively for dict values.</span>
	                <span style="color: #008080; font-style: italic;">// If this not successful, post a message stating so and return false.</span>
	                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>AddKeyValueToDict<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> dict, key, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
						Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Failed to add key value to dict when loading plist from dict&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
						<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span>
	            <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
					Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Did not load plist value correctly for key in node: &quot;</span> <span style="color: #008000;">+</span> key <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> node<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
	        <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
				Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;The plist being loaded may be corrupt.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end for</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> LoadValueFromPlistNode<span style="color: #008000;">&#40;</span>XmlNode node, <span style="color: #0600FF; font-weight: bold;">ref</span> ValueObject value<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load a null plist value node.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;string&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;integer&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;real&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span>, <span style="color: #0600FF; font-weight: bold;">null</span>, DateTimeStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// Date objects are in ISO 8601 format</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;data&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// Data objects are just loaded as a string</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;true&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// Boollean values are empty objects, simply identified with a name being &quot;true&quot; or &quot;false&quot;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;false&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// The value can be an array or dict type.  In this case, we need to recursively call the appropriate loader functions for dict and arrays.</span>
	    <span style="color: #008080; font-style: italic;">// These functions will in turn return a boolean value for their success, so we can just return that.</span>
	    <span style="color: #008080; font-style: italic;">// The val value also has to be instantiated, since it's being passed by reference.</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dict&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Hashtable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			Hashtable htRef <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> LoadDictFromPlistNode<span style="color: #008000;">&#40;</span>node, <span style="color: #0600FF; font-weight: bold;">ref</span> htRef<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;array&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArrayList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			ArrayList alRef <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> LoadArrayFromPlistNode<span style="color: #008000;">&#40;</span>node, <span style="color: #0600FF; font-weight: bold;">ref</span> alRef<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load a value from a non value type node: &quot;</span> <span style="color: #008000;">+</span> node <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> LoadArrayFromPlistNode<span style="color: #008000;">&#40;</span>XmlNode node, <span style="color: #0600FF; font-weight: bold;">ref</span> ArrayList array <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// If we were passed a null node object, then post an error stating so and return false</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load a null plist array node.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// If we were passed a non array node, then post an error stating so and return false</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;array&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to load an array from a non-array node type: &quot;</span> <span style="color: #008000;">+</span> node <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// We can be passed an empty array object.  If so, initialize it</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>array <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> array <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArrayList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Itterate through the child nodes for this array object</span>
	    <span style="color: #6666cc; font-weight: bold;">int</span> nodeCount <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
	    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> nodeCount<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// Establish variables to hold the child node of the array, and it's value</span>
	        XmlNode cnode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">ChildNodes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        ValueObject element <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ValueObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        <span style="color: #008080; font-style: italic;">// Attempt to load the value from the current array node.</span>
	        <span style="color: #008080; font-style: italic;">// If successful, add it as an element of the array.  If not, post and error stating so and return false.</span>
	        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LoadValueFromPlistNode<span style="color: #008000;">&#40;</span>cnode, <span style="color: #0600FF; font-weight: bold;">ref</span> element<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
				array<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
				<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> 
			<span style="color: #008000;">&#125;</span>
	    <span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// If we made it through the array without errors, return true</span>
	    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AddKeyValueToDict<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> Hashtable dict, <span style="color: #6666cc; font-weight: bold;">string</span> key, ValueObject value<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// Make sure that we have values that we can work with.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>dict <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> key <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> key<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> value <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to AddKeyValueToDict() with null objects.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// If the hashtable doesn't already contain the key, they we can just go ahead and add it.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>dict<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>key<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			dict<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>key, value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// At this point, the dict contains already contains the key we're trying to add.</span>
	    <span style="color: #008080; font-style: italic;">// If the value for this key is of a different type between the dict and the new value, then we have a type mismatch.</span>
	    <span style="color: #008080; font-style: italic;">// Post an error stating so, but go ahead and overwrite the existing key value.</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogWarning</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Value type mismatch for overlapping key (will replace old value with new one): &quot;</span> <span style="color: #008000;">+</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> key<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span>
    	<span style="color: #008080; font-style: italic;">// If the value for this key is a hashtable, then we need to recursively add the key values of each hashtable.</span>
    	<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// Itterate through the elements of the value's hashtable.</span>
			Hashtable htTmp <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
	        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> element <span style="color: #0600FF; font-weight: bold;">in</span> htTmp<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	            <span style="color: #008080; font-style: italic;">// Recursively attempt to add/repalce the elements of the value hashtable to the dict's value hashtable.</span>
	            <span style="color: #008080; font-style: italic;">// If this fails, post a message stating so and return false.</span>
				Hashtable htRef <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span>dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
	            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>AddKeyValueToDict<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> htRef, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>element, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ValueObject<span style="color: #008000;">&#40;</span>htTmp<span style="color: #008000;">&#91;</span>element<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	                Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Failed to add key value to dict: &quot;</span> <span style="color: #008000;">+</span> element <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> htTmp<span style="color: #008000;">&#91;</span>element<span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;, &quot;</span> <span style="color: #008000;">+</span> dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	            <span style="color: #008000;">&#125;</span>
	        <span style="color: #008000;">&#125;</span>
    	<span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// If the value is an array, then there's really no way we can tell which elements to overwrite, because this is done based on the congruent keys.</span>
	    <span style="color: #008080; font-style: italic;">// Thus, we'll just add the elements of the array to the existing array.</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			ArrayList alTmp <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
			ArrayList alAddTmp <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span>dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> element <span style="color: #0600FF; font-weight: bold;">in</span> alTmp<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				alAddTmp<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
	    <span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// If the key value is not an array or a hashtable, then it's a primitive value that we can easily write over.</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
			dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">val</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
    	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #008080;">#endregion</span>
&nbsp;
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SavePlistToFile <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> xmlFile, Hashtable plist<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// If the hashtable is null, then there's apparently an issue; fail out.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>plist <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Passed a null plist hashtable to SavePlistToFile.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Create the base xml document that we will use to write the data</span>
	    XmlDocument xml <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    xml<span style="color: #008000;">.</span><span style="color: #0000FF;">XmlResolver</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//Disable schema/DTD validation, it's not implemented for Unity.</span>
	    <span style="color: #008080; font-style: italic;">// Create the root XML declaration</span>
	    <span style="color: #008080; font-style: italic;">// This, and the DOCTYPE, below, are standard parts of a XML property list file</span>
	    XmlDeclaration xmldecl <span style="color: #008000;">=</span> xml<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateXmlDeclaration</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;1.0&quot;</span>, <span style="color: #666666;">&quot;UTF-8&quot;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    xml<span style="color: #008000;">.</span><span style="color: #0000FF;">PrependChild</span><span style="color: #008000;">&#40;</span>xmldecl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Create the DOCTYPE</span>
	    XmlDocumentType doctype <span style="color: #008000;">=</span> xml<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateDocumentType</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;plist&quot;</span>, <span style="color: #666666;">&quot;-//Apple//DTD PLIST 1.0//EN&quot;</span>, <span style="color: #666666;">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    xml<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>doctype<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Create the root plist node, with a version number attribute.</span>
	    <span style="color: #008080; font-style: italic;">// Every plist file has this as the root element.  We're using version 1.0 of the plist scheme</span>
	    XmlNode plistNode <span style="color: #008000;">=</span> xml<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateNode</span><span style="color: #008000;">&#40;</span>XmlNodeType<span style="color: #008000;">.</span><span style="color: #0000FF;">Element</span>, <span style="color: #666666;">&quot;plist&quot;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    XmlAttribute plistVers <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>XmlAttribute<span style="color: #008000;">&#41;</span>xml<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateNode</span><span style="color: #008000;">&#40;</span>XmlNodeType<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span>, <span style="color: #666666;">&quot;version&quot;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    plistVers<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;1.0&quot;</span><span style="color: #008000;">;</span>
	    plistNode<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>plistVers<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    xml<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>plistNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Now that we've created the base for the XML file, we can add all of our information to it.</span>
	    <span style="color: #008080; font-style: italic;">// Pass the plist data and the root dict node to SaveDictToPlistNode, which will write the plist data to the dict node.</span>
	    <span style="color: #008080; font-style: italic;">// This function will itterate through the hashtable hierarchy and call itself recursively for child hashtables.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>SaveDictToPlistNode<span style="color: #008000;">&#40;</span>plistNode, plist<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// If for some reason we failed, post an error and return false.</span>
	        Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Failed to save plist data to root dict node: &quot;</span> <span style="color: #008000;">+</span> plist<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We were successful</span>
	        <span style="color: #008080; font-style: italic;">// Create a StreamWriter and write the XML file to disk.</span>
	        <span style="color: #008080; font-style: italic;">// (do not append and UTF-8 are default, but we're defining it explicitly just in case)</span>
	        StreamWriter sw <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamWriter<span style="color: #008000;">&#40;</span>xmlFile, <span style="color: #0600FF; font-weight: bold;">false</span>, <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Encoding</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        xml<span style="color: #008000;">.</span><span style="color: #0000FF;">Save</span><span style="color: #008000;">&#40;</span>sw<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// We're done here.  If there were any failures, they would have returned false.</span>
	    <span style="color: #008080; font-style: italic;">// Return true to indicate success.</span>
	    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080;">#region SAVE_PLIST_PRIVATE_METHODS</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SaveDictToPlistNode<span style="color: #008000;">&#40;</span>XmlNode node, Hashtable dict<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// If we were passed a null object, return false</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>node <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attempted to save a null plist dict node.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    XmlNode dictNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateNode</span><span style="color: #008000;">&#40;</span>XmlNodeType<span style="color: #008000;">.</span><span style="color: #0000FF;">Element</span>, <span style="color: #666666;">&quot;dict&quot;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    node<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>dictNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// We could be passed an null hashtable.  This isn't necessarily an error.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>dict <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogWarning</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Attemped to save a null dict: &quot;</span> <span style="color: #008000;">+</span> dict<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Iterate through the keys in the hashtable</span>
	    <span style="color: #008080; font-style: italic;">//for (var key in dict.Keys) {</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> key <span style="color: #0600FF; font-weight: bold;">in</span> dict<span style="color: #008000;">.</span><span style="color: #0000FF;">Keys</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// Since plists are key value pairs, save the key to the plist as a new XML element</span>
	        XmlElement keyNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;key&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        keyNode<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>key<span style="color: #008000;">;</span>
	        dictNode<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>keyNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	        <span style="color: #008080; font-style: italic;">// The name of the value element is based on the datatype of the value.  We need to serialize it accordingly.  Pass the XML node and the hash value to SaveValueToPlistNode to handle this.</span>
	        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>SaveValueToPlistNode<span style="color: #008000;">&#40;</span>dictNode, dict<span style="color: #008000;">&#91;</span>key<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	            <span style="color: #008080; font-style: italic;">// If SaveValueToPlistNode() returns false, that means there was an error.  Return false to indicate this up the line.</span>
	            Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">LogError</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Failed to save value to plist node: &quot;</span> <span style="color: #008000;">+</span> key<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	        <span style="color: #008000;">&#125;</span>
	    <span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// If we got this far then all is well.  Return true to indicate success.</span>
	    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SaveValueToPlistNode<span style="color: #008000;">&#40;</span>XmlNode node, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// The node passed will be the parent node to the new value node.</span>
	    XmlNode valNode<span style="color: #008000;">;</span>
	    <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> type <span style="color: #008000;">=</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    <span style="color: #008080; font-style: italic;">// Identify the data type for the value and serialize it accordingly</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> 
			valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;string&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Int16<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> 
		         type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Int32<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span>
		         type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Int64<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;integer&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Single<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> 
		         type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">Double</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span>
		         type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">Decimal</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;real&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// Dates need to be stored in ISO 8601 format</span>
	        valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			DateTime dt <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span>
	        valNode<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span> <span style="color: #008000;">=</span> dt<span style="color: #008000;">.</span><span style="color: #0000FF;">ToUniversalTime</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;o&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        node<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>valNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// Boolean values are empty elements, simply being stored as an elemement with a name of true or false</span>
	        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>value <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;true&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;false&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	        node<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>valNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// Hashtables and arrays require special functions to save their values in an itterative and recursive manner.</span>
	    <span style="color: #008080; font-style: italic;">// The functions will return true/false to indicate success/failure, so pass those on.</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>    <span style="color: #008000;">&#123;</span> 
			<span style="color: #0600FF; font-weight: bold;">return</span> SaveDictToPlistNode<span style="color: #008000;">&#40;</span>node, <span style="color: #008000;">&#40;</span>Hashtable<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> 
		<span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>type <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> SaveArrayToPlistNode<span style="color: #008000;">&#40;</span>node, <span style="color: #008000;">&#40;</span>ArrayList<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #008080; font-style: italic;">// Anything that doesn't fit the defined data types will just be stored as &quot;data&quot;, which is effectively a string.</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span> 
			valNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;data&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Some of the values (strings, numbers, data) basically get stored as a string.  The rest will store their values in their special format and return true for success.  If we made it this far, then the value in valNode must be stored as a string.</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>valNode <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> valNode<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerText</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    node<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>valNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// We're done.  Return true for success.</span>
	    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SaveArrayToPlistNode <span style="color: #008000;">&#40;</span>XmlNode node, ArrayList array<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	    <span style="color: #008080; font-style: italic;">// Create the value node as an &quot;array&quot; element.</span>
	    XmlElement arrayNode <span style="color: #008000;">=</span> node<span style="color: #008000;">.</span><span style="color: #0000FF;">OwnerDocument</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;array&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	    node<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>arrayNode<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// Each element in the array can be any data type.  Itterate through the array and send each element to SaveValueToPlistNode(), where it can be stored accordingly based on its data type.</span>
	    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> element <span style="color: #0600FF; font-weight: bold;">in</span> array<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">// If SaveValueToPlistNode() returns false, then there was a problem.  Return false in that case.</span>
	        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>SaveValueToPlistNode<span style="color: #008000;">&#40;</span>arrayNode, element<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	    <span style="color: #008000;">&#125;</span>
    	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end PListManager class</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">class</span> ValueObject <span style="color: #008000;">&#123;</span> 
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> val<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> ValueObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> ValueObject<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> aVal<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> val <span style="color: #008000;">=</span> aVal<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/05/09/using-apple-property-list-files-with-unity3d/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Unity3D File Based Assetbundles on the iPhone</title>
		<link>http://www.chrisdanielson.com/2011/05/03/unity3d-file-assetbundles-on-the-iphone/</link>
		<comments>http://www.chrisdanielson.com/2011/05/03/unity3d-file-assetbundles-on-the-iphone/#comments</comments>
		<pubDate>Tue, 03 May 2011 21:37:11 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[assetbundle]]></category>
		<category><![CDATA[AssetBundleRequest]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[prefab]]></category>
		<category><![CDATA[UnityEditor]]></category>
		<category><![CDATA[UnityEngine]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=460</guid>
		<description><![CDATA[Developing assetbundles for the Unity3D engine seems to be a troubling case.  I'm going to try and make this a little a little easier than it typically is in my simple tutorial on how to do it.]]></description>
			<content:encoded><![CDATA[<p>Let me start off by saying that Unity3D is a really great game engine.  Let me also say that I wish the documentation was as great as the engine is.  Sadly, it&#8217;s difficult to figure out some of the more powerful features of Unity3D without significant trial and error.</p>
<p><em>Please note, that I have read that the usage of Assetbundles on the iPhone can be memory intensive and may or may not fit your needs per your project.  I am just putting this information here so that others can see how to do this.</em>  <strong>Pro Tip</strong>: What this means to you?  Profile the heck out of your code, pre-assetbundles and after integrating assetbundles.  </p>
<p>Assumptions:<br />
1.  You know or are familiar Unity3D 3.3.<br />
2.  You can code in C#.<br />
3.  You&#8217;re an ace at creating prefabs in Unity.<br />
4.  You&#8217;re using Unity3D 3.3 Pro and iOS Pro.</p>
<p>OK, if you&#8217;re still feeling good, let&#8217;s bounce into this how-to.</p>
<h3>Create the Project</h3>
<h3><span style="font-weight: normal; font-size: 13px;">Open up a new project in Unity3D and set it up for &#8220;iPhone&#8221; iOS.  Feel free to name it whatever passes your way.</span></h3>
<p><span style="font-weight: normal; font-size: 13px;">In the <strong>project</strong> hierarchy, let&#8217;s go ahead and create a simple directory structure as follows:</span><br />
<a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.08.08-PM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.08.08-PM.png" alt="" title="Screen shot 2011-05-03 at 1.08.08 PM" width="253" height="228" class="alignright size-full wp-image-466" /></a><br />
/Example Project/<br />
/Example Project/iphone/<br />
/Example Project/iphone/objects/<br />
/Example Project/iphone/materials/</p>
<p>Hit save after doing this and save your default scene and name it whatever you want.  In my case, I named it &#8220;test&#8221;.</p>
<p>Though, this is a near complete looking example (image to the right), the basic structure should look like the image to the right here.</p>
<p>Add at least one prefab to your project.  I have added two prefabs here, &#8220;box&#8221; and &#8220;ABCD&#8221;.  Both are just tests and contain a cube prefab with a simple texture applied.  Make sure that the materials referenced by your prefabs have the following attributes.  1.  They are named the same as the prefab.  (See the image above!).  2.  They are stored in the materials folder underneath the iphone folder.</p>
<h3>UnityEditor Coding Time</h3>
<p>When working on assetbundles, the first thing you have to do is generate them.  Unfortunately, Unity3D does not have anything built in for generating these files except for a UnityEditor API.  The UnityEditor script can only be run from inside the Unity3D editor tool.  It typically appears as a menu item after the script has been successfully compiled.  So if you can code, then you&#8217;re in good shape.  </p>
<p>Let&#8217;s create the UnityEditor script.  Create a new C-Sharp script in a <strong>/Plugins/</strong> folder (create it if it doesn&#8217;t already exist) at the root of your project and name it <em>MPCreateAssetBundle</em>.  Copy and paste the following into it.  <em>Please note: some of this code was borrowed from Unity&#8217;s own Character Customization tutorial on their website</em>.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p460code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p46012"><td class="code" id="p460code12"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEditor</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Object</span><span style="color: #008000;">=</span>UnityEngine<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MPCreateAssetBundle <span style="color: #008000;">:</span> MonoBehaviour <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> mpAssetDir <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#123;</span><span style="color: #666666;">&quot;iphone&quot;</span>, <span style="color: #666666;">&quot;ipad&quot;</span>, <span style="color: #666666;">&quot;macosx&quot;</span>, <span style="color: #666666;">&quot;pc&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">// , &quot;universal&quot;}; &lt;-- not needed, use the /Resources/ folder.</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>MenuItem<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Custom/Monkey Prism/Create All Assetbundles #&amp;i&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Execute<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Creating Assetbundles&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">bool</span> blnFound <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">String</span> currentDir <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">Object</span> o <span style="color: #0600FF; font-weight: bold;">in</span> Selection<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFiltered</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#41;</span>, SelectionMode<span style="color: #008000;">.</span><span style="color: #0000FF;">DeepAssets</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			blnFound <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>o<span style="color: #008000;">.</span><span style="color: #0000FF;">name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;@&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//animations!</span>
			<span style="color: #6666cc; font-weight: bold;">String</span> assetPath <span style="color: #008000;">=</span> AssetDatabase<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAssetPath</span><span style="color: #008000;">&#40;</span>o<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>assetPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				currentDir <span style="color: #008000;">=</span> assetPath<span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//Files only.</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #008080; font-style: italic;">//Only check those directories that we have specified in the mpAssetDir</span>
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>assetPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #6666cc; font-weight: bold;">String</span> currentBuildType <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> s <span style="color: #0600FF; font-weight: bold;">in</span> mpAssetDir<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>assetPath<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">+</span>s<span style="color: #008000;">+</span><span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					currentBuildType <span style="color: #008000;">=</span> s<span style="color: #008000;">;</span>
					<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>currentBuildType <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//if the directory is not found to be one from the mpAssetDir bail out.</span>
&nbsp;
			<span style="color: #6666cc; font-weight: bold;">string</span> assetBundleName <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span>, genericName <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
			List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;</span> toinclude <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">//Generate pre-fabs for everything in the finished pre-fab directory.</span>
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>o<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>GameObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;GameObject &quot;</span> <span style="color: #008000;">+</span> currentDir<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				<span style="color: #6666cc; font-weight: bold;">String</span> d <span style="color: #008000;">=</span> CharacterRoot<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>GameObject<span style="color: #008000;">&#41;</span>o<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				d <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot;materials/&quot;</span><span style="color: #008000;">;</span>
				Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>d<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				List<span style="color: #008000;">&lt;</span>Material<span style="color: #008000;">&gt;</span> materials <span style="color: #008000;">=</span> CollectAll<span style="color: #008000;">&lt;</span>Material<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>d<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;materials count=&quot;</span> <span style="color: #008000;">+</span> materials<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				genericName <span style="color: #008000;">=</span> o<span style="color: #008000;">.</span><span style="color: #0000FF;">name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				assetBundleName <span style="color: #008000;">=</span> currentBuildType <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;-prefab-&quot;</span> <span style="color: #008000;">+</span> genericName<span style="color: #008000;">;</span>
				<span style="color: #008080; font-style: italic;">//Package up the prefabs in the iPhone directory.</span>
				toinclude<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>o<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008080; font-style: italic;">//Do we need to add in a material?  I think so.</span>
				<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Material m <span style="color: #0600FF; font-weight: bold;">in</span> materials<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Material Name=&quot;</span> <span style="color: #008000;">+</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>m<span style="color: #008000;">.</span><span style="color: #0000FF;">name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>genericName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
						toinclude<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
						Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Added a new material!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #008000;">&#125;</span>
				<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end foreach</span>
&nbsp;
			<span style="color: #008000;">&#125;</span> 
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>assetBundleName <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
			<span style="color: #008080; font-style: italic;">// Create a directory to store the generated assetbundles.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>AssetbundlePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateDirectory</span><span style="color: #008000;">&#40;</span>AssetbundlePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Delete existing assetbundles for current object</span>
            <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> existingAssetbundles <span style="color: #008000;">=</span> Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFiles</span><span style="color: #008000;">&#40;</span>AssetbundlePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> bundle <span style="color: #0600FF; font-weight: bold;">in</span> existingAssetbundles<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">EndsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;.assetbundle&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/assetbundles/&quot;</span> <span style="color: #008000;">+</span> assetBundleName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    File<span style="color: #008000;">.</span><span style="color: #0000FF;">Delete</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">//Directories expected.</span>
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;currentBuildType = &quot;</span> <span style="color: #008000;">+</span> currentBuildType<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">//path = AssetbundlePath + bundleName + &quot;.assetbundle&quot;;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>toinclude<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #6666cc; font-weight: bold;">String</span> path <span style="color: #008000;">=</span> AssetbundlePath <span style="color: #008000;">+</span> assetBundleName <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.assetbundle&quot;</span><span style="color: #008000;">;</span>
				Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>currentBuildType<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>mpAssetDir<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> currentBuildType<span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>mpAssetDir<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">//iPhone &amp; iPad</span>
					BuildPipeline<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildAssetBundle</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span>, toinclude<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, path, BuildAssetBundleOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">CollectDependencies</span>, BuildTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">//TODO: might need to condition further and might want to use an enum with the conditional.</span>
					BuildPipeline<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildAssetBundle</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span>, toinclude<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, path, BuildAssetBundleOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">CollectDependencies</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end foreach</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>blnFound<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;no objects were found for building assets with.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>	
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> AssetbundlePath
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;assetbundles&quot;</span> <span style="color: #008000;">+</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">DirectorySeparatorChar</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// This method loads all files at a certain path and</span>
    <span style="color: #008080; font-style: italic;">// returns a list of specific assets.</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> CollectAll<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> path<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">Object</span>
    <span style="color: #008000;">&#123;</span>
        List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> l <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> files <span style="color: #008000;">=</span> Directory<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFiles</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> file <span style="color: #0600FF; font-weight: bold;">in</span> files<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;.meta&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
            T asset <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span> AssetDatabase<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadAssetAtPath</span><span style="color: #008000;">&#40;</span>file, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>asset <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Asset is not &quot;</span> <span style="color: #008000;">+</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;: &quot;</span> <span style="color: #008000;">+</span> file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            l<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>asset<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> l<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>	
	<span style="color: #008080; font-style: italic;">// Returns the path to the directory that holds the specified FBX.</span>
    <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> CharacterRoot<span style="color: #008000;">&#40;</span>GameObject character<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span> root <span style="color: #008000;">=</span> AssetDatabase<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAssetPath</span><span style="color: #008000;">&#40;</span>character<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> root<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, root<span style="color: #008000;">.</span><span style="color: #0000FF;">LastIndexOf</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'/'</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Once this is completed, you&#8217;ll want to do two things.<br />
1.  Select (by moving your mouse over and left-clicking on it once) the <strong>iphone</strong> folder under &#8220;Example Project&#8221;.<br />
2.  Run the script as shown in the image:  <a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.45.19-PM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.45.19-PM.png" alt="" title="Screen shot 2011-05-03 at 1.45.19 PM" width="647" height="115" class="alignnone size-full wp-image-480" /></a></p>
<p>So let&#8217;s back up for a second and look at what we just did.  We created a project, created some folders within the project, placed prefabs into the iphone folder and created a UnityEditor script.  Upon running this script, a new directory named &#8220;assetbundles&#8221; would be created.<br />
<a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.56.22-PM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-1.56.22-PM.png" alt="" title="Screen shot 2011-05-03 at 1.56.22 PM" width="448" height="236" /></a><br />
This directory is not going to be visible to you until you open finder (on Mac) or explorer (on Windows) as it is located on the file system.  (see the image above).  Inside this folder you should see your prefab(s) named now as:  <em>iphone-prefab-&lt;my prefab name&gt;.assetbundle</em>.  If you are seeing this, congratulations, you&#8217;ve now created your own assetbundles uniquely per prefab.</p>
<h3>Generic GameObject and a Simple Script</h3>
<p>If you&#8217;ve come this far, great work!  We&#8217;re nearly done.<br />
Let&#8217;s create a new GameObject under the <strong>Hierarchy</strong>. </p>
<p>Now we&#8217;re going to write a simple script to instantiate the assetbundles we assembled earlier.  Create a new C-Sharp script in the <strong>/Plugins/</strong> folder and name it &#8220;Example&#8221;.  Copy and paste the following code into it:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p460code13'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p46013"><td class="code" id="p460code13"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Example <span style="color: #008000;">:</span> MonoBehaviour <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> WWW www<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> AssetBundleRequest gameObjectRequest<span style="color: #008000;">;</span>	
	<span style="color: #008080; font-style: italic;">// Use this for initialization</span>
	IEnumerator Start <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//TODO: change the name of the file below!!!</span>
		<span style="color: #6666cc; font-weight: bold;">String</span> strPath <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;file://&quot;</span> <span style="color: #008000;">+</span> Application<span style="color: #008000;">.</span><span style="color: #0000FF;">dataPath</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;/../assetbundles/iphone-prefab-box.assetbundle&quot;</span><span style="color: #008000;">;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>strPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		www <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WWW<span style="color: #008000;">&#40;</span>strPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> www<span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/* TODO: change the name &quot;Box&quot; to match the name of your prefab that you compiled into the assetbundle on step 1. */</span>
		AssetBundleRequest request <span style="color: #008000;">=</span> www<span style="color: #008000;">.</span><span style="color: #0000FF;">assetBundle</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LoadAsync</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Box&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>GameObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> request<span style="color: #008000;">;</span>
		Instantiate<span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">asset</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Vector3<span style="color: #008000;">&#40;</span>3f, 0f, 0f<span style="color: #008000;">&#41;</span>, Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">identity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		Instantiate<span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">asset</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Vector3<span style="color: #008000;">&#40;</span>0f, 0f, 0f<span style="color: #008000;">&#41;</span>, Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">identity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		Instantiate<span style="color: #008000;">&#40;</span>request<span style="color: #008000;">.</span><span style="color: #0000FF;">asset</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Vector3<span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span>3f, 0f, 0f<span style="color: #008000;">&#41;</span>, Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">identity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		www<span style="color: #008000;">.</span><span style="color: #0000FF;">assetBundle</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Unload</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
        <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><strong>NOTE:</strong> Make sure to change the TODO line in the code to match your file name!  If you don&#8217;t do this, it might not work!</p>
<p>We&#8217;re nearly done!  Drag your Example.cs script onto the GameObject you created earlier.  Here is how my project looks:<br />
<a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-2.16.03-PM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-2.16.03-PM.png" alt="" title="Screen shot 2011-05-03 at 2.16.03 PM" width="750" height="367" class="alignnone size-full wp-image-493" /></a></p>
<h3>Build Time</h3>
<p>We&#8217;re now going to build this codebase so that you can run it on your iOS device for testing.  I&#8217;m going to skip the painful steps of creating a code signing certificate and all that jazz.  We&#8217;re instead going to focus on how to get the actual assetbundle onto your iOS device in an area that will be accessible to the &#8220;Application.dataPath&#8221; call in your code!  </p>
<p>1.  Build the Unity project for iOS.<br />
2.  XCode should automatically open.<br />
3.  Within XCode you are going to need to tell it about your assetbundles folder!  Open up finder or explorer and locate the assetbundles folder that was generated by the UnityEditor script we discussed earlier.<br />
4.  Drag and drop the assetbundles folder into XCode at the root of the iOS project.  (You should see a prompt as follows)<br />
<a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-10.53.56-AM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-10.53.56-AM.png" alt="" title="Screen shot 2011-05-03 at 10.53.56 AM" width="739" height="545" class="alignnone size-full wp-image-496" /></a></p>
<p>5.  Click &#8220;Finish&#8221;.  </p>
<p>This will then look something like this:<br />
<a href="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-2.24.30-PM.png"><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/05/Screen-shot-2011-05-03-at-2.24.30-PM.png" alt="" title="Screen shot 2011-05-03 at 2.24.30 PM" width="256" height="157" class="alignnone size-full wp-image-497" /></a></p>
<p>6.  Build the code using XCode and run it on your iOS device.</p>
<p>If everything works properly, you should see one of the prefabs instantiate on your iOS screen.  That is all there is to it!  I think you&#8217;ll find that this isn&#8217;t as bad as one might imagine, but it does require some serious fishing around in code examples and heavily crawling the Unity forums.  The only way I figured this out was by trial and error, heavy amounts of Debug.Log calls and 3 pots of coffee.  I&#8217;m now going to go and grind my teeth on my level editor.</p>
<p>Edit:  I have one of my original forum posts here as well regarding this issue.  <a href="http://forum.unity3d.com/threads/87892-Failed-to-load-asset-bundle">Unity3D Forum</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/05/03/unity3d-file-assetbundles-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Unity3D Conditional Device Compilation By Scenes</title>
		<link>http://www.chrisdanielson.com/2011/04/29/unity3d-conditional-device-compilation-by-scenes/</link>
		<comments>http://www.chrisdanielson.com/2011/04/29/unity3d-conditional-device-compilation-by-scenes/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 19:08:02 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[BuildPipeline]]></category>
		<category><![CDATA[BuildPlayer]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=434</guid>
		<description><![CDATA[Conditionally Dynamic Device Specific Build Process in Unity3D By Scene.]]></description>
			<content:encoded><![CDATA[<p>Recently I <a href="http://forum.unity3d.com/threads/87495-Conditionally-Dynamic-Device-Specific-Build-Process">posted at the Unity3D forum</a> in regard to how one can create a single project and compile multiple device and platform builds within this context.  My goal here is simply to reduce having multiple projects for a single Unity3d application.</p>
<blockquote><p>On my second cup of coffee here and hope I make sense with my questions here.</p>
<p>After watching the fantastic Smuggle Truck design/build discussions here:</p>
<p>http://learnunity3d.com/2011/04/smug&#8230;chniques-talk/</p>
<p>I was perplexed by how they created the iPad/iPhone/Mac OS conditional compilation build all from a single project. Only those assets referenced for that build are baked into the final project that is then sent to XCode.</p>
<p>I&#8217;m aware of the preprocessor flags (http://unity3d.com/support/documenta&#8230;mpilation.html). I also understand how to use them.</p>
<p>I guess the hurdle(s) I haven&#8217;t figured out yet are the following.</p>
<p>1. How does one condition the build between UNITY_IPHONE and UNITY_IPAD? Note: there isn&#8217;t any UNITY_IPAD define that I&#8217;m aware of. Within the Unity editor it is not possible to pass in custom preprocessor defines globally. They are scoped per-script. I see the command line option of &#8220;-executeMethod …&#8221; (http://unity3d.com/support/documenta&#8230;Arguments.html) Perhaps that is the magic sauce?</p>
<p>2. How did they conditionally include only unique assets to that particular build? For example, Mac OS X textures would be a higher resolution than those for the iPad and iPhone. Perhaps, this will be answered in question one.</p>
<p>Anyone have any ideas or other forum links that I may have missed?<br />
Note, I have seen this: http://forum.unity3d.com/threads/171&#8230;al+Compilation</p></blockquote>
<p><img src="http://www.chrisdanielson.com/wp-content/uploads/2011/04/Screen-shot-2011-04-29-at-11.32.53-AM.png" alt="" title="Creating a device independent project BY SCENE." width="257" height="147" class="alignleft size-full wp-image-436" />Well here is a basic solution that is created <strong>by scene</strong>.  By scene means that you have to create a different scene for each device but give them the same name.   As seen in the first picture here.</p>
<p>Let me just state for the record that this solution would work perfectly but it is <strong>less than ideal</strong>.  I am posting this to merely explain how to conditionally gather assets into a final deployment as well as to isolate resources per build.  I believe the ideal solution would be to use asset bundles.  I will cover that in a new blog entry in a few days/weeks as I figure it out as well.</p>
<p>I am going to provide a script at the bottom of this article and a zip file containing the magic mixture to easily integrate this beast into your project.  Integrating this script is easy.  Simply uncompress the zip file and place the &#8220;MonkeyPrism&#8221; folder into the root of your project.  <img src="http://www.chrisdanielson.com/wp-content/uploads/2011/04/Screen-shot-2011-04-29-at-11.33.09-AM.png" alt="" title="Script added into Unity Editor" width="291" height="49" class="alignright size-full wp-image-444" /></p>
<p>Once you have the C-Sharp editor object installed you should be able to run the basic build process using the menu system or shortcut keys as documented within the C-Sharp code.<br />
<img src="http://www.chrisdanielson.com/wp-content/uploads/2011/04/Screen-shot-2011-04-29-at-11.40.50-AM.png" alt="" title="Unity3D Monkey Prism Build Process integrated script." width="402" height="133" class="alignnone size-full wp-image-446" /></p>
<p><a href='http://www.chrisdanielson.com/wp-content/uploads/2011/04/MonkeyPrism.zip'>Download the file here</a>.</p>
<p>Everyone:  This script requires Unity Pro and it is setup to build for (iPhone, iPad, Mac OS Universal and Windows).<br />
PC Users:  Take note that I used the &#8220;/&#8221; in my script.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p434code14'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p43414"><td class="code" id="p434code14"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEditor</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// A C# build object demonstrating a dynamic build process for Unity 3D.</span>
<span style="color: #008080; font-style: italic;">/// </span>
<span style="color: #008080; font-style: italic;">/// This script requires you to organize your scenes by device and platform as follows:</span>
<span style="color: #008080; font-style: italic;">///		SCENES_LOC / {iphone, ipad, macos, pc} / {your scenes}</span>
<span style="color: #008080; font-style: italic;">///		i.e.	Assets/Scenes/iphone/scene0.unity</span>
<span style="color: #008080; font-style: italic;">///				Assets/Scenes/iphone/scene1.unity</span>
<span style="color: #008080; font-style: italic;">/// </span>
<span style="color: #008080; font-style: italic;">/// </span>
<span style="color: #008080; font-style: italic;">/// Please note: this is not perfect and honestly, I'm looking into an asset bundle</span>
<span style="color: #008080; font-style: italic;">/// solution as well here.  I just wanted to figure out if there was a better solution.</span>
<span style="color: #008080; font-style: italic;">/// Version 1.0</span>
<span style="color: #008080; font-style: italic;">/// April 29, 2011</span>
<span style="color: #008080; font-style: italic;">/// License:  Free to use and modify.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MonkeyPrismBuild <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//TODO: place your core scenes location here.  (relative to the already loaded project)</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> SCENES_LOC <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Assets/Scenes/&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">//TODO: place your scenes into this array.</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> myScenes <span style="color: #008000;">=</span> <span style="color: #008000;">&#123;</span> 
		<span style="color: #666666;">&quot;home.unity&quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">/*, &quot;levelselect.unity&quot;, 
		&quot;game.unity&quot;, &quot;credits.unity&quot; };*/</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">enum</span> MP_BUILD_TYPE <span style="color: #008000;">&#123;</span>
		iPhone <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, iPad, MacOS, PC
	<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
	<span style="color: #008080; font-style: italic;">/**
	 * Make sure uniqueBuildNames maps with the enum above and take note of the GetScenesByBuildType method.
	 * Also: make sure that these names match with directories under your SCENES_LOC.
	 */</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> uniqueBuildNames <span style="color: #008000;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #666666;">&quot;iphone&quot;</span>,<span style="color: #666666;">&quot;ipad&quot;</span>,<span style="color: #666666;">&quot;macos&quot;</span>,<span style="color: #666666;">&quot;pc&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>MenuItem <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Tools/Build/iPhone #&amp;i&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #008080; font-style: italic;">//press shift+alt+i</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> PerformBuildIPHONE<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Building iPhone version&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		RunBuild<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>MenuItem <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Tools/Build/iPad #&amp;p&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #008080; font-style: italic;">//press shift+alt+p</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> PerformBuildIPAD<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Building iPad version&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		RunBuild<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPad</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>MenuItem <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Tools/Build/Mac OS #&amp;m&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #008080; font-style: italic;">//press shift+alt+m</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> PerformBuildMACOS<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Building Universal Mac OS version&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		RunBuild<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">MacOS</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#91;</span>MenuItem <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Tools/Build/PC #&amp;c&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #008080; font-style: italic;">//press shift+alt+c</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> PerformBuildPC<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Building Windows PC version&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		RunBuild<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">PC</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> GetScenesByBuildType<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE type, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> buildDir<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #6666cc; font-weight: bold;">int</span> len <span style="color: #008000;">=</span> myScenes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> scenes <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span>len<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">//string buildDir = null;</span>
		<span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>type<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPad</span><span style="color: #008000;">:</span>
				buildDir <span style="color: #008000;">=</span> uniqueBuildNames<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPad</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span><span style="color: #008000;">:</span>
				buildDir <span style="color: #008000;">=</span> uniqueBuildNames<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">MacOS</span><span style="color: #008000;">:</span>
				buildDir <span style="color: #008000;">=</span> uniqueBuildNames<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">MacOS</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">PC</span><span style="color: #008000;">:</span>
				buildDir <span style="color: #008000;">=</span> uniqueBuildNames<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">PC</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end switch;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>buildDir <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> buildDir<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> 
			<span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Invalid MP_BUILD_TYPE::BuildType Specified.  Please visit the MPBuild.cs script to resolve.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> len<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			scenes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> SCENES_LOC <span style="color: #008000;">+</span> buildDir <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;/&quot;</span> <span style="color: #008000;">+</span> myScenes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> scenes<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RunBuild<span style="color: #008000;">&#40;</span>MP_BUILD_TYPE type<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span> buildDir <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> scenes <span style="color: #008000;">=</span> GetScenesByBuildType<span style="color: #008000;">&#40;</span>type, <span style="color: #0600FF; font-weight: bold;">ref</span> buildDir<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>type<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPad</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span><span style="color: #008000;">:</span>
				BuildPipeline<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildPlayer</span><span style="color: #008000;">&#40;</span>scenes, buildDir, BuildTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">iPhone</span>, BuildOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">MacOS</span><span style="color: #008000;">:</span>
				BuildPipeline<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildPlayer</span><span style="color: #008000;">&#40;</span>scenes, buildDir, BuildTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">StandaloneOSXUniversal</span>, BuildOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">case</span> MP_BUILD_TYPE<span style="color: #008000;">.</span><span style="color: #0000FF;">PC</span><span style="color: #008000;">:</span>
				BuildPipeline<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildPlayer</span><span style="color: #008000;">&#40;</span>scenes, buildDir, BuildTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">StandaloneWindows</span>, BuildOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">//end switch;</span>
&nbsp;
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/04/29/unity3d-conditional-device-compilation-by-scenes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity 3D JavaScript and C# Scoping/Compiling Issue</title>
		<link>http://www.chrisdanielson.com/2011/04/22/unity-3d-javascript-and-c-scopingcompiling-issue/</link>
		<comments>http://www.chrisdanielson.com/2011/04/22/unity-3d-javascript-and-c-scopingcompiling-issue/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 17:58:53 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Compiling]]></category>
		<category><![CDATA[Interoperate]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Scope]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=423</guid>
		<description><![CDATA[This is a quick write-up regarding something as simple as getting JavaScript to interoperate properly with C# scripts in your Unity projects. I ran into such an issue after purchasing EZ Gui via the Unity Asset Store.  Immediately upon purchasing you are prompted to &#8220;import&#8221; the project into your codebase.  I did this without issue. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick write-up regarding something as simple as getting JavaScript to interoperate properly with C# scripts in your Unity projects.</p>
<p>I ran into such an issue after purchasing EZ Gui via the Unity Asset Store.  Immediately upon purchasing you are prompted to &#8220;import&#8221; the project into your codebase.  I did this without issue.  Everything worked fine and dandy until my JavaScript code required referencing a SpriteText object.  This is when the following issue began happening:</p>
<blockquote><p>Unity BCE0018: The name &#8216;SpriteText&#8217; does not denote a valid type (&#8216;not found&#8217;).</p></blockquote>
<p>My folder structure was simply the following:</p>
<p>/scripts/myCameraScript.js  &lt;&#8211; trying to reference the SpriteText</p>
<p>&nbsp;</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p423code16'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42316"><td class="code" id="p423code16"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">:</span> SpriteText<span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//this line was throwing the error.</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>/EZ GUI/  &lt;&#8211; default after purchasing and importing from the Unity Asset store.</p>
<p>I sat and read Unity compiling and scoping rules over and over located <a href="http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html" target="_blank">here</a>.  On point 4, the statement reads &#8220;All scripts that are compiled in this step have access to all scripts in the first group (&#8220;Standard Assets&#8221;, &#8220;Pro Standard Assets&#8221; or &#8220;Plugins&#8221;).&#8221;</p>
<p>The solution is simple here.  Take the EZ Gui code located in the &#8220;Plugins&#8221; folder and move it to the root.</p>
<p>/EZ Gui/Plugins/   &lt;&#8211; move this to:</p>
<p>/Plugins/</p>
<p>Done.  It works.  Super simple.</p>
<p><strong>Bonus Play</strong>, Rule of thumb (kind of no brainers really):</p>
<ol>
<li>Place all your plugins in the <strong>/Plugins/</strong> folder.</li>
<li>Place all your C# Code into the <strong>/Standard Assets/</strong> folder.</li>
<li>Place all your JavaScript code into <strong>/Scripts/</strong> or any folder that is NOT named (&#8220;Standard Assets&#8221;, &#8220;Pro Standard Assets&#8221; or &#8220;Plugins&#8221;)</li>
</ol>
<p>This will lead to success and less headaches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/04/22/unity-3d-javascript-and-c-scopingcompiling-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocos2D and Box2D Compilation Errors</title>
		<link>http://www.chrisdanielson.com/2010/10/30/cocos2d-and-box2d-compilation-errors/</link>
		<comments>http://www.chrisdanielson.com/2010/10/30/cocos2d-and-box2d-compilation-errors/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 17:29:58 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[glui.h]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=385</guid>
		<description><![CDATA[This is just to help those that have run into a whole slew of linking and other errors when attempting to add the cocos2d and Box2d frameworks directly into your project. This information is pertinent for: #define COCOS2D_VERSION 0&#215;00009904 Cocos2d is easy enough to get to compile into your project.  Dealing with Box2d is entirely [...]]]></description>
			<content:encoded><![CDATA[<p>This is just to help those that have run into a whole slew of linking and other errors when attempting to add the cocos2d and Box2d frameworks directly into your project.</p>
<p>This information is pertinent for:</p>
<blockquote><p>#define COCOS2D_VERSION 0&#215;00009904</p></blockquote>
<p>Cocos2d is easy enough to get to compile into your project.  Dealing with Box2d is entirely more complicated if you don&#8217;t understand how the file inclusions work.  Because of the location of the Box2D.h file you&#8217;ll quickly find yourself in a nearly endless conundrum of mismapped linking&#8230;</p>
<p>Here is how my project is currently setup:</p>
<div id="attachment_387" class="wp-caption alignleft" style="width: 186px"><img class="size-full wp-image-387" title="Cocos2D with Box2D project Groups" src="http://www.chrisdanielson.com/wp-content/uploads/2010/10/Screen-shot-2010-10-30-at-9.53.40-AM.png" alt="" width="176" height="149" /><p class="wp-caption-text">Cocos2D with Box2D Project Groups</p></div>
<p>As you can see I have created the Box2D and Cocos2D directories as groups.</p>
<p>The actual file system looks like (I created the lib folder):</p>
<div id="_mcePaste">/Users/chris/Documents/iphone_apps/myCocos2DProject/lib</div>
<div>which contains the following directories copied directly from the cocos2D download source package:  <strong>cocos2d</strong> and   <strong>external</strong></div>
<div><em>Take careful note that I have removed the &#8220;<strong>TestBed</strong>&#8221; in order to avoid the missing &#8220;glui.h&#8221; issues!</em></div>
<div>So even with this setup I still was receiving over 5000 nasty Box2D errors.  Here is the fix I found to work.</div>
<div>==========================</div>
<div>==========================</div>
<div>
<ol>
<li>Go to <strong>Project</strong> -&gt; <strong>Edit Active Target &#8220;myCocos2DProject&#8221;</strong></li>
<li><strong> </strong>Select the <strong>Build</strong> tab.</li>
</ol>
</div>
<div>
<dl id="attachment_389" class="wp-caption alignright" style="width: 491px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-389" title="Edit XCode Project Settings" src="http://www.chrisdanielson.com/wp-content/uploads/2010/10/Screen-shot-2010-10-30-at-9.48.47-AM.png" alt="" width="481" height="90" /></dt>
<dd class="wp-caption-dd">Edit XCode Project Settings</dd>
</dl>
</div>
<div>Check the &#8220;<strong>Always Search User Paths</strong>&#8220;</div>
<div>And add in the &#8220;lib/external/Box2d/**&#8221; into the &#8220;<strong>User Header Search Paths</strong>&#8221;  Pro Tip: <em>When adding the header search paths, make sure that you have the <span style="text-decoration: underline;">recurse</span></em><em> check box selected.</em></div>
<div>That is all you have to so to fix the issue!</div>
<div>One final super pro tip:  Make sure that your .m files are renamed to .mm in order to get the C++ libraries working.  You will have to rename the AppDelegate_iPhone.m to AppDelegate_iPhone.mm.  (Otherwise you&#8217;ll see errors like:  cassert no such file or directory, etc.)</div>
<div></div>
<div>Happy Box2D coding.</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2010/10/30/cocos2d-and-box2d-compilation-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

