<?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>technical architecture.</title>
	<atom:link href="http://buchhofer.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://buchhofer.com</link>
	<description>Maxscript, Architecture, 3D, 3DSMax, Unity3D</description>
	<lastBuildDate>Sat, 14 Jan 2012 14:12:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Configurable Inverse Kinematics in unity at runtime</title>
		<link>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/</link>
		<comments>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 04:49:16 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=330</guid>
		<description><![CDATA[As demo&#8217;d in this video: OR3D tool walk thru the video is a bit on the older side, but it shows the IK fairly well. the system is fairly simple rig that attaches as a script to the IK End Effector, and parses up the hierarchy collecting any bones that are tagged with a certain [...]]]></description>
			<content:encoded><![CDATA[<p>As demo&#8217;d in this video: <a href="http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/" title="What have you Done for me Lately">OR3D tool walk thru</a> the video is a bit on the older side, but it shows the IK fairly well.</p>
<p>the system is fairly simple rig that attaches as a script to the IK End Effector, and parses up the hierarchy collecting any bones that are tagged with a certain empty class (In my case called an EndJoint).</p>
<p>I collect bone joints at runtime after combining and configuring the hierarchy, and pass them into the CCD IK function as an array of unity transforms. the bulk of the code is taken almost directly from Jeff Lander&#8217;s game developer article describing the Cyclic Coordinate Decent (CCD) inverse kinematics algorithm, written in 1998, <a href="http://graphics.cs.cmu.edu/nsp/course/15-464/Spring07/assignments/jlander_gamedev_nov98.pdf" title="Original Article Here"></a></p>
<p>the port can be downloaded from here: <a href="http://dl.dropbox.com/u/8000/IKCCD2D.zip">IKCCD2D.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Architecture &#8211; Revit to Max to Unity</title>
		<link>http://buchhofer.com/2011/12/uni/</link>
		<comments>http://buchhofer.com/2011/12/uni/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 21:42:19 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=318</guid>
		<description><![CDATA[Here is a Revit -> 3dsmax -> Unity project that we worked on earlier this year. the videos below are captured in HD in unity directly from some premade itween paths Exterior axo from Dave Buck on Vimeo. Realtime HD Architecture, Captured in Unity3D from Dave Buck on Vimeo. Basic workflow was to export out [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a Revit -> 3dsmax -> Unity project that we worked on earlier this year.</p>
<p>the videos below are captured in HD in unity directly from some premade itween paths</p>
<p><iframe src="http://player.vimeo.com/video/31943486?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/31943486">Exterior axo</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p><iframe src="http://player.vimeo.com/video/31940365?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/31940365">Realtime HD Architecture, Captured in Unity3D</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Basic workflow was to export out the WorkSets from Revit as individual FBX files<br />
Import them into 3dsmax with the file link manager, usually set to combine objects by material<br />
from there run a set of scripts that collapsed / welded / AutoSmoothed / split meshes that were too large (65k verts is a pain) cleans up the layers, replaces materials, and exports the now unity friendly layers into different FBX&#8217;s for unitys consumption</p>
<p>Inside unity there are a few small steps needed, done mostly with AssetPostProcessors that hook up any external lightmaps that we generated in max, replace/reconnect any materials that are in our standard material library, and attach any components that are supplied in the max user properties fields.</p>
<p>bake the lighting to suit, (In this case, just give us some AO and Sunlight since we needed to be able to turn around revit design changes -> working webplayer overnight with minimal user babysitting.)</p>
<p>this workflow allowed the building owner to &#8216;walk&#8217; around the design very rapidly after it was changed.</p>
<p>There are a few more captures up at http://vimeo.com/vsai/videos/ for anyone interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/12/uni/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity per project compiler options, -unsafe</title>
		<link>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/</link>
		<comments>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 22:31:30 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[csharp]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=316</guid>
		<description><![CDATA[I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged. Slightly awkward, but it turns [...]]]></description>
			<content:encoded><![CDATA[<p>I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged.</p>
<p>Slightly awkward, but it turns out that there is an -unsafe compiler option that needs to be turned on in unity/mono, and that you can do this very easily on a per project basis by adding a file &#8216;smcs.rsp&#8217; to the root of your assets dir, and in there you can add the text &#8216;-unsafe&#8217; to add this to the compiler commandline.</p>
<p>Reference threads: <a href="http://forum.unity3d.com/threads/41592-Setting-Compiler-Options">Setting Compiler Options</a>, <a href="http://forum.unity3d.com/threads/7009-Unsafe-code-in-Unity">Unsafe code in Unity</a>, <a href="http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript">How To: Set Project-Wide #pragma Directives with JavaScript</a></p>
<p>Other apparent uses stated in the threads are setting project wide defines and pragmas</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A google reader feed of tech art blogs</title>
		<link>http://buchhofer.com/2011/11/tech-art-blogs/</link>
		<comments>http://buchhofer.com/2011/11/tech-art-blogs/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 17:53:00 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[TechArt]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=309</guid>
		<description><![CDATA[here&#8217;s a little google reader bundle of (currently) 70 tech art blogs, mostly taken from this thread: http://tech-artists.org/forum/showthread.php?t=1514 and thrown into an easy to follow group at: Google Reader Bundle: Tech Arts 2011  for anyone else thats deeply into this google reader bug, but doesn&#8217;t want to add them all by hand.]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s a little google reader bundle of (currently) 70 tech art blogs, mostly taken from this thread: <a title="Tech arts forum blog listing thread" href="http://tech-artists.org/forum/showthread.php?t=1514" target="_blank">http://tech-artists.org/forum/showthread.php?t=1514</a></p>
<p>and thrown into an easy to follow group at: <a href="http://www.google.com/reader/bundle/user%2F03567438545568037746%2Fbundle%2FTech%20Arts%202011" target="_blank">Google Reader Bundle: Tech Arts 2011 </a></p>
<p>for anyone else thats deeply into this google reader bug, but doesn&#8217;t want to add them all by hand.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/tech-art-blogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArtBreak, MiLB Stadium</title>
		<link>http://buchhofer.com/2011/11/artbreak-milb-stadium/</link>
		<comments>http://buchhofer.com/2011/11/artbreak-milb-stadium/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 19:55:34 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Stills]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=310</guid>
		<description><![CDATA[A little Art break, here&#8217;s a few shots from a recent set of renderings done for a minor league baseball stadium.]]></description>
			<content:encoded><![CDATA[<p>A little Art break, here&#8217;s a few shots from a recent set of renderings done for a minor league baseball stadium.</p>
<p><iframe align="center" src="http://www.flickr.com/slideShow/index.gne?group_id=&#038;user_id=11168326@N03&#038;set_id=72157628115392905/show&#038;text=" frameBorder="0" width="500" height="500" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/artbreak-milb-stadium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ignore file for Mercurial and Unity</title>
		<link>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/</link>
		<comments>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 15:38:38 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=301</guid>
		<description><![CDATA[here&#8217;s a working ignore file for use of Unity and Mercurial simple, but slightly different from the instructions posted in the current docs, so figured i&#8217;d pass it on for anyone else who cares to check it out. placed in a plain text file named .htignore in your project directory syntax: glob *.tmproj *.pidb *.sln *.userprefs [...]]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s a working ignore file for use of Unity and <a href="http://mercurial.selenic.com/" target="_blank">Mercurial</a> simple, but slightly different from the instructions posted in the current docs, so figured i&#8217;d pass it on for anyone else who cares to check it out.</p>
<p>placed in a plain text file named .htignore in your project directory</p>
<pre>syntax: glob

*.tmproj
*.pidb
*.sln
*.userprefs
*.csproj
*.unityproj

AnnotationManager
assetDatabase3
AssetImportState
assetservercachev3
AssetVersioning.db
BuildPlayer.prefs
BuildSettings.asset
EditorSettings.asset
EditorUserBuildSettings.asset
expandedItems
FailedAssetImports.txt
guidmapper
InspectorExpandedItems.asset
MonoManager.asset
ScriptMapper

cache/*
Temp/*
metadata/*
ScriptAssemblies/*
previews/*</pre>
<p><a href="http://hgbook.red-bean.com/read/mercurial-in-daily-use.html">The Mercurial in Daily Use guide</a> seems to be a good list of things that you might wish to do</p>
<p>&nbsp;</p>
<p>Some notes for myself, but might be useful to someone else getting started also.</p>
<p>edit: To start a local serve on my workstation that my laptop can push to, use the command line</p>
<address>hg serve &#8211;config web.push_ssl=No &#8211;config &#8220;web.allow_push=*&#8221;</address>
<p>to pass your changes up from the laptop to the workstation:</p>
<address>hg push http://workstationname:8000</address>
<p>and on the workstation use:</p>
<address>hg update</address>
<p>to get the latest updated file revisions locally..</p>
<p>and you&#8217;re sync&#8217;d. fun times.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What have you done for me lately?</title>
		<link>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/</link>
		<comments>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 17:10:09 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=286</guid>
		<description><![CDATA[I&#8217;ve been working on this tool for a while now, here&#8217;s a quick captured demo of some of the features of my hospital room design application in action. Interactive 3D OR/ICU design tool from Dave Buck on Vimeo. here&#8217;s a current video of my OR/ICU design project, created in unity3d, with fully configurable parametric models [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on this tool for a while now, here&#8217;s a quick captured demo of some of the features of my hospital room design application in action.</p>
<p><iframe src="http://player.vimeo.com/video/24523384?title=0&amp;byline=0&amp;portrait=0" width="400" height="205" frameborder="0"></iframe>
<p><a href="http://vimeo.com/24523384">Interactive 3D OR/ICU design tool</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>here&#8217;s a current video of my OR/ICU design project, created in unity3d, with fully configurable parametric models rigged with both IK and FK, and a tool to quickly draw out any layout of walls, windows and doors to spatially visualize the placement and reach of equipment needed in an operating room space.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fun with Generics and Lists in C#</title>
		<link>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/</link>
		<comments>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/#comments</comments>
		<pubDate>Thu, 19 May 2011 15:58:03 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=264</guid>
		<description><![CDATA[So I&#8217;ve been doing a lot of List juggling lately and have run into a few tidbits that I wish I had learned a few months ago. I figure that is always a good cue to write them down for future reference and for any others who are digging into this C# world headfirst also. [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been doing a lot of List juggling lately and have run into a few tidbits that I wish I had learned a few months ago. I figure that is always a good cue to <strong>write them down</strong> for future reference and for any others who are digging into this C# world headfirst also. this is all sort of an exansion to try and get a concrete example of mike_mac&#8217;s <a href="http://www.michaelgarforth.com/archives/2011/04/delegates-events-lambdas-and-all-things-callbacky-part-2/">lamda</a>/<a href="http://www.michaelgarforth.com/archives/2011/04/delegates-events-lambdas-and-all-things-callbacky-part-1/">delegates/callback</a> articles</p>
<p>Say I have a custom class that I&#8217;m using to store a structured set of data, this time we&#8217;ll play with &#8220;ArmDefs&#8221;. ArmDef&#8217;s just hold a little string and int based data and a list of ArmDef&#8217;s as children, and a second list of GameObjects that contains all of the models for this section of arm for use to serialize to disk, but thats more a story for another time.</p>
<p>Overall this is used to build up a hierarchy that holds the &#8220;contents&#8221; of a runtime modular rig, and handles the Saving/Loading/Reloading.</p>
<p>To work with this I needed to set up a pile of recursive functions to edit the tree at runtime, since I don&#8217;t know the depth of the hierarchy, and rebuild the system as needed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Serializable</span><span style="color: #008000;">&#93;</span>
<span style="color: #008080; font-style: italic;">//Inheriting from ISerializable gives us</span>
<span style="color: #008080; font-style: italic;">//an easy access to Serialization to disk</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ArmDef <span style="color: #008000;">:</span> ISerializable <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span> Children <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>ArmDef<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: #0600FF; font-weight: bold;">public</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> iFile<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;">Name</span><span style="color: #008000;">=</span> iFile<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>ArmDef<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: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddChild<span style="color: #008000;">&#40;</span>ArmDef child<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Children<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>child<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//just wrapping the Add so that we can do &quot;extra&quot;</span>
<span style="color: #008080; font-style: italic;">//stuff here if we want, like add links to parents etc</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>not really building these thru scripts out in the wild but just to build something to work with here.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> ArmDef config <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Base Level&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//add a couple children</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2c&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//add a couple grandchildren</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level3a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level3b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>ok thats all the boring stuff for now! here is a Generic Recursive function that walks down a tree and does &#8216;Action<>&#8216; to all children of &#8216;parent&#8217;. The key here is that the Action<> pretty much rocks. !</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HandleArmDef<span style="color: #008000;">&#40;</span>Action<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span> item, ArmDef parent<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>parent<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><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: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ArmDeft <span style="color: #0600FF; font-weight: bold;">in</span> parent<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HandleArmDef<span style="color: #008000;">&#40;</span>item, ti<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    item<span style="color: #008000;">&#40;</span>parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now the fun begins when you start to chain this stuff together to &#8220;act&#8221; on all children.<br />
we can define that &#8220;Action<ArmDef> item&#8221; in the above function to be something else using some Lambda or Delegate type stuff. (I&#8217;m learning here, those are the reading points for the moment!)</p>
<p>This will go through the hierarchy and remove all children with the Name of &#8220;Level3a&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> toDelete <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Level3a&quot;</span><span style="color: #008000;">;</span>
HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span> <span style="color: #008000;">=</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>child <span style="color: #008000;">=&gt;</span> child<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">!=</span> toDelete<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>, config<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>In another example, i wanted to search the hierarchy and see if there was a certain value anywhere in the hierarchy. easiest way i found was to just quickly build a flattened list and use the Linq &#8220;Any&#8221; function to see if the string was found anywhere in the hierarchy.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> flatList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> flatList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>item<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: #008000;">&#125;</span>, parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">bool</span> isCurrentlyFlat <span style="color: #008000;">=</span> flatList<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Flat&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>in another case, i wanted to insert a new child into the hierarchy as a child of a specific object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">void</span> AddChildAddon<span style="color: #008000;">&#40;</span>ArmDef parent, <span style="color: #6666cc; font-weight: bold;">string</span> addAsChildOf, <span style="color: #6666cc; font-weight: bold;">string</span> newChild<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//for each object 'item' down the hierarchy</span>
    <span style="color: #008080; font-style: italic;">//if the item.Name contains our addAsChildOf string</span>
    <span style="color: #008080; font-style: italic;">//we'll add the newChild as a child to the item.</span>
    HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item<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>addAsChildOf<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span>newChild<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>, parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>there&#8217;s plenty more possibilities of things to do here if I&#8217;ve explained well enough!<br />
More info on <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746">Linq by example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unity: Toying with Scriptable objects and Custom Editors</title>
		<link>http://buchhofer.com/2011/05/scriptable-objects-and-custom-editors/</link>
		<comments>http://buchhofer.com/2011/05/scriptable-objects-and-custom-editors/#comments</comments>
		<pubDate>Wed, 18 May 2011 14:30:36 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=266</guid>
		<description><![CDATA[Expanding on the previous post about Scriptable Objects as an easy way to save/edit some data at runtime, here&#8217;s a small extension looking at an example for a simple custom editor that appears when you select the Scriptable Object we built previously in the Project view. Here&#8217;s what you get clicking on the file previously: [...]]]></description>
			<content:encoded><![CDATA[<p>Expanding on the <a href="http://buchhofer.com/2010/10/unity-toying-with-scriptable-objects/">previous post about Scriptable Objects</a> as an easy way to save/edit some data at runtime, here&#8217;s a small extension looking at an example for a simple custom editor that appears when you select the Scriptable Object we built previously in the Project view.</p>
<p>Here&#8217;s what you get clicking on the file previously:<br />
<img src="http://buchhofer.com/upload/files/unity/Before_Custom_Editor.png" alt="Before Custom Editor" /></p>
<p>And the result with the custom editor:<br />
<img src="http://buchhofer.com/upload/files/unity/CustomEditor.png" alt="with editor" /></p>
<p>Now, this isn&#8217;t the sexiest of examples, but hopefully it helps someone along the way!</p>
<p>First a small addition to the data class, lets add a constructor to it, since our input values are going to be basically the same every time (Mimic &#8216;this&#8217; camera), we&#8217;ll add a secondary constructor for the class that just takes a unity Camera as input and records the values for us.</p>
<p>We&#8217;ll use the same <a href="http://buchhofer.com/2010/10/unity-toying-with-scriptable-objects/">&#8216;CameraLocationHolder.cs&#8217;</a> from below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//File: CameraLocation.cs</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>
<span style="color: #008080; font-style: italic;">//the Serializable attribute is key to what makes the custom class visible in the editor !</span>
<span style="color: #008000;">&#91;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Serializable</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> CameraLocation
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> isOrtho<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> orthoSize<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> fov<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> Vector3 position<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> Quaternion rotation<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//base constructor that builds an empty CamLoc</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> CameraLocation<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        name <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
        isOrtho <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        orthoSize <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
        fov <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> Vector3<span style="color: #008000;">.</span><span style="color: #0000FF;">zero</span><span style="color: #008000;">;</span>
        rotation <span style="color: #008000;">=</span> Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">identity</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008080; font-style: italic;">//build a CamLoc from a supplied camera</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> CameraLocation<span style="color: #008000;">&#40;</span>Camera c<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>c<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;New Camera&quot;</span><span style="color: #008000;">;</span>
            isOrtho <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">isOrthoGraphic</span><span style="color: #008000;">;</span>
            orthoSize <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">orthographicSize</span><span style="color: #008000;">;</span>
            fov <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">fov</span><span style="color: #008000;">;</span>
            position <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">;</span>
            rotation <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And we replace the &#8216;CameraListboxWizard&#8217; that we previously used to edit the Scriptable Object with this (very similar) &#8216;Custom Editor&#8217;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//File: CameraLocationEditor.cs -- Place in an Editor directory under the unity project</span>
&nbsp;
<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;">UnityEditor</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//this limits the editor to running on object that have type CameraLocationHolder</span>
<span style="color: #008000;">&#91;</span>CustomEditor<span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>CameraLocationHolder<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> CameraLocationEditor <span style="color: #008000;">:</span> Editor <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//This will just be a shortcut to the target, ex: the object you clicked on.</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> CameraLocationHolder db<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> Awake<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		db<span style="color: #008000;">=</span><span style="color: #008000;">&#40;</span>CameraLocationHolder<span style="color: #008000;">&#41;</span>target<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnInspectorGUI<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginVertical</span><span style="color: #008000;">&#40;</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>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Add current Camera.main position&quot;</span>, GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">50</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>
			Camera m <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">main</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;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//Add the new camera to the list</span>
                db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> CameraLocation<span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//tell the unity editor that the list has changed and needs to be serialized</span>
                EditorUtility<span style="color: #008000;">.</span><span style="color: #0000FF;">SetDirty</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>			
        <span style="color: #008000;">&#125;</span>
&nbsp;
        GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Space</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        DisplayCurrentCamList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Space</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">EndVertical</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: #6666cc; font-weight: bold;">void</span> DisplayCurrentCamList<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>db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//For each of the cameralocations in the saved scriptable object db</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> db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            EditorGUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginHorizontal</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;">//A text field to rename the camera</span>
            db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">name</span> <span style="color: #008000;">=</span> GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">TextField</span><span style="color: #008000;">&#40;</span>db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">name</span>, GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">200</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//a few simple buttons to juggle the array order</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;UP&quot;</span><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;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    CameraLocation item <span style="color: #008000;">=</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                    db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Insert</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>, item<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: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;DN&quot;</span><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;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">&lt;</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    CameraLocation item <span style="color: #008000;">=</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                    db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Insert</span><span style="color: #008000;">&#40;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, item<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: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Remove&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</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;">//sets the maincamera to be at the selected cameralocation</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MoveTo&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                MoveToView<span style="color: #008000;">&#40;</span>db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</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;">//updates the cameralocation to match up with the Camera.main (Usable at runtime or at edit time)</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">Button</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;UPDATE&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                UpdateView<span style="color: #008000;">&#40;</span>db<span style="color: #008000;">.</span><span style="color: #0000FF;">content</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>	
			EditorUtility<span style="color: #008000;">.</span><span style="color: #0000FF;">SetDirty</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            EditorGUILayout<span style="color: #008000;">.</span><span style="color: #0000FF;">EndHorizontal</span><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>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> MoveToView<span style="color: #008000;">&#40;</span>CameraLocation cam<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		Camera MainCamera <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">mainCamera</span><span style="color: #008000;">;</span>
	    Quaternion currentRotation <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">//if we had an ortho cam, lets just set it there before we start moving.</span>
		MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">orthographicSize</span> <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">orthoSize</span><span style="color: #008000;">;</span>
		MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">isOrthoGraphic</span> <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">isOrtho</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">//a parent check incase we have a 'fpswalker' type script setup also</span>
	    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">parent</span><span style="color: #008000;">&#41;</span>
	    <span style="color: #008000;">&#123;</span>
	        <span style="color: #008080; font-style: italic;">//move the parent object</span>
	        MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">parent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">position</span> <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">;</span>
&nbsp;
	        Vector3 ang <span style="color: #008000;">=</span> currentRotation<span style="color: #008000;">.</span><span style="color: #0000FF;">eulerAngles</span><span style="color: #008000;">;</span>
&nbsp;
	        <span style="color: #008080; font-style: italic;">//rotate the parent object on the Y axis</span>
	        MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">parent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span> <span style="color: #008000;">=</span> Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">Euler</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, ang<span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> , <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	        <span style="color: #008080; font-style: italic;">//rotate the child camera on the X and Z axis</span>
	        MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">localRotation</span> <span style="color: #008000;">=</span> Quaternion<span style="color: #008000;">.</span><span style="color: #0000FF;">Euler</span><span style="color: #008000;">&#40;</span>ang<span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> , <span style="color: #FF0000;">0</span>, ang<span style="color: #008000;">.</span><span style="color: #0000FF;">z</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008000;">&#125;</span>
	    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// there is no FPSWalker parent, so just move the camera itself</span>
	    <span style="color: #008000;">&#123;</span>
	        MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">position</span> <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">;</span>
	        MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span> <span style="color: #008000;">=</span> currentRotation<span style="color: #008000;">;</span>
	    <span style="color: #008000;">&#125;</span>
&nbsp;
	    MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">fov</span> <span style="color: #008000;">=</span> cam<span style="color: #008000;">.</span><span style="color: #0000FF;">fov</span><span style="color: #008000;">;</span>	
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> UpdateView<span style="color: #008000;">&#40;</span>CameraLocation cam<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		Camera MainCamera <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">mainCamera</span><span style="color: #008000;">;</span>
	    cam<span style="color: #008000;">.</span><span style="color: #0000FF;">isOrtho</span> <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">main</span><span style="color: #008000;">.</span><span style="color: #0000FF;">isOrthoGraphic</span><span style="color: #008000;">;</span>
		cam<span style="color: #008000;">.</span><span style="color: #0000FF;">orthoSize</span> <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">main</span><span style="color: #008000;">.</span><span style="color: #0000FF;">orthographicSize</span><span style="color: #008000;">;</span>
		cam<span style="color: #008000;">.</span><span style="color: #0000FF;">position</span> <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">main</span><span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">position</span><span style="color: #008000;">;</span>
    	cam<span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span> <span style="color: #008000;">=</span> Camera<span style="color: #008000;">.</span><span style="color: #0000FF;">main</span><span style="color: #008000;">.</span><span style="color: #0000FF;">transform</span><span style="color: #008000;">.</span><span style="color: #0000FF;">rotation</span><span style="color: #008000;">;</span>
		cam<span style="color: #008000;">.</span><span style="color: #0000FF;">fov</span> <span style="color: #008000;">=</span> MainCamera<span style="color: #008000;">.</span><span style="color: #0000FF;">fov</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>	
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now having built that up, we can simply click on the asset file that we had created previously and see the editor in the Inspector panel, making it easier to handle multiple lists.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/05/scriptable-objects-and-custom-editors/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Some Useful Unity3D resources</title>
		<link>http://buchhofer.com/2011/02/some-useful-unity3d-resources/</link>
		<comments>http://buchhofer.com/2011/02/some-useful-unity3d-resources/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 15:40:30 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=259</guid>
		<description><![CDATA[Since I&#8217;m doing a lot of unity here lately, and starting to lay down some teaching to coworkers, here are a couple useful references for unity3d stuff that aren&#8217;t too commonly thrown out there. http://feedity.com/rss.aspx/unifycommunity-com/UVtQUlVb &#8211; RSS feed that updates when new scripts are added to the community WIKI (And feedity in general is pretty [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m doing a lot of unity here lately, and starting to lay down some teaching to coworkers, here are a couple useful references for unity3d stuff that aren&#8217;t too commonly thrown out there.</p>
<p><a href="http://feedity.com/rss.aspx/unifycommunity-com/UVtQUlVb">http://feedity.com/rss.aspx/unifycommunity-com/UVtQUlVb</a> &#8211; RSS feed that updates when new scripts are added to the community WIKI (And feedity in general is pretty nifty.)</p>
<p><a href="http://www.google.com/cse/home?cx=002470491425767499270:iugs1ezlsfq">http://www.google.com/cse/home?cx=002470491425767499270:iugs1ezlsfq</a> a google custom search engine maintained by some anonymous saint, searches the unity references, answers, forums, and a few other popular blogs.</p>
<p><a href="http://www.google.com/cse/home?cx=001712401338047450041:csfhqk-trfa">http://www.google.com/cse/home?cx=001712401338047450041:csfhqk-trfa</a> a second google CSE that includes MSDN and the wiki among others, for when you need that extra bit of microsoft reference.</p>
<p>Also, don&#8217;t neglect the boys in irc.freenode.net #unity3d, definitely the single most useful resource @ <a href="http://webchat.freenode.net/">http://webchat.freenode.net/</a> or your friendly neighborhood irc client.</p>
<p><em>*Oops! bolger fail. edit to fix the links.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/02/some-useful-unity3d-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

