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

<channel>
	<title>Chris Danielson&#039;s Blog &#187; C#</title>
	<atom:link href="http://www.chrisdanielson.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdanielson.com</link>
	<description>Trials and Tribulations of a Software Developer</description>
	<lastBuildDate>Wed, 14 Sep 2011 00:00:51 +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>Timer Manager for Unity3D</title>
		<link>http://www.chrisdanielson.com/2011/07/09/timer-manager-for-unity3d/</link>
		<comments>http://www.chrisdanielson.com/2011/07/09/timer-manager-for-unity3d/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 15:49:39 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[Unity3D]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Time.time]]></category>
		<category><![CDATA[Timer]]></category>

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

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

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

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

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

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

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

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

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

<p>&nbsp;</p>
<p>/EZ GUI/  &lt;&#8211; default after purchasing and importing from the Unity Asset store.</p>
<p>I sat and read Unity compiling and scoping rules over and over located <a href="http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html" target="_blank">here</a>.  On point 4, the statement reads &#8220;All scripts that are compiled in this step have access to all scripts in the first group (&#8220;Standard Assets&#8221;, &#8220;Pro Standard Assets&#8221; or &#8220;Plugins&#8221;).&#8221;</p>
<p>The solution is simple here.  Take the EZ Gui code located in the &#8220;Plugins&#8221; folder and move it to the root.</p>
<p>/EZ Gui/Plugins/   &lt;&#8211; move this to:</p>
<p>/Plugins/</p>
<p>Done.  It works.  Super simple.</p>
<p><strong>Bonus Play</strong>, Rule of thumb (kind of no brainers really):</p>
<ol>
<li>Place all your plugins in the <strong>/Plugins/</strong> folder.</li>
<li>Place all your C# Code into the <strong>/Standard Assets/</strong> folder.</li>
<li>Place all your JavaScript code into <strong>/Scripts/</strong> or any folder that is NOT named (&#8220;Standard Assets&#8221;, &#8220;Pro Standard Assets&#8221; or &#8220;Plugins&#8221;)</li>
</ol>
<p>This will lead to success and less headaches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2011/04/22/unity-3d-javascript-and-c-scopingcompiling-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net C Sharp Date Range Check Method</title>
		<link>http://www.chrisdanielson.com/2009/07/21/net-c-sharp-date-range-check-method/</link>
		<comments>http://www.chrisdanielson.com/2009/07/21/net-c-sharp-date-range-check-method/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 16:04:50 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Date Range]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=58</guid>
		<description><![CDATA[This function is a trivial example of how to do a basic date range check in .Net. I do a few silly conversions from string to timestamp only to serve as an example. View Code CSHARP/* Assumes the local culture. Does a check to see if the current time is within the range of 7 [...]]]></description>
			<content:encoded><![CDATA[<p>This function is a trivial example of how to do a basic date range check in .Net.  I do a few silly conversions from string to timestamp only to serve as an example.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p58code11'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5811"><td class="code" id="p58code11"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/*
Assumes the local culture.  
Does a check to see if the current time is within the range 
  of 7 AM and 1 PM.  If so, returns true.
*/</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>IsCurrentDateInRange<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;7:00&quot;</span>, <span style="color: #666666;">&quot;13:00&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//The current date is in range.</span>
<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">//The current date is out of range.</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p58code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5812"><td class="code" id="p58code12"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">/*
startTime should be in the format HH:mm such as 09:45
endTime should be in the format HH:mm such as 18:45
The culture is assumed to be the local one which can be 
troubling in applications that extend themselves internationally.
*/</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsCurrentDateInRange<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> startTime, <span style="color: #6666cc; font-weight: bold;">string</span> endTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  DateTime dtNow <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
  DateTime dtStart, dtEnd<span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> hour <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, minute <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> strDt <span style="color: #008000;">=</span> startTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">':'</span> <span style="color: #008000;">&#125;</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>strDt<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
     Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>strDt<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> hour<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>strDt<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> minute<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     dtStart <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DateTime<span style="color: #008000;">&#40;</span>dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Year</span>, dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Month</span>, dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Day</span>, hour, minute, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">else</span>
  <span style="color: #008000;">&#123;</span>
     <span style="color: #008080; font-style: italic;">//TODO: log an error in formatting.</span>
     <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>               
&nbsp;
  strDt <span style="color: #008000;">=</span> endTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">':'</span> <span style="color: #008000;">&#125;</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>strDt<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
     hour <span style="color: #008000;">=</span> minute <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
     Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>strDt<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> hour<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>strDt<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> minute<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     dtEnd <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DateTime<span style="color: #008000;">&#40;</span>dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Year</span>, dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Month</span>, dtNow<span style="color: #008000;">.</span><span style="color: #0000FF;">Day</span>, hour, minute, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">else</span>
  <span style="color: #008000;">&#123;</span>
     <span style="color: #008080; font-style: italic;">//TODO: log an error in formatting.</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  TimeSpan tsEndDiff <span style="color: #008000;">=</span> dtEnd <span style="color: #008000;">-</span> dtNow<span style="color: #008000;">;</span>
  TimeSpan tsStartDiff <span style="color: #008000;">=</span> dtNow <span style="color: #008000;">-</span> dtStart<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>tsStartDiff<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&amp;&amp;</span> tsEndDiff<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</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;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">else</span> 
     <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2009/07/21/net-c-sharp-date-range-check-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

