<?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>CosmicMesh.com</title>
	<atom:link href="http://www.cosmicmesh.com/wp/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.cosmicmesh.com/wp</link>
	<description></description>
	<lastBuildDate>Tue, 19 Jul 2011 03:19:08 +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>Inaugural Meeting of the Washington, DC Area Uniteers</title>
		<link>http://www.cosmicmesh.com/wp/?p=108</link>
		<comments>http://www.cosmicmesh.com/wp/?p=108#comments</comments>
		<pubDate>Tue, 19 Jul 2011 03:19:08 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=108</guid>
		<description><![CDATA[JRavey and I (and anyone else who happens to be at the Starbucks in Rosslyn) will be holding the inaugural meeting of the Washington, DC Area Uniteers on Wednesday evening, July 19, 2011 at 7pm. Starbucks 1501 N 17th Street Arlington, VA 22209]]></description>
			<content:encoded><![CDATA[<p>JRavey and I (and anyone else who happens to be at the Starbucks in Rosslyn) will be holding the inaugural meeting of the <a href="http://forum.unity3d.com/threads/96003-Washington-DC-Uniteers">Washington, DC Area Uniteers</a> on Wednesday evening, July 19, 2011 at 7pm.<br />
<br />
Starbucks<br />
1501 N 17th Street<br />
Arlington, VA 22209</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=108</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>uScript Pricing Revealed</title>
		<link>http://www.cosmicmesh.com/wp/?p=89</link>
		<comments>http://www.cosmicmesh.com/wp/?p=89#comments</comments>
		<pubDate>Mon, 18 Jul 2011 00:49:24 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[uScript]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=89</guid>
		<description><![CDATA[The team at Detox Studios announced their pricing for uScript today, via this Pricing FAQ on their website. The retail price of $195 appears fair, particularly given uScript&#8217;s capabilities when compared to other Unity visual scripting tools. The early adopter price of $95, available for the first month or so following release, seems very good. <a href='http://www.cosmicmesh.com/wp/?p=89' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>The team at <a href="http://www.detoxstudios.com/">Detox Studios</a> announced their pricing for uScript today, via <a href="http://www.detoxstudios.com/?p=87">this Pricing FAQ on their website</a>. The retail price of $195 appears fair, particularly given <a href="http://www.detoxstudios.com/?page_id=10">uScript&#8217;s</a> capabilities when compared to other <a href="http://www.unity3d.com">Unity</a> visual scripting tools. The early adopter price of $95, available for the first month or so following release, seems very good. The team notes they are targeting a mid-August release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=89</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nodes, Nodes, Nodes</title>
		<link>http://www.cosmicmesh.com/wp/?p=65</link>
		<comments>http://www.cosmicmesh.com/wp/?p=65#comments</comments>
		<pubDate>Tue, 12 Jul 2011 02:13:51 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[uScript]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=65</guid>
		<description><![CDATA[I&#8217;ve been participating in the open beta of the uScript Visual Scripting Tool from the guys at Detox Studios.  uScript&#8217;s interface will be familiar to users of Unreal Kistmet or VirTools, and is intended to offer similar visual scripting capabilities to teams using Unity. I&#8217;ve been very impressed with uScript, so far.  Like any beta, <a href='http://www.cosmicmesh.com/wp/?p=65' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.detoxstudios.com/"><img class="alignright size-full wp-image-90" title="uScript Logo" src="http://www.cosmicmesh.com/wp/wp-content/uploads/2011/07/sitelogo_small.png" alt="uScript by Detox Studios" width="300" height="100" /></a></p>
<p>I&#8217;ve been participating in the open beta of the <a href="http://uscript.net/forum/index.php" target="_blank">uScript Visual Scripting Tool</a> from the guys at <a href="http://www.detoxstudios.com/" target="_blank">Detox Studios</a>.  uScript&#8217;s interface will be familiar to users of <a href="http://www.unrealengine.com/features/kismet/" target="_blank">Unreal Kistmet</a> or <a href="http://www.3dvia.com/products/3dvia-virtools/" target="_blank">VirTools</a>, and is intended to offer similar visual scripting capabilities to teams using <a href="http://www.unity3d.com" target="_blank">Unity</a>.</p>
<p>I&#8217;ve been very impressed with uScript, so far.  Like any beta, there are bugs and quirky bits.  However, the team of developers has been very engaged in answering questions, acknowledging bugs, and incorporating feedback into the product.  They have gotten a sizable number of interested users (440 forum users, as of this evening) and a core group of folks that are offering feedback, examples, finding bugs, and hunting for features.</p>
<p>I&#8217;ve been using the product alongside those others, and I&#8217;ve provided a couple of new nodes to perform certain functions, which were missing from the core beta release.  None of these are rocket science, just things I needed to be able to do when building graphs with uScript.  They&#8217;ve made it very easy to extend&#8230; so, I did so as a way to see how it was done and give others some of the missing bits I wanted, too.</p>
<p>Those nodes are listed in their <a href="http://www.uscript.net/forum/viewforum.php?f=21" target="_blank">Node forum</a> are, and I am cross-posting here to make them easy to find:</p>
<ul>
<li><a href="http://uscript.net/forum/viewtopic.php?f=21&amp;t=63">Firing an Event with Named Axis Input</a></li>
<li><a href="http://uscript.net/forum/viewtopic.php?f=21&amp;t=89">Mouse Axis Input</a></li>
<li><a href="http://uscript.net/forum/viewtopic.php?f=21&amp;t=102">Screen showCursor</a></li>
<li><a href="http://uscript.net/forum/viewtopic.php?f=21&amp;t=107">Get GameObject Name</a></li>
<li><a href="http://uscript.net/forum/viewtopic.php?f=21&amp;t=128">GameObjects and Nulls</a> (CompareToNull and SetNull)</li>
</ul>
<div><span style="font-size: medium;"><span class="Apple-style-span" style="font-size: 16px; line-height: 24px;">Please note that the licensing for these nodes conforms to the <a href="http://www.uscript.net/forum/ucp.php?mode=terms">Terms of Service</a> posted by the guys at Detox Studios.</span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=65</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixed Sized Queue</title>
		<link>http://www.cosmicmesh.com/wp/?p=62</link>
		<comments>http://www.cosmicmesh.com/wp/?p=62#comments</comments>
		<pubDate>Tue, 05 Jul 2011 02:51:23 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=62</guid>
		<description><![CDATA[During some work today, I needed to manage a queue of objects in a last-in first-out (LIFO) pattern.  Unusually (for me, anyway) I also wanted to constrain the size of the queue to a maximum number of objects. The result is the FixedSizedQueue, shown below. 123456789101112131415161718192021222324252627282930using System.Collections; using System.Collections.Generic; public class FixedSizedQueue&#60;T&#62; &#123; &#160; &#160; <a href='http://www.cosmicmesh.com/wp/?p=62' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>During some work today, I needed to manage a queue of objects in a last-in first-out (<a href="http://en.wikipedia.org/wiki/LIFO_(computing)">LIFO</a>) pattern.  Unusually (for me, anyway) I also wanted to constrain the size of the <a href="http://msdn.microsoft.com/en-us/library/system.collections.queue.aspx">queue</a> to a maximum number of objects. The result is the FixedSizedQueue, shown below.</p>
<div class="codecolorer-container csharp dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> FixedSizedQueue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// A regular ol' Queue</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Queue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> q <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Queue<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><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Size limit we're working with</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Limit <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Adds the newest item to the queue,</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// drops the oldest</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Enqueue<span style="color: #008000;">&#40;</span>T obj<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; q<span style="color: #008000;">.</span><span style="color: #0000FF;">Enqueue</span><span style="color: #008000;">&#40;</span>obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>q<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> Limit<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q<span style="color: #008000;">.</span><span style="color: #0000FF;">Dequeue</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Accesses the current number of objects</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// in the queue</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Count<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">&#40;</span>q<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SourceTree: Finally a Top-Notch Mercurial Client for Mac</title>
		<link>http://www.cosmicmesh.com/wp/?p=61</link>
		<comments>http://www.cosmicmesh.com/wp/?p=61#comments</comments>
		<pubDate>Fri, 01 Jul 2011 03:51:21 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[SourceTree]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=61</guid>
		<description><![CDATA[Mercurial is my favorite DVCS because of the options available for branching/merging and its preservation of history (Hg prevents you from changing previous commits). It has a relatively simple command line tool, but it has been missing a powerful and intuitive GUI on OSX. Several options were available, but all seemed immature and brittle, despite <a href='http://www.cosmicmesh.com/wp/?p=61' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Mercurial is my favorite <a href="http://en.wikipedia.org/wiki/Distributed_Version_Control_System">DVCS</a> because of the options available for branching/merging and its preservation of history (Hg prevents you from changing previous commits).  It has a relatively simple command line tool, but it has been missing a powerful and intuitive GUI on OSX.  Several options  were available, but all seemed immature and brittle, despite the increasing popularity of DVCS among mac-based developers.</p>
<p>Enter <a href="http://www.sourcetreeapp.com/">SourceTree</a> (£35/$60 in the <a href="http://itunes.apple.com/us/app/sourcetree/id411678673?mt=12&amp;ls=1">Mac AppStore</a>).  SourceTree offers multi-repository support for <a href="http://git-scm.com/">Git</a> and <a href="http://mercurial.selenic.com/">Mercurial</a> repositories (and SVN) in a single tool.  You can preview binary assets (images) and its integration of diff tools is easy to use and intuitive.</p>
<p>I just picked it up, and so far I really enjoy using it.  I have not yet done any hardcore branch/merge activity, so I&#8217;ll plan to update this post with my feedback in the future.  But, for now, we seem to have a winner!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=61</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Power of Unity</title>
		<link>http://www.cosmicmesh.com/wp/?p=49</link>
		<comments>http://www.cosmicmesh.com/wp/?p=49#comments</comments>
		<pubDate>Thu, 26 May 2011 17:46:40 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=49</guid>
		<description><![CDATA[Richard Fine posted a great article on Gamasutra about the power and flexibility offered by Unity, as well as the reasons it can be challenging for newcomers with a traditional development background.  Read more in the article, Opinion: Six Misconceptions I Had About Unity.]]></description>
			<content:encoded><![CDATA[<p>Richard Fine posted a great article on <a href="http://www.gamasutra.com">Gamasutra</a> about the power and flexibility offered by <a href="http://unity3d.com/">Unity</a>, as well as the reasons it can be challenging for newcomers with a traditional development background.  Read more in the article, <a href="http://www.gamasutra.com/view/news/34394/Opinion_The_Six_Misconceptions_I_Had_About_Unity.php">Opinion: Six Misconceptions I Had About Unity</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=49</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Practices for Version Control</title>
		<link>http://www.cosmicmesh.com/wp/?p=31</link>
		<comments>http://www.cosmicmesh.com/wp/?p=31#comments</comments>
		<pubDate>Sun, 17 Apr 2011 16:52:32 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=31</guid>
		<description><![CDATA[Currently, we&#8217;re using Mercurial for version control, and leveraging hosting and other tools provided by Fog Creek Software&#8217;s Kiln platform. I was doing some research on branching/merging, and came across this great blog post outlining best practices for version control.  The article is system-agnostic, and provides some good techniques and examples of why they are <a href='http://www.cosmicmesh.com/wp/?p=31' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Currently, we&#8217;re using <a href="http://mercurial.selenic.com/" target="_blank">Mercurial</a> for version control, and leveraging hosting and other tools provided by <a href="http://www.fogcreek.com/" target="_blank">Fog Creek Software&#8217;s</a> <a href="http://www.fogcreek.com/kiln/" target="_blank">Kiln</a> platform.</p>
<p>I was doing some research on branching/merging, and came across <a href="http://blog.looplabel.net/2008/07/28/best-practices-for-version-control/" target="_blank">this great blog post</a> outlining best practices for <a href="http://en.wikipedia.org/wiki/Version_control" target="_blank">version control</a>.  The article is system-agnostic, and provides some good techniques and examples of why they are valuable.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=31</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>L3DT Mosaic Terrains</title>
		<link>http://www.cosmicmesh.com/wp/?p=14</link>
		<comments>http://www.cosmicmesh.com/wp/?p=14#comments</comments>
		<pubDate>Mon, 11 Apr 2011 20:24:41 +0000</pubDate>
		<dc:creator>CosmicMesh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Terrain]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=14</guid>
		<description><![CDATA[As part of my current project, I wanted to set up a very large game area, allowing the player to explore a large game world.  For performance reasons &#8212; both at game time and during design time &#8212; its impractical to implement this as one large terrain object. Fortunately, my favorite landscape generator, L3DT, has <a href='http://www.cosmicmesh.com/wp/?p=14' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>As part of my current project, I wanted to set up a very large game area, allowing the player to explore a large game world.  For performance reasons &#8212; both at game time and during design time &#8212; its impractical to implement this as one large terrain object.</p>
<p>Fortunately, my favorite landscape generator, <a href="http://www.bundysoft.com/L3DT/">L3DT</a>, has the ability to break large maps up into smaller maps (called <a href="http://www.bundysoft.com/docs/doku.php?id=l3dt:algorithms:mosaics">mosaics</a>). Each of the tiles can be exported individually, so I can import each tile into Unity as separate terrain object.  This will allow me to readily implement terrain paging, by creating discreet &#8220;zones&#8221; that can be enabled and disabled via script.  I can even work with each zone as an individual scene (e.g., one terrain and its associated detail objects), as long as I collapse them down to a single prefab that can be combined in the final scene.</p>
<p>One other note &#8212; terrain seams can be a bit of a pain, because of the way L3DT exports tiles, and how Unity imports RAW heightmaps.  <a href="http://forum.unity3d.com/profile.php?mode=viewprofile&amp;u=938">Eric</a> at <a href="http://www.starscenesoftware.com/Home.html">Starscene</a> has created a tool, <a href="http://www.starscenesoftware.com/Utilities.html#Stitchscape">Stitchscape</a>, that readily alters the individual terrains to easily stitch them together without seams.  The price is quite low and it&#8217;s a huge time saver!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=14</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fiddling with Multiple Layers</title>
		<link>http://www.cosmicmesh.com/wp/?p=10</link>
		<comments>http://www.cosmicmesh.com/wp/?p=10#comments</comments>
		<pubDate>Mon, 11 Apr 2011 01:43:16 +0000</pubDate>
		<dc:creator>CosmicMesh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Raycasting]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.cosmicmesh.com/wp/?p=10</guid>
		<description><![CDATA[Today, I needed to implement ray-casting in a Unity scene.  I had a bit of a problem getting the layer mask right, as my skills with bit shifting are mediocre, at best.  So, I&#8217;ve decided to post an example. Specifically, I wanted to get &#8220;mouseover&#8221; information whenever the user&#8217;s mouse floated over certain game objects <a href='http://www.cosmicmesh.com/wp/?p=10' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Today, I needed to implement <a href="http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html">ray-casting</a> in a <a href="http://unity3d.com/">Unity</a> scene.  I had a bit of a problem getting the <a href="http://unity3d.com/support/documentation/ScriptReference/LayerMask.html">layer mask</a> right, as my skills with bit shifting are mediocre, at best.  So, I&#8217;ve decided to post an example.</p>
<p>Specifically, I wanted to get &#8220;mouseover&#8221; information whenever the user&#8217;s mouse floated over certain game objects in the scene, while ignoring other objects.  Conveniently, i had already implemented numerous <a href="http://unity3d.com/support/documentation/Components/Layers.html">layers</a> to hold these objects, so I just had to take those layers into account when performing my ray-casting.</p>
<p>First, I set up some values we&#8217;ll need:</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// Layers</span><br />
<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">var</span> mouseoverIgnoreLayers <span style="color: #339933;">:</span> int <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Mouseover Raycasting</span><br />
<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">var</span> mouseoverHit <span style="color: #339933;">:</span> RaycastHit<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">var</span> mouseoverObject <span style="color: #339933;">:</span> GameObject<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Next, in the Start() function, we&#8217;ll grab the layers we need to mask:</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> Start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// Grab the layers we are looking for</span><br />
mouseoverIgnoreLayers <span style="color: #339933;">=</span> &nbsp;<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span><br />
<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;&lt;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span><br />
<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;&lt;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span><br />
<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;&lt;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span><br />
<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;&lt;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L5&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span><br />
<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&lt;&lt;</span> LayerMask.<span style="color: #660066;">NameToLayer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;L6&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Invert the bitmask so we ignore these but enable the rest</span><br />
mouseoverIgnoreLayers <span style="color: #339933;">=</span> ~mouseoverIgnoreLayers<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Finally, we execute the ray-casting logic in Update():</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> Update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// Get the ray from camera to mouse position</span><br />
<span style="color: #003366; font-weight: bold;">var</span> cameraRay <span style="color: #339933;">:</span> Ray <span style="color: #339933;">=</span> Camera.<span style="color: #660066;">main</span>.<span style="color: #660066;">ScreenPointToRay</span> <span style="color: #009900;">&#40;</span>Input.<span style="color: #660066;">mousePosition</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Test mouseover, ignoring movement layers</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Physics.<span style="color: #660066;">Raycast</span> <span style="color: #009900;">&#40;</span>cameraRay<span style="color: #339933;">,</span> mouseoverHit<span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> mouseoverIgnoreLayers<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #006600; font-style: italic;">// Mouseover info/effects for certain objects</span><br />
mouseoverObject <span style="color: #339933;">=</span> mouseoverHit.<span style="color: #660066;">transform</span>.<span style="color: #660066;">root</span>.<span style="color: #660066;">gameObject</span><span style="color: #339933;">;</span><br />
Debug.<span style="color: #660066;">Log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Mouseover object: &quot;</span> <span style="color: #339933;">+</span> mouseoverObject.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cosmicmesh.com/wp/?feed=rss2&#038;p=10</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

