tag:blogger.com,1999:blog-80777261250071401372024-03-12T22:07:50.277-07:00Mobile Software Development.Side projects, and non-profit work. Always in search of the indefinable hack.Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.comBlogger76125tag:blogger.com,1999:blog-8077726125007140137.post-83984169049369467132013-10-19T19:31:00.001-07:002013-10-19T19:32:57.674-07:00Azure Deployments.Eventually, a project makes it to End Game.. as we call it. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwYSL86IC8UqWhzI2eaqvP6H9UUKDqBM-BjNVdNSMD68rIjnFLJtj1HTf2ozqp5s31JdO9gbNlYjfYv6w4jOUOD_ZKBhdOTwdrC3akIpgQ7HOTRSEwml7mZN49ufbvGqk8T0JZ4COz887F/s1600/Certificate.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwYSL86IC8UqWhzI2eaqvP6H9UUKDqBM-BjNVdNSMD68rIjnFLJtj1HTf2ozqp5s31JdO9gbNlYjfYv6w4jOUOD_ZKBhdOTwdrC3akIpgQ7HOTRSEwml7mZN49ufbvGqk8T0JZ4COz887F/s640/Certificate.PNG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNn2X0hAVhpbYg-fH5BVrpt_WdMEnozTESfaAdhnOWsHEs_McF-gG0BdGJzDCRl2JBGFJZ-zGtSJBzmca9_1x-01q5GnyiJW9cZoxaiweHCyqSBAsCPrS1UpQqceWSDaa42Aze5BZoqIoi/s1600/Endpoint.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNn2X0hAVhpbYg-fH5BVrpt_WdMEnozTESfaAdhnOWsHEs_McF-gG0BdGJzDCRl2JBGFJZ-zGtSJBzmca9_1x-01q5GnyiJW9cZoxaiweHCyqSBAsCPrS1UpQqceWSDaa42Aze5BZoqIoi/s640/Endpoint.PNG" width="640" /></a></div>
You start having customers. Right? If you've been working in Azure, that means, you'll need at least a few things.<br />
<br />
#1). You'll need an "A Record" in DNS.. pointing to your azure deployment url's IP. This will make your site.. resolve to the IP address for your load balancer.<br />
<br />
#2) You'll need to make a CName record, for "www". So that www.yourdomaingoeshere.com will resolve for your customers. Use your azure production deployment URL. <br />
<br />
#3), You'll need to get your https certificate. Make sure to import it, with the private key.. and then export it back out. Upload that cert to your azure deployment. Attach it in your project via the screen shots above.. by right clicking on your web role. <br />
<br />
Very quickly, you'll realize: Cloud work is just like regular development. There isn't any magic here.<br />
<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-50436636385108291482013-09-12T21:09:00.002-07:002013-09-13T17:33:15.440-07:00Creating and using sliding menus in Xamarin.AndroidI needed a stylish way to navigate menu options in my app and by piecing together different examples from documentation and online forums I was able to get my menu to slide forward when traversing deeper into my menus, and slide backwards when backing up.<br />
<br />
In my Menu layout I specify a ViewFlipper as the parent view, and then underneath that I list all of the views I'll be sliding between. I've used TableLayouts as my child views since I think they work well for buttons, but you can use LinearLayouts or whatever you prefer. Make sure you give each view a unique ID and then place the file in the <b>Resources\layout</b> folder of your project.<br />
<br />
<b style="font-family: 'Courier New'; font-size: 13px; line-height: 20.796875px;">MySlidingMenu.axml:</b><br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><?<span class="type">xml</span> version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?>
<<span class="type">ViewFlipper</span> xmlns:android=<span class="string">"http://schemas.android.com/apk/res/android"</span>
android:id=<span class="string">"@+id/viewFlipper"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"fill_parent"</span>>
<<span class="type">TableLayout</span>
android:id=<span class="string">"@+id/tlMainMenu"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span>>
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnSubmenu1"</span>
android:text=<span class="string">"To Submenu1"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnSubmenu2"</span>
android:text=<span class="string">"To Submenu2"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
</<span class="type">TableLayout</span>>
<<span class="type">TableLayout</span>
android:id=<span class="string">"@+id/tlSubmenu1"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span>>
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnAction1"</span>
android:text=<span class="string">"Action One"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnCancel1"</span>
android:text=<span class="string">"Cancel"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
</<span class="type">TableLayout</span>>
<<span class="type">TableLayout</span>
android:id=<span class="string">"@+id/tlSubmenu2"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span>>
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnAction2"</span>
android:text=<span class="string">"Action Two"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnSubSubmenu"</span>
android:text=<span class="string">"To Sub-Submenu"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnCancel2"</span>
android:text=<span class="string">"Cancel"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
</<span class="type">TableLayout</span>>
<<span class="type">TableLayout</span>
android:id=<span class="string">"@+id/tlSubSubmenu"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span>>
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnAction3"</span>
android:text=<span class="string">"Action Three"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
<<span class="type">Button</span>
android:id=<span class="string">"@+id/btnCancel3"</span>
android:text=<span class="string">"Cancel"</span>
android:minWidth=<span class="string">"25px"</span>
android:minHeight=<span class="string">"25px"</span>
android:layout_width=<span class="string">"fill_parent"</span>
android:layout_height=<span class="string">"wrap_content"</span> />
</<span class="type">TableLayout</span>>
</<span class="type">ViewFlipper</span>><!--[if IE]>
<![endif]--></pre>
</div>
Next, you'll need four animation XML files that tell the screen how to transition. Create these four files and then place them in the <b>Resources\anim\</b> folder in your project. You will probably need to create the anim folder if it doesn't already exist.<br />
<br />
<b>slide_in_left.xml:</b><br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><?<span class="type">xml</span> version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span> ?>
<<span class="keyword">set</span> xmlns:android=<span class="string">"http://schemas.android.com/apk/res/android"</span>>
<<span class="type">translate</span> android:fromXDelta=<span class="string">"-50%p"</span> android:toXDelta=<span class="string">"0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span>/>
<<span class="type">alpha</span> android:fromAlpha=<span class="string">"0.0"</span> android:toAlpha=<span class="string">"1.0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span> />
</<span class="keyword">set</span>></pre>
</div>
<b>slide_in_right.xml:</b><br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><?<span class="type">xml</span> version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?>
<<span class="keyword">set</span> xmlns:android=<span class="string">"http://schemas.android.com/apk/res/android"</span>>
<<span class="type">translate</span> android:fromXDelta=<span class="string">"50%p"</span> android:toXDelta=<span class="string">"0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span>/>
<<span class="type">alpha</span> android:fromAlpha=<span class="string">"0.0"</span> android:toAlpha=<span class="string">"1.0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span> />
</<span class="keyword">set</span>></pre>
</div>
<b>slide_out_left.xml:</b><br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><?<span class="type">xml</span> version=<span class="string">"1.0"</span> encoding=<span class="string">"utf-8"</span>?>
<<span class="keyword">set</span> xmlns:android=<span class="string">"http://schemas.android.com/apk/res/android"</span>>
<<span class="type">translate</span> android:fromXDelta=<span class="string">"0"</span> android:toXDelta=<span class="string">"-50%p"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span>/>
<<span class="type">alpha</span> android:fromAlpha=<span class="string">"1.0"</span> android:toAlpha=<span class="string">"0.0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span> />
</<span class="keyword">set</span>></pre>
</div>
<b>slide_out_right.xml:</b><br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><?<span class="type">xml</span> version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span> ?>
<<span class="keyword">set</span> xmlns:android=<span class="string">"http://schemas.android.com/apk/res/android"</span>>
<<span class="type">translate</span> android:fromXDelta=<span class="string">"0"</span> android:toXDelta=<span class="string">"50%p"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span>/>
<<span class="type">alpha</span> android:fromAlpha=<span class="string">"1.0"</span> android:toAlpha=<span class="string">"0.0"</span>
android:duration=<span class="string">"@android:integer/config_mediumAnimTime"</span> />
</<span class="keyword">set</span>></pre>
</div>
Now you have all of the XML files, the last thing you need is the code added to your activity. I suggest declaring the variables that hold the ViewFlipper, Views and Buttons at the top of your Activity like so:<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">private</span> <span class="type">ViewFlipper</span> vf;
<span class="keyword">private</span> <span class="type">TableLayout</span> tlMainMenu;
<span class="keyword">private</span> <span class="type">TableLayout</span> tlSubmenu1;
<span class="keyword">private</span> <span class="type">TableLayout</span> tlSubmenu2;
<span class="keyword">private</span> <span class="type">TableLayout</span> tlSubSubmenu;
<span class="keyword">private</span> <span class="type">Button</span> btnSubmenu1;
<span class="keyword">private</span> <span class="type">Button</span> btnSubmenu2;
<span class="keyword">private</span> <span class="type">Button</span> btnSubSubmenu;
<span class="keyword">private</span> <span class="type">Button</span> btnCancel1;
<span class="keyword">private</span> <span class="type">Button</span> btnCancel2;
<span class="keyword">private</span> <span class="type">Button</span> btnCancel3;</pre>
</div>
I didn't include the Action buttons because those are just placeholders for whatever it is you want to display on your own menu so I don't need to show you how to configure those. Next, the following goes in your OnCreate method:<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;">SetContentView (Resource.<span class="type">Layout</span>.MySlidingMenu);
vf = FindViewById<ViewFlipper> (Resource.Id.viewFlipper);
tlMainMenu = FindViewById<<span class="type">TableLayout</span>> (Resource.Id.tlMainMenu);
tlSubmenu1 = FindViewById<<span class="type">TableLayout</span>> (Resource.Id.tlSubmenu1);
tlSubmenu2 = FindViewById<<span class="type">TableLayout</span>> (Resource.Id.tlSubmenu2);
tlSubSubmenu = FindViewById<<span class="type">TableLayout</span>> (Resource.Id.tlSubSubmenu);
btnSubmenu1 = FindViewById<<span class="type">Button</span>> (Resource.Id.btnSubmenu1);
btnSubmenu2 = FindViewById<<span class="type">Button</span>> (Resource.Id.btnSubmenu2);
btnSubSubmenu = FindViewById<<span class="type">Button</span>> (Resource.Id.btnSubSubmenu);
btnCancel1 = FindViewById<<span class="type">Button</span>> (Resource.Id.btnCancel1);
btnCancel2 = FindViewById<<span class="type">Button</span>> (Resource.Id.btnCancel2);
btnCancel3 = FindViewById<<span class="type">Button</span>> (Resource.Id.btnCancel3);
btnSubmenu1.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_right);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_left);
vf.DisplayedChild = vf.IndexOfChild(tlSubmenu1);
};
btnSubmenu2.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_right);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_left);
vf.DisplayedChild = vf.IndexOfChild(tlSubmenu2);
};
btnSubmenu3.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_right);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_left);
vf.DisplayedChild = vf.IndexOfChild(tlSubmenu3);
};
btnSubSubmenu.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_right);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_left);
vf.DisplayedChild = vf.IndexOfChild(tlSubSubmenu);
};
btnCancel1.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_left);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_right);
vf.DisplayedChild = vf.IndexOfChild(tlMainMenu);
};
btnCancel2.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_left);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_right);
vf.DisplayedChild = vf.IndexOfChild(tlMainMenu);
};
btnCancel3.Click += <span class="keyword">delegate</span> {
vf.SetInAnimation(<span class="keyword">this</span>, Resource.Animation.slide_in_left);
vf.SetOutAnimation(<span class="keyword">this</span>, Resource.Animation.slide_out_right);
vf.DisplayedChild = vf.IndexOfChild(tlSubmenu2);
};</pre>
</div>
Notice that the submenu buttons all have an InAnimation of slide_in_right and an OutAnimation of slide_out_left, while the cancel buttons all have an InAnimation of slide_in_left and an OutAnimation of slide_out_right. This gives the illusion that submenus are further to the right, and your parents menus are to the left via the sliding animation.<br />
<br />
Lastly, you'll want to add support for using the back button to navigate your menus. Since the back button should do something different based on where you are at on the menu I suggest using the following method to capture the use of the back key, determine where you are and simulate the click of the cancel/back button on that portion of the menu. Also, this is the reason for declaring the ViewFinder/Views/Buttons outside of the OnCreate method, because if we declared them locally we'd have to re-declare them for this method:<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">bool</span> OnKeyDown (Android<span class="type">ViewsKeycode</span> keyCode, Android<span class="type">ViewsKeyEvent</span> e)
{
<span class="keyword">if</span> (keyCode == Keycode.Back) {
<span class="keyword">if</span> (vf.DisplayedChild == vf.IndexOfChild (tlSubmenu2))
btnCancel1.PerformClick ();
<span class="keyword">else</span> <span class="keyword">if</span> (vf.DisplayedChild == vf.IndexOfChild (tlSubmenu3))
btnCancel2.PerformClick ();
<span class="keyword">else</span> <span class="keyword">if</span> (vf.DisplayedChild == vf.IndexOfChild (tlSubSubmenu))
btnCancel3.PerformClick ();
<span class="keyword">return</span> <span class="keyword">true</span>;
}
<span class="keyword">else</span>
<span class="keyword">return</span> base.OnKeyDown (keyCode, e);
}<!--[if IE]>
<![endif]--></pre>
</div>
That's it! You now have everything you need to create the illusion of sliding menus, and the ability to traverse them at will. Please leave me a comment if this was helpful for you, or if you have any questions. Thank you!Jaredhttp://www.blogger.com/profile/00323032321674321584noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-47142717720172247582013-08-03T08:33:00.002-07:002013-08-03T09:09:53.832-07:00Print Hub Sales.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQG9W9KfqZNcn5_2kG7Rt2-01GWGUlMzjU2VrcvY21uKnvkb2jnRbflQ-vHRMKZo2sAcbOCijt0fkFKHg86aje9qtTw_FI0oQd3k6tUVe6hkcSkeEIxVkZ0FB_F8H9d1mUJ358zYRQVCQ_/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="284" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQG9W9KfqZNcn5_2kG7Rt2-01GWGUlMzjU2VrcvY21uKnvkb2jnRbflQ-vHRMKZo2sAcbOCijt0fkFKHg86aje9qtTw_FI0oQd3k6tUVe6hkcSkeEIxVkZ0FB_F8H9d1mUJ358zYRQVCQ_/s640/Capture.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
This week I've been ranking pretty regularly on iPad sales, and a bit on iPhone. Not a high rank, obviously.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Jared is saying he will make a support web site. Since, I've been pretty bad on support for the app, and we are making an Android version.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
At least 3/4th's of the issues keeping the app from the Supported Apps list should be gone now, and I'm hoping to get listed soon.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Today, I'm hoping to get the "basic" versus "advanced" printing capability in.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Anyways, enough of me being crazy or posting. Gotta get to "work"</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcrnCF2sEhPJaNdMU61qaIO3caCxvVnNYI_apiVcA8Anp1RftdsIJhN6mqDA7wf-xMYad6JqO1KVwhjvGUslZl_e47yJeK8tZfx35YVzChcziE31x0Lr6AHL62OZhzBsHaDnIxBF1Jbx1v/s1600/IPhone.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="329" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcrnCF2sEhPJaNdMU61qaIO3caCxvVnNYI_apiVcA8Anp1RftdsIJhN6mqDA7wf-xMYad6JqO1KVwhjvGUslZl_e47yJeK8tZfx35YVzChcziE31x0Lr6AHL62OZhzBsHaDnIxBF1Jbx1v/s640/IPhone.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The evidence of how rough it is on the ITunes store. Keep this in mind, even if you have a great app, you are still dependent on search terms in iTunes. I'm not claiming my app is even great.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr9rGQiN8ewGUhWrijx8pbILIbBkbRz0LvHAMFaToToWMwRhn3z-e06KIIp0kO3QDIWZPV-pFdQr1XlOx33xn8lvpN0jmoZr4VSqyxuocgXav9HvjoZoD0S9tMELQMzvMWwzUVmMgnJRrc/s1600/IPad.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr9rGQiN8ewGUhWrijx8pbILIbBkbRz0LvHAMFaToToWMwRhn3z-e06KIIp0kO3QDIWZPV-pFdQr1XlOx33xn8lvpN0jmoZr4VSqyxuocgXav9HvjoZoD0S9tMELQMzvMWwzUVmMgnJRrc/s640/IPad.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">How many "sales" does it take to rank on iPad? I don' t know. I just know that the threshold is a lot lower than ranking in iPhone. I've shown up on the iPad ranking, a number of times. iPhone? Meh. App Annie provided these graphs, and would give me more graphs, if I was interested in paying a large amount of money per year, to get real intelligence on the store environment. (Sorry App Annie, I can't yet, I'm still making coffee money from my IOS App).</td></tr>
</tbody></table>
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-76715320443294267792013-07-28T08:57:00.000-07:002013-07-28T08:57:51.065-07:00Grid Based Movement in UnityIf you have played old school games like Dungeon Master, Eye of the Beholder, the early Lands of Lore and Wizardry series or even more recent games like Legend of Grimrock, then you know what Grid Based Movement is. This is my implementation of grid based movement using <a href="https://www.assetstore.unity3d.com/#/content/4004" target="_blank">Grid Framework by HiPhish</a>. Feel free to use your own grid system.<br />
<br />
<a href="http://www.youtube.com/watch?v=rH3xkNdFRe0&feature=youtu.be" target="_blank">See script in action</a><br />
<br />
Setup a scene and if you are using Grid Framework create a new grid.<br />
Add an empty gameobject to represent the player. I also make the camera a child of this object and set the camera position to 0,0,0 so it is always looking forward from the centre of the player.<br />
<br />
Add this script to the player object. If you are not using Grid Framework, you will need to change/remove the GFGrid variable and the first line in the awake method. All this line currently does is move the player to 0,0,0. In a later post the grid will be used to determine if a move is valid or not. You will also need to either create the inputs I have specified in the script or update the script to match your own. I use w,s,a,d for forwards, backward, stepleft, stepright and q and e for turning.<br />
<br />
<span style="font-size: xx-small;">public GFGrid Grid;//Grid the Player is attached to.</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public float StepSpeed = 0.5f; //how fast in seconds each step or turn takes to complete<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Vector3 CurrentGridPosition = new Vector3(0,0,0); //3d position in Grid</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public string CurrentDirection; //Direction Player is facing (n,s,e,w)</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>float timer = 0; //used to disable turn left and turn right inputs when player is already turning</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>bool enableRotation = true;<span class="Apple-tab-span" style="white-space: pre;"> </span>//used to disable turn left and turn right inputs when player is already turning</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 intendedPosition;//Before player is moved, the position the player will end up at is stored here</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Is used to check that the move is valid and also used to disable move inputs</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//when player is already moving</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Awake()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>this.transform.position = Grid.GridToWorld(CurrentGridPosition); //move player to default position/grid origin</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition; //no movement has occured yet, so intended position is set to current position</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "n"; //TODO: default direction is calculated from CurrentGridPosition.</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Start()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//sets timer to match time it takes to make one step or turn</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>timer = StepSpeed; </span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void MoveTo(Vector3 position)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Move Player to position over time</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>LeanTween.move(gameObject, position, StepSpeed);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void TurnPlayer(Vector3 position)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Turn Player to new rotation over time</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>LeanTween.rotate(gameObject, position, StepSpeed);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#region Movement</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void MoveForward()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// calculate intended position. Get current direction and add one step forward</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch(CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,-1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(-1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//TODO: Check move is valid, if not, break</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveTo(Grid.GridToWorld(intendedPosition));<span class="Apple-tab-span" style="white-space: pre;"> </span>//Actually move player<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentGridPosition = intendedPosition; //Update CurrentGridPosition</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void MoveBackward()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// calculate intended position. Get current direction and add one step backward</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch(CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,-1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(-1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//TODO: Check move is valid</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveTo(Grid.GridToWorld(intendedPosition));<span class="Apple-tab-span" style="white-space: pre;"> </span>//Actually move player<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentGridPosition = intendedPosition; //Update CurrentGridPosition<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void StepLeft()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// calculate intended position. Get current direction and add one step left</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch(CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(-1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,-1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//TODO: Check move is valid</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveTo(Grid.GridToWorld(intendedPosition));//Actually move player<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentGridPosition = intendedPosition; //Update CurrentGridPosition<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void StepRight()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// calculate intended position. Get current direction and add one step right</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch(CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,-1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(-1,0,0);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>intendedPosition = CurrentGridPosition + new Vector3(0,0,1);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//TODO: Check move is valid</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveTo(Grid.GridToWorld(intendedPosition));<span class="Apple-tab-span" style="white-space: pre;"> </span>//Actually move player<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentGridPosition = intendedPosition; //Update CurrentGridPosition<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void TurnLeft()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//check if player is already turning</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(!enableRotation)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>enableRotation = false; //disable turn inputs</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 intendedPosition = transform.localEulerAngles + new Vector3(0,-90,0);//calculate intended position after turning </span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TurnPlayer(intendedPosition); //actually turn player</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Because player has turned, player direction has changed. This updates to correct value</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch (CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "w";<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "n";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "e";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "s";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void TurnRight()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//check if player is already turning</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(!enableRotation)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>enableRotation = false; //disable turn inputs</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 intendedPosition = transform.localEulerAngles + new Vector3(0,90,0);//calculate intended position after turning </span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TurnPlayer(intendedPosition); //actually turn player</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Because player has turned, player direction has changed. This updates to correct value</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>switch (CurrentDirection.ToLower())</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>default:</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "n":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "e";<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "e":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "s";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "s":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "w";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>case "w":</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CurrentDirection = "n";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>break;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#endregion<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Update()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//checks if player is moving, if not enables movement inputs</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(CurrentGridPosition == intendedPosition)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("Forward"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveForward();<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("Backward"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MoveBackward();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("StepLeft"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>StepLeft();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("StepRight"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>StepRight();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//checks if player is turning, if not enables turning inputs</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(enableRotation)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("TurnLeft"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TurnLeft();<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButtonDown("TurnRight"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TurnRight();<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//if player is turning, checks if turn has finished.</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(!enableRotation)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>timer -= Time.deltaTime;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(timer < 0)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>enableRotation = true;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>timer = StepSpeed;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-15025866295473883222013-07-22T14:57:00.002-07:002013-07-22T14:58:27.605-07:00Using Grid Framework to build a platformerThe last months have been insanely busy. I may have overdone it on my still healing foot, and so today I find myself at home and forced to rest. It sounds like a perfect opportunity to make a game AND a tutorial!!<br />
<br />
I enlisted the help of my 4 year old daughter in deciding what kind of game to make. She wanted a game where Happy Face has to collect a crown. Happy Face will encounter a witch, a Mother Spider and her Baby Spiders. So, I am going to be building a single screen platformer. By single screen, I mean that what is displayed is the entire game, no scrolling, no extra rooms. At least not yet :)<br />
<br />
I have also just purchased <a href="https://www.assetstore.unity3d.com/#/content/4004">Grid Framework</a> and this is a great time to see what it can do.<br />
<br />
First thing is to create the actual grid. GameObject > Create Grid > Rectangular Grid will do the trick. Hexagonal Grids and Polar Grids are also available. Hexagonal grids will be perfect for deep strategy games. A polar grid is a circular grid, and the only use I can think of for it right now is as some kind of radar or motion sensor display.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVtAVsyZQ72l0_QwTPMkkqDUGuuh9_6YpFYXNJo4lmAgX6Vsu3chRV2eRHan4BadjhAvtyzN6bCAmfzOnxFc6hGomncdfH0JuD7fm4Y4GAfI-G8SSDRVwbwcYBt_phdz2xSIvZtWMujCI/s1600/defaultgrid.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="157" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVtAVsyZQ72l0_QwTPMkkqDUGuuh9_6YpFYXNJo4lmAgX6Vsu3chRV2eRHan4BadjhAvtyzN6bCAmfzOnxFc6hGomncdfH0JuD7fm4Y4GAfI-G8SSDRVwbwcYBt_phdz2xSIvZtWMujCI/s400/defaultgrid.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Grid with Default Settings</td></tr>
</tbody></table>
<br />
Now to shape the grid to fit our game world. For this game, I need a grid twice as wide as it is tall. I dont care about depth, so I set the Z to 0. X is 12 and Y is 5. Your dimensions may vary.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1rD46B9IkVlQfG5wlV0Tv0V02bZ4PKMKQ_U54XRKckL1vOfmHreUN0o8klH1ok9iTalwhVtEnJEz4Uypn7fwerqlUjz1D3xZBuvCKo-buBTJRrC3VGbKOv-dhYgdHVmnoh_h1UCxLV-s/s1600/2dgrid.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1rD46B9IkVlQfG5wlV0Tv0V02bZ4PKMKQ_U54XRKckL1vOfmHreUN0o8klH1ok9iTalwhVtEnJEz4Uypn7fwerqlUjz1D3xZBuvCKo-buBTJRrC3VGbKOv-dhYgdHVmnoh_h1UCxLV-s/s400/2dgrid.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">2D Grid</td></tr>
</tbody></table>
I should now be able to use this grid to create a basic level layout. Open up the Grid Align Panel (Window > Grid Align Panel) and turn on AutoSnapping. Make sure you have assigned your grid to the panel too.<br />
Create a basic cube (GameObject > Create Other > Cube) and drag it onto the grid. You will see that it is perfectly aligned, and moving it around will snap it to the grid. Place a bunch of these and you have a level.<br />
I will create a boundary first, to stop an eager 4 year old from jumping off the world into oblivion.<br />
<br />
Once the boundary is created, lets get Happy Face into the game and moving. All artwork has been provided by my daughter :)<br />
<br />
For the sake of simplicity, I am faking a 2D sprite by creating a cube with a transparent diffuse and her painting attached. Also add a character controller. This will replace the default box collider.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwZEklj461N8UEfPjqUgNk6XI571uMJJXNydNH5LyZgztBC2EWhyZHQGhRmnsB_TxOWHVa6YB1oshftOoQfA_jqGBe-jHc0ztkPgK2ySGEjLRkD4GAJ6W6fNUJVp4zrwx9Txpu-I5J3D8/s1600/fake2dSprite.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="211" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwZEklj461N8UEfPjqUgNk6XI571uMJJXNydNH5LyZgztBC2EWhyZHQGhRmnsB_TxOWHVa6YB1oshftOoQfA_jqGBe-jHc0ztkPgK2ySGEjLRkD4GAJ6W6fNUJVp4zrwx9Txpu-I5J3D8/s400/fake2dSprite.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fake2D Sprite settings</td></tr>
</tbody></table>
Lets add some simple scripting to get this happy fella moving. Attach this script to your 'sprite'<br />
<br />
<span style="font-size: xx-small;">float moveSpeed = 3.0f;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>float jumpSpeed = 8.0f;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>float gravity = 10.0f;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 moveDirection = Vector3.zero;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>// Update is called once per frame<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>void Update ()<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>{<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//handle input and move character controller;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>CharacterController cc = GetComponent<CharacterController>();<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>if(cc.isGrounded)<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); // Gets Horizontal movement. Edit > Project Settings > Input to find out more about Axis.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection = transform.TransformDirection(moveDirection);<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection *= moveSpeed;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>if(Input.GetButton("Jump") && cc.isGrounded)<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>{<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection.y = jumpSpeed;<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection.y -= gravity * Time.deltaTime;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>cc.Move(moveDirection * Time.deltaTime);</span><br />
<br />
Test it out and you should be able to walk your sprite back and forth without it falling out of the world. Lets add a few platforms and the crown. The grid will allow me to easily line up platforms, and with the current gravity settings on the player I know that the sprite can jump just over 3 grid squares high, so I need a maximum distance of 3 squares floor to floor for the character to be able to make the jump.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMQB8DO4OtDaDYZAjHPEjHcaz1Gbh74Ktilui4lc2SMhhsZnCf_2dfKRqH-ohSIuC0-VOm8xRwAhd4a6t8LYnPpO-jtpcgRNtM_NaOPvmV8N8D5Px8FN9ZheOy9vyg1n9CJQIvJUrrIrY/s1600/level.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMQB8DO4OtDaDYZAjHPEjHcaz1Gbh74Ktilui4lc2SMhhsZnCf_2dfKRqH-ohSIuC0-VOm8xRwAhd4a6t8LYnPpO-jtpcgRNtM_NaOPvmV8N8D5Px8FN9ZheOy9vyg1n9CJQIvJUrrIrY/s400/level.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Basic level</td></tr>
</tbody></table>
<br />
<br />
Lets add a quick script to the crown to allow it be 'collected'.<br />
When the player touches the crown, the following needs to happen:<br />
Record that the crown has been collected<br />
Play a 'pick up' sound<br />
'Destroy' the game object.<br />
<br />
To make a trigger on the crown object, I select it and set 'Is Trigger' to true on the box collider. I also have an empty object in my scene called 'Game Manager', with a game manager script attached. I'll use this to track any information that the entire game needs to know about. Right now it just consists of a single public bool to track if the crown has been collected or not. Set it's default value to false (uncollected).<br />
<br />
My crown script. I used the free tool <a href="http://www.drpetter.se/project_sfxr.html">SFXR</a> to generate my sound fx.<br />
<br />
<span style="font-size: xx-small;">using UnityEngine;</span><br />
<span style="font-size: xx-small;">using System.Collections;</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">public class Crown : MonoBehaviour {</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void OnTriggerEnter(Collider other) //fired when an object ENTERS the trigger zone</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Record that crown has been collected</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GameManager gmScript = GameObject.Find("Game Manager").GetComponent<GameManager>();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>gmScript.CrownCollected = true;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Play Pick up sound</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>audio.Play();</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Destroy Object</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Destroy(GameObject.Find("Crown"), 0.3f);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;">}</span><br />
<br />
Test and you should have a playable level with a pick upable crown. Whats missing? Friends, of course!!<br />
<br />
Next part coming soon....<br />
<br />
<br />Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-44728291054980572402013-07-21T20:41:00.001-07:002013-07-21T20:41:56.646-07:00The battle with OAuth.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNeTjY1ZAVfH-JSk5j4hdOc-NVuzAYd6iS-Ggk6pyRTcgnW6ZhWUNxXHtLISqxHq2EqVwYmgel2G17LnPEavVVgSP6XIr002zfC6lkNjpx0Ht9QfFRwkj6vPkTKcB6uaEa8xb7tMPf1cg-/s1600/iOS+Simulator+Screen+shot+Jul+21,+2013+7.27.05+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNeTjY1ZAVfH-JSk5j4hdOc-NVuzAYd6iS-Ggk6pyRTcgnW6ZhWUNxXHtLISqxHq2EqVwYmgel2G17LnPEavVVgSP6XIr002zfC6lkNjpx0Ht9QfFRwkj6vPkTKcB6uaEa8xb7tMPf1cg-/s400/iOS+Simulator+Screen+shot+Jul+21,+2013+7.27.05+PM.png" width="266" /></a></div>
I've been battling OAuth, all day, today. In Xamarin.Auth. The fundamental problem is that it didn't support JSON responses.. so I pulled down the GitHub repo.. started dinking with it.<br />
<br />
I eventually got it to work. Took quite a bit of fighting. I'm looking forward to using it here soon, for the Xamarin.IOS app and for the Xamarin.Android app.Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-58214061776838504452013-07-18T20:44:00.002-07:002013-07-18T20:44:10.438-07:00Using Intents in Xamarin to catch "Send to" and "Open with" file promptsIn Xamarin for Android you don't directly edit the AndroidManifest.xml file which means you need to create code that will generate the necessary portions of the manifest which direct your application to make itself available to handle incoming file hand-offs. This is done using an IntentFilter which you place at the top of the class for the activity which you want to handle the incoming data. In my case, I chose a neutral splashscreen as the loading activity so that the user will see my app's loading screen while I determine and load the true activity that will be handling the file.<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">namespace</span> MyApp
{
[<span class="type">Activity</span> (<span class="type">Label</span>=<span class="string">"MyAppName"</span>, MainLauncher = <span class="keyword">true</span>, <span class="type">Icon</span>=<span class="string">"@drawable/icon"</span>, Theme = <span class="string">"@style/ThemeBase.Splash"</span>, NoHistory = <span class="keyword">true</span>)]
[IntentFilter (<span class="keyword">new</span>[]{<span class="type">Intent</span>.ActionView},
Categories=<span class="keyword">new</span>[]{<span class="type">Intent</span>.ActionDefault, <span class="type">Intent</span>.CategoryBrowsable, <span class="type">Intent</span>.ActionSend, <span class="type">Intent</span>.ActionSendMultiple},
DataScheme=<span class="string">"mimetype"</span>,
DataPathPattern=<span class="string">"*/*"</span>,
DataHost=<span class="string">"*.*"</span>)]
<span class="keyword">public</span> <span class="keyword">class</span> <span class="type">SplashActivity</span> : <span class="type">Activity</span>
{
<span class="keyword">protected</span> <span class="keyword">override</span> <span class="keyword">void</span> OnCreate (<span class="type">Bundle</span> bundle)
{
<span class="keyword">base</span>.OnCreate (bundle);
<span class="type">Intent</span> intent = <span class="type">Intent</span>;
<span class="type">String</span> action = intent.<span class="type">Action</span>;
<span class="type">String</span> type = intent.<span class="type">Type</span>;
<span class="keyword">if</span> (<span class="type">Intent</span>.ActionSend.Equals(action) && type != <span class="keyword">null</span>) {
<span class="keyword">if</span> (type.StartsWith(<span class="string">"image/"</span>)) {
handleSendImage(intent); <span class="comment">// Handle single image being sent</span>
}
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="type">Intent</span>.ActionSendMultiple.Equals(action) && type != <span class="keyword">null</span>) {
<span class="keyword">if</span> (type.StartsWith(<span class="string">"image/"</span>)) {
handleSendMultipleImages(intent); <span class="comment">// Handle multiple images being sent</span>
}
}
<span class="keyword">else</span>
{
<span class="comment">// Start our real activity if no acceptable file received</span>
StartActivity (<span class="keyword">typeof</span> (<span class="type">MainActivity</span>));
}
}
}
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
The above code allows me to handle any filetype at all (<span class="string">DataHost="*.*") and will cause my application to appear as an option in the "Send" link of any other app. If you only need to handle a specific filetype you would change the second * in DataHost to the filetype you need, such as (DataHost="*.png") would only handle PNG (Portable Network Graphics) files. </span><br />
<span class="string"><br /></span>
<span class="string">In my case, since I am accepting all filetypes, I need to determine what type of file I was given and handle it appropriately. </span><span class="string">You can see this occurring in the operations with the data derived from intent (intent, action, type), which is the incoming file details and requested action by the other app. </span>The action type gives a hint on what needs to be done with the file being sent (Send, Open, View, etc.) and the type tells you the MIME type information for the file, whether it's a PDF, image file, APK, MP3, webpage, etc. If you aren't sure what file type you need to receive, set your DataHost to *.* then set a breakpoint, debug your app and inspect the intent.type after opening the desired file.Jaredhttp://www.blogger.com/profile/00323032321674321584noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-52348173352155332472013-07-10T12:54:00.000-07:002013-07-10T12:54:05.060-07:00Making good progress on the Android Version. <div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7TAe3u9y_BONVKqp3mmXR-hDWRhlCL__3_Ni9L-qWD1AMBovE92qo3rpEnF15lwQ-CfencZYBgMAxlOxUlHscuvILPLaY1d5ea3DNJeOOuXHn2PczKQauZinxe42AfaEjZqp92D69wNl/s1600/Screen+Shot+2013-07-10+at+1.47.14+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7TAe3u9y_BONVKqp3mmXR-hDWRhlCL__3_Ni9L-qWD1AMBovE92qo3rpEnF15lwQ-CfencZYBgMAxlOxUlHscuvILPLaY1d5ea3DNJeOOuXHn2PczKQauZinxe42AfaEjZqp92D69wNl/s640/Screen+Shot+2013-07-10+at+1.47.14+PM.png" width="360" /></a></div>
<br />
Things are looking pretty decent, actually. Just gotta keep making progress. I really have gotten a lot better at this whole mobile thing. Kind of impressed. It's amazing how much time you save, when your projects have a lot of classes without native references.<br />
<br />
I really can't wait for the release this weekend on ITunes. <br />
<br />
I'll have to add a back navigation button.. up in that window.. but I think I can live with how it's taking shape already.Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-23051843507560741402013-07-09T17:28:00.000-07:002013-07-09T17:28:06.270-07:00Starting up the Android Version of Print Hub.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhenN-i3znQ6MLOF0fMdo9yTPq2_-RF0GiA_eSxaYqa-0CGYEm6KFIIm3cfhe8oeia5p9I7fq5OaNDiffvPZRfEFSZSI8Z7hxTMPGTDekA9nbjGCPGRdG04fFwo0PwlPNGWJXO_2MIxgheO/s1600/Screen+Shot+2013-07-09+at+6.13.35+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhenN-i3znQ6MLOF0fMdo9yTPq2_-RF0GiA_eSxaYqa-0CGYEm6KFIIm3cfhe8oeia5p9I7fq5OaNDiffvPZRfEFSZSI8Z7hxTMPGTDekA9nbjGCPGRdG04fFwo0PwlPNGWJXO_2MIxgheO/s640/Screen+Shot+2013-07-09+at+6.13.35+PM.png" width="360" /></a></div>
<br />
<br />
I've been dying to kick some tush (as I'd say to my boys) on this stuff that's been floating around.<br />
Jared is kicking it with me. Camera functions and Album functions work, moving on to the rest of the stuff here soon. Had to take a bit of time and get some native Java code ported over. I should have started with Android for my first store app, instead of spending so much time on IOS, but I think if I had.. I would have been really frustrated later, moving to IOS. Java code ports for functionality, are so fast. I could do it in my sleep. : )<br />
<br />
That's one problem that will always exist in Xamarin, because there is no Graphics port for Mono, you always have to work with graphics / pdf's.. almost everything natively.. unless, you can find something that has been ported purely to Mono. <br />
<br />
You have to give Apple this: Their best apps always look good. Or at least, a heckuva lot better than most Android Apps out there. The game, is to understand enough.. to be able to style both sides. Android, and IOS.. powerfully. I think I know have the ability to make.. purdy apps. Now it's just porting API's.. luckily, I do that once. <br />
<br />
What I really love about porting API's.. is that the code to use those API's.. is always so tiny..Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-80816148560961340192013-07-09T09:07:00.001-07:002013-07-09T09:10:33.651-07:00Print Hub Progress.<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
I did a lot of work yesterday on Print Hub. I'm not even sure how long I worked on it.<br />
<div>
It seemed to be a lot more fun than it was before. In fact, I got a whole pile of the Google Cloud Print API working, that didn't work before previously (Not entirely sure what was up there, but I rewrote a number of classes, and cleaned things up). Here in the next couple days, I'll be pushing a couple other app ideas, out the door (I'm hoping), but frankly, there doesn't seem to be a lot in the way right now. : )<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVAbVAF1daPb6j36pZLf56efVy4_Y77xyVSjKvkWzrObi1wez-x5bIW7UXicuVX_F7xDsP2FTHc0Srm6UL3_w4zK9AxH0EvNUF-N8hpv3mr7V-mG0EHCG22p_35r3-GtH7eJWY9j4AK6Ml/s1600/IMG_0009.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVAbVAF1daPb6j36pZLf56efVy4_Y77xyVSjKvkWzrObi1wez-x5bIW7UXicuVX_F7xDsP2FTHc0Srm6UL3_w4zK9AxH0EvNUF-N8hpv3mr7V-mG0EHCG22p_35r3-GtH7eJWY9j4AK6Ml/s400/IMG_0009.PNG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">I added Processing Invites, and deleting Jobs.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht-Mt6lvsRzicmrrKcUc4Ok7bqsI1FYcML5JZTZ8EuMOFSW6iQhzk0opy9uhW9ObbtoSnTNo-yLBovSsRdBMyytGMA1xeAJPv-pLBhLpwq7MoLbdB1HeiGPcoQzWHwJsFyJJv6-vosAaZy/s1600/IMG_0005.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht-Mt6lvsRzicmrrKcUc4Ok7bqsI1FYcML5JZTZ8EuMOFSW6iQhzk0opy9uhW9ObbtoSnTNo-yLBovSsRdBMyytGMA1xeAJPv-pLBhLpwq7MoLbdB1HeiGPcoQzWHwJsFyJJv6-vosAaZy/s400/IMG_0005.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Obviously, I did some styling work.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7RDgoWPrTJFHAR0Vl0_ClP0IarPabhwLrzVA9vjAiNuf8EO6x8S0s8VEiGR5tRw9JLsccarFrcAWoLYlT10ekRc33d512DGXeOoFZrd01O4UrQDpRjdQLCU_c4GC8KfSfYVHr2CvKP5qI/s1600/IMG_0007.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7RDgoWPrTJFHAR0Vl0_ClP0IarPabhwLrzVA9vjAiNuf8EO6x8S0s8VEiGR5tRw9JLsccarFrcAWoLYlT10ekRc33d512DGXeOoFZrd01O4UrQDpRjdQLCU_c4GC8KfSfYVHr2CvKP5qI/s400/IMG_0007.PNG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">I wanted it to be a bit cleaner.. overall. Faster on that main dialog for printing.</td></tr>
</tbody></table>
</div>
Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-47475225303621365142013-06-23T20:29:00.001-07:002013-06-23T20:36:00.240-07:00How to import Sketchup Free models into Unity FreeSometimes you need to get your 'Programmer Art' into Unity. I recently tried out <a href="http://www.sketchup.com/">Sketchup</a> for 3D modelling and found it an excellent tool to let me create some basic models for prototyping. This method will allow you to import your own models, or models imported from <a href="http://sketchup.google.com/3dwarehouse/">Google 3D Warehouse</a>. If you dont use the paid version of Sketchuo, you will need this free <a href="http://sketchucation.com/forums/viewtopic.php?t=33448">plugin</a>. If you don't want to register on that site, its in my <a href="https://dl.dropboxusercontent.com/u/82846598/OBJexporter.rb" rel="nofollow">Dropbox</a>. Put this file in your sketchup\plugins folder.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG7L5pF52s6_OTLkrsLA7cojsVZT6UhX0Oaw6ZeeutZ-zpfdF-MRcjlh0Zh_B9a7V7vpiIh22XFR4hexITdbULePDEHwo_CYcPDQLzLajDre3vgQAJYc5IjOOrIjFyeTUxdLpXu5AXfz8/s1600/800px-Celtic-knot-basic-linear.svg_.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="76" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG7L5pF52s6_OTLkrsLA7cojsVZT6UhX0Oaw6ZeeutZ-zpfdF-MRcjlh0Zh_B9a7V7vpiIh22XFR4hexITdbULePDEHwo_CYcPDQLzLajDre3vgQAJYc5IjOOrIjFyeTUxdLpXu5AXfz8/s200/800px-Celtic-knot-basic-linear.svg_.png" width="200" /></a></div>
<br />
<br />
Lets get started:<br />
<br />
First we need a Sketchup model. <a href="https://dl.dropboxusercontent.com/u/82846598/ChurchyTypeThing.skp" rel="nofollow">Here is one I made earlier :)</a>. Feel free to use it or make your own. If you choose to make your own, I recommend using the Simple Metre template, as the scale will match Unity. If you want pull something from the warehouse, go to Window > Components and use the search bar.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnQxPeEIORJkqOxNdDUJ_IrCB0qs2X4YDRHcEnEjBWGA4gyk496erCyPoNIO9zKq3sVyFnZ_LcKGdKfWiZ7kkWzWb9IWTQ-bOjBfXOKsQNQ5xj4am_QE-B6bo9tFPJ_bOEca2rWmpKSzA/s1600/churchytypething.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnQxPeEIORJkqOxNdDUJ_IrCB0qs2X4YDRHcEnEjBWGA4gyk496erCyPoNIO9zKq3sVyFnZ_LcKGdKfWiZ7kkWzWb9IWTQ-bOjBfXOKsQNQ5xj4am_QE-B6bo9tFPJ_bOEca2rWmpKSzA/s320/churchytypething.PNG" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A churchy type thing</td></tr>
</tbody></table>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
When you are ready to export your model:<br />
<br />
Select File > OBJ Exporter<br />
Give it a filename and select YES to convert all texture files to PNG.<br />
This process will also optimise the model (remove duplicate vertices etc..)<br />
<br />
To import the model into Unity:<br />
<br />
Copy the .mtl,.obj and the model textures folder into your projects Asset folder. Create a new folder or use an existing one, it doesn't matter as long as it is in the Assets folder.<br />
Open your Unity project. You will see the model and its associated files in the project window.<br />
There will be a prefab ready for you to drag into your scene (or instantiate through code), with it's textures intact, including the UV mappings.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiphRpuPEUfLyJQ3Cp0bTFmn9Io8A6j6LRGi6kgJLgE_USgSVVoeLfHpAdcDfQqiJsF-3LCHY-y6LPNLmj8YdzSAELq_wueokMjKMJHZkhqwqskBhAdroKgpTw5JLVhJqx-0o5ndMOOa0U/s1600/churchununity.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiphRpuPEUfLyJQ3Cp0bTFmn9Io8A6j6LRGi6kgJLgE_USgSVVoeLfHpAdcDfQqiJsF-3LCHY-y6LPNLmj8YdzSAELq_wueokMjKMJHZkhqwqskBhAdroKgpTw5JLVhJqx-0o5ndMOOa0U/s640/churchununity.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The same churchy thing in a Unity scene.</td></tr>
</tbody></table>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-16486251467796089142013-06-22T16:42:00.000-07:002013-06-22T16:46:49.090-07:00Useful Xamarin.IOS code for Filter Information.I know with IOS7 coming, making Filter code could be a thing of the past..<br />
<div>
<br /></div>
<div>
But I wanted to throw this code out there anyways.<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>CIFilter filter = CIFilter.FromName ("CISharpenLuminance");
string[] keys = filter.InputKeys;
NSDictionary attributes = filter.Attributes;
foreach(NSObject key in attributes.Keys)
{
Console.WriteLine(key.ToString());
Console.WriteLine (attributes[key].ToString());
}
foreach (string s in keys)System.Console.WriteLine (s);
</code></pre>
<br />
<br />
Pick your filter.. throw it into the CIFilter.FromName() line, and bam, you have all the info you need to apply it.</div>Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-18134098000524633332013-06-22T12:01:00.000-07:002013-06-22T12:01:33.292-07:00How to use Xamarin's new UI Designer with Paint Code for custom controls.<div class="separator" style="clear: both; text-align: center;">
<a href="http://blog.xamarin.com/hands-on-xamarin-studio%E2%80%99s-powerful-new-ios-designer/" target="_blank">Xamarin's new IOS Designer</a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
After reading this post by the Xamarin team, I really wanted to get to work on making some nifty things. So, I basically pulled down the latest updates in the Alpha channel from Xamarin, made a new project, and hopped right in.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
I wanted to see how much easier it was to make custom styled components and add them to my applications, and boy, was I impressed how much faster it is.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Using the UIButton for this little example of code, is probably the worst thing I could have done, but oh well. I created this simple class, MyButton and inherited from UIButton. </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code> [Register("MyButton")]
public class MyButton : UIButton
{
public MyButton ()
{
}
public MyButton (IntPtr handle)
{
this.Handle = handle;
}
public override void Draw (System.Drawing.RectangleF rect)
{
base.Draw (rect);
var context = UIGraphics.GetCurrentContext();
//// Color Declarations
UIColor strokeColor = UIColor.FromRGBA(0.000f, 0.000f, 0.000f, 1.000f);
//// Shadow Declarations
var shadow = strokeColor.CGColor;
var shadowOffset = new SizeF(3.1f, 3.1f);
var shadowBlurRadius = 5;
//// Image Declarations
var image = UIImage.FromFile("Test2.png");
//// Rectangle Drawing
var rectanglePath = UIBezierPath.FromRoundedRect(rect, 8);
context.SaveState();
context.SetShadowWithColor(shadowOffset, shadowBlurRadius, shadow);
context.SaveState();
rectanglePath.AddClip();
image.Draw(rect);
context.RestoreState();
context.RestoreState();
strokeColor.SetStroke();
rectanglePath.LineWidth = 1;
rectanglePath.Stroke();
}
}
</code></pre>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
The Draw code, came from PaintCode.. I had to tweak a couple things, one, I had to tweak image.Draw to match the button's submitted rect for Draw. Below is a screenshot from PaintCode, I set the Corners to rounded, upped the radius so that it was visible for the rounding of the corners, then I picked a texture image, for the fill.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy5APhtTkHsFdc8ZNjlZ_bxCEfJCdZ_da_vith0gz5YwMV4kas1x3V5earLElhzUn1g-_zvZAjK5MwXX1b6-RvGbvH0W3ruaKULFLAEzP7aVV24nk86lINsCQ8KRaukrl9KodMV0DUxFuy/s1600/Screen+Shot+2013-06-22+at+12.45.38+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="367" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy5APhtTkHsFdc8ZNjlZ_bxCEfJCdZ_da_vith0gz5YwMV4kas1x3V5earLElhzUn1g-_zvZAjK5MwXX1b6-RvGbvH0W3ruaKULFLAEzP7aVV24nk86lINsCQ8KRaukrl9KodMV0DUxFuy/s400/Screen+Shot+2013-06-22+at+12.45.38+PM.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Below is rendered output inside of their new designer.. which means I didn't need to deploy in order to see a result. </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFSBZRXlbpJs0ct8mnVL5TNhRmS3MvgFONU9ioFy29smqB3sVMULCOnFd5UPqgL3UAB-2jylbNqlB5-g15mJIfHHqmlQX8r93NvsU9uqo2BYebp5LkCJDcFM4KNDzowR9NLC60qq7M_B_u/s1600/Screen+Shot+2013-06-22+at+12.44.56+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFSBZRXlbpJs0ct8mnVL5TNhRmS3MvgFONU9ioFy29smqB3sVMULCOnFd5UPqgL3UAB-2jylbNqlB5-g15mJIfHHqmlQX8r93NvsU9uqo2BYebp5LkCJDcFM4KNDzowR9NLC60qq7M_B_u/s640/Screen+Shot+2013-06-22+at+12.44.56+PM.png" width="438" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-5418019356924083272013-06-21T16:41:00.002-07:002013-06-21T16:41:41.400-07:00Print Hub status update.<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8opRrzus2MMAUfwAg4_IhwE9VDJuZrq4407R9sTauR28EVAYM5_xnpLj93-Zan9PDF36DvkeROvcRUSTjBLJFK1trYL7VpiqsQB_478TaNucUd6bwF7kp4gTvXjduDsvG9aE_nOMYjGVO/s1600/Screen+Shot+2013-06-21+at+5.31.31+PM.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8opRrzus2MMAUfwAg4_IhwE9VDJuZrq4407R9sTauR28EVAYM5_xnpLj93-Zan9PDF36DvkeROvcRUSTjBLJFK1trYL7VpiqsQB_478TaNucUd6bwF7kp4gTvXjduDsvG9aE_nOMYjGVO/s640/Screen+Shot+2013-06-21+at+5.31.31+PM.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Graph provided by AppFigures.com</td></tr>
</tbody></table>
As you can see, I'm still getting purchases.. even without marketing, and without being listed as a supporting app on Google Cloud Print. <br />
<br />
I'm hoping this weekend to finish off those requirements, so I can get listed, and then I'll see if my purchase rate goes up.<br />
<br />
I had a chat with App.IO's CEO this week, I have a weird suspicion that the App.IO team bought my app and that's why I had that surge of purchases. Just told him I loved the platform.. and that he needed some "C guys" to deal with the latency in rendering for the product. To be honest, they really don't need the work done.. who cares if it is laggy. It's gorgeous.<br />
<br />
Here this weekend, I'm going to try and get the start of my next couple apps going. <br />
<br />
I don't know what to think. I don't think being an independent mobile developer will ever be easy, but I do know that I'm going to keep adding my features. I'm pretty much operating at a loss, in regards to App Store deployments, but honestly, I'm ok with it. I've gotten some components, that I'll be able to re-use for other projects. I probably still need a lot more components to be able to do the wide array of applications I intend to do. <br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-24592066720895564512013-06-16T00:03:00.000-07:002013-06-17T08:20:30.321-07:00Example of Deleting from SQLite DB using C# in Xamarin AndroidI tried to use LINQ syntax to delete my objects from a table like shown here, but got an error "Cannot store type: MyObject":<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> DeleteOldObjects()
{
<span class="keyword">string</span> path = <span class="type">Path</span>.Combine (System.<span class="type">Environment</span>.GetFolderPath (System.<span class="type">Environment</span>.<span class="type">SpecialFolder</span>.MyDocuments), <span class="string">"MyDatabase.db"</span>);
<span class="type">var</span> db = <span class="keyword">new</span> <span class="type">SQLiteConnection</span>(path,password,<span class="keyword">false</span>);
<span class="type">var</span> query = db.Table<MyObject>().Where(rt => rt.Date < <span class="type">DateTime</span>.Now.AddDays(-3));
<span class="keyword">if</span> (query != <span class="keyword">null</span>) {
<span class="keyword">foreach</span> (var <span class="keyword">object</span> <span class="keyword">in</span> query.ToList<MyObject>()) {
db.Delete<MyObject>(<span class="keyword">object</span>);
}
}
db.Commit ();
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
From what I could determine by looking at the SQLite.cs code, it seems like this error is when it's trying to bind my object as a parameter:<br />
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: 13.3333px;
font-width: 400;
color: black;
font-family: "Courier New";
}
.csharpcode pre { margin: 0px; }
.csharpcode .comment { color: #008000; }
.csharpcode .comment2 { color: #808080; }
.csharpcode .type { color: #2B91AF; }
.csharpcode .keyword { color: #0000FF; }
.csharpcode .string { color: #A31515; }
.csharpcode .preproc { color: #0000FF; }
</style>
<br />
<div class="csharpcode">
<br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">internal</span> <span class="keyword">static</span> <span class="keyword">void</span> BindParameter (<span class="type">IntPtr</span> stmt, <span class="keyword">int</span> index, <span class="keyword">object</span> <span class="keyword">value</span>)
{
<span class="keyword">if</span> (<span class="keyword">value</span> == <span class="keyword">null</span>) {
SQLite3.BindNull (stmt, index);
} <span class="keyword">else</span> {
<span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> Int32) {
SQLite3.BindInt (stmt, index, (<span class="keyword">int</span>)<span class="keyword">value</span>);
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> String) {
SQLite3.BindText (stmt, index, (<span class="keyword">string</span>)<span class="keyword">value</span>, -1, NegativePointer);
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> Byte || <span class="keyword">value</span> <span class="keyword">is</span> UInt16 || <span class="keyword">value</span> <span class="keyword">is</span> SByte || <span class="keyword">value</span> <span class="keyword">is</span> Int16) {
SQLite3.BindInt (stmt, index, <span class="type">Convert</span>.ToInt32 (<span class="keyword">value</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> Boolean) {
SQLite3.BindInt (stmt, index, (<span class="keyword">bool</span>)<span class="keyword">value</span> ? 1 : 0);
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> UInt32 || <span class="keyword">value</span> <span class="keyword">is</span> Int64) {
SQLite3.BindInt64 (stmt, index, <span class="type">Convert</span>.ToInt64 (<span class="keyword">value</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> Single || <span class="keyword">value</span> <span class="keyword">is</span> Double || <span class="keyword">value</span> <span class="keyword">is</span> Decimal) {
SQLite3.BindDouble (stmt, index, <span class="type">Convert</span>.ToDouble (<span class="keyword">value</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> DateTime) {
SQLite3.BindText (stmt, index, ((<span class="type">DateTime</span>)<span class="keyword">value</span>).ToString (<span class="string">"yyyy-MM-dd HH:mm:ss"</span>), -1, NegativePointer);
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span>.GetType ().IsEnum) {
SQLite3.BindInt (stmt, index, <span class="type">Convert</span>.ToInt32 (<span class="keyword">value</span>));
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">value</span> <span class="keyword">is</span> <span class="keyword">byte</span>[]) {
SQLite3.BindBlob (stmt, index, (<span class="keyword">byte</span>[])<span class="keyword">value</span>, ((<span class="keyword">byte</span>[])<span class="keyword">value</span>).Length, NegativePointer);
} <span class="keyword">else</span> {
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="type">NotSupportedException</span> (<span class="string">"Cannot store type: "</span> + <span class="keyword">value</span>.GetType ());
}
}
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
That seemed to me like the most intuitive way to perform that task since it's the same syntax used to insert objects, but since it didn't work I found you actually need to pass the primary key of the object you want to delete, like this:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> DeleteOldObjects()
{
<span class="keyword">string</span> path = <span class="type">Path</span>.Combine (System.<span class="type">Environment</span>.GetFolderPath (System.<span class="type">Environment</span>.<span class="type">SpecialFolder</span>.MyDocuments), <span class="string">"MyDatabase.db"</span>);
<span class="type">var</span> db = <span class="keyword">new</span> <span class="type">SQLiteConnection</span>(path,password,<span class="keyword">false</span>);
<span class="type">DateTime</span> expireDate = <span class="type">DateTime</span>.Now.AddDays(-3));
<span class="type">var</span> query = db.Table<MyObject>().Where(rt => rt.Date < expireDate );
<span class="keyword">if</span> (query != <span class="keyword">null</span>) {
<span class="keyword">foreach</span> (var <span class="keyword">object</span> <span class="keyword">in</span> query.ToList<MyObject>()) {
db.Delete<MyObject>(<span class="keyword">object.PrimaryKeyId</span>);
}
}
db.Commit ();
}<!--[if IE]>
<![endif]--></pre>
</div>
Jaredhttp://www.blogger.com/profile/00323032321674321584noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-29971560512818287222013-06-15T21:25:00.002-07:002013-06-16T12:55:46.124-07:00Efficient Custom ListView Adapter SelectionsA customer requested I create a ListView of their business objects using custom graphics and text based on the status of the object. I had no problem creating it but they complained that it took too long to refresh when making selections. After puzzling over the code for awhile trying to determine how to speed it up, I realized that the convertView paramter passed in to the GetView method that I was overriding in my custom listview adapter was actually the existing view of the object, and if it wasn't null I didn't have to recreate it. <br />
<br />
So now in my code I check first and I only create the view from scratch if it's null. Otherwise, I only modify the existing view to change the background color to signify that it has been selected. I also store the two Drawables that are the backgrounds so they don't have to be retrieved and assigned memory for each object. This allows the ListView to refresh quickly as it doesn't have to reacquire the underlying objects and rebuild the entire view based on the object's properties each time the selection is changed. This seems like a simple thing, but maybe someone else that is struggling with ListView performance will happen across my post.<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">namespace</span> Droid
{
<span class="keyword">public</span> <span class="keyword">class</span> <span class="type">ListViewObjectAdapter</span> : <span class="type">BaseAdapter</span><<span class="type">MyObject</span>> {
<span class="type">List</span><<span class="type">MyObject</span>> items;
<span class="keyword">public</span> <span class="keyword">int</span> selectedListItem = -1;
<span class="type">Activity</span> context;
<span class="keyword">Drawable</span> bgDefault;
<span class="keyword">Drawable</span> bgHighlight;
<span class="keyword">public</span> ListViewobjectAdapter(<span class="type">Activity</span> context, <span class="type">List</span><<span class="type">MyObject</span>> items)
: <span class="keyword">base</span>()
{
<span class="keyword">this</span>.context = context;
<span class="keyword">this</span>.items = items;
<span class="keyword">Drawable</span> bgDefault = context.<span class="type">Resources</span>.GetDrawable(Resource.Drawable.gray_button_focused);
<span class="keyword">Drawable</span> bgHighlight = context.<span class="type">Resources</span>.GetDrawable(Resource.Drawable.gray_button_default);
}
<span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">long</span> GetItemId(<span class="keyword">int</span> position)
{
<span class="keyword">return</span> position;
}
<span class="keyword">public</span> <span class="keyword">void</span> SetItems(<span class="type">List</span><<span class="type">MyObject</span>> items)
{
<span class="keyword">this</span>.items = items;
<span class="keyword">this</span>.NotifyDataSetInvalidated ();
}
<span class="keyword">public</span> <span class="keyword">override</span> MyObject <span class="keyword">this</span>[<span class="keyword">int</span> position]
{
<span class="keyword">get</span> { <span class="keyword">return</span> items[position]; }
}
<span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">int</span> Count
{
<span class="keyword">get</span> { <span class="keyword">return</span> items.Count; }
}
<span class="keyword">public</span> <span class="keyword">override</span> <span class="type">View</span> GetView(<span class="keyword">int</span> position, <span class="type">View</span> convertView, <span class="type">ViewGroup</span> parent)
{
<span class="type">View</span> view = convertView;
<span class="keyword">if</span> (view == <span class="keyword">null</span>)
{
<span class="keyword">string</span> SENT_PREFIX = context.<span class="type">Resources</span>.GetString(Resource.<span class="type">String</span>.sent_object_prefix);
<span class="keyword">string</span> UNSENT_PREFIX = context.<span class="type">Resources</span>.GetString(Resource.<span class="type">String</span>.unsent_object_prefix);
<span class="type">MyObject</span> item = items[position];
<span class="type">Subobject</span> subobject = Helper.GetSubobjectById (item.SubobjectId);
view = context.LayoutInflater.Inflate (Resource.<span class="type">Layout</span>.ListViewObjectItem, <span class="keyword">null</span>);
view.FindViewById<TextView> (Resource.Id.tvTitle).<span class="type">Text</span> = Helper.GetInfoBySubOject (SubObject);
<span class="keyword">if</span> (item.Date.Date.Equals (<span class="type">DateTime</span>.Now.Date))
view.FindViewById<TextView> (Resource.Id.tvobjectId).<span class="type">Text</span> = item.Date.ToShortTimeString ();
<span class="keyword">else</span>
view.FindViewById<TextView> (Resource.Id.tvobjectId).<span class="type">Text</span> = item.Date.ToShortDateString ();
view.FindViewById<TextView> (Resource.Id.tvobjectIdText).<span class="type">Text</span> = <span class="string">""</span>;
<span class="keyword">if</span> (item.IsValid) {
view.FindViewById<ImageView> (Resource.Id.Image2).SetImageResource (Resource.Drawable.icon_accept);
view.FindViewById<TextView> (Resource.Id.tvDescription).<span class="type">Text</span> = <span class="string">"Extra Info: "</span> + Helper.GetAdditionalInfoByObjectId(item.MyObjectId);
} <span class="keyword">else</span> {
view.FindViewById<ImageView> (Resource.Id.Image2).SetImageResource (Resource.Drawable.icon_reject);
<span class="type">ValidSubobject</span> SubobjectMeasure = Helper.GetValidSubObjectByObjectId (item.MyObjectId);
view.FindViewById<TextView> (Resource.Id.tvDescription).<span class="type">Text</span> = <span class="string">"MyInfo: "</span> + SubobjectMeasure.Info.ToString () + ";
}
}
<span class="type">RelativeLayout</span> rlListViewItem = (<span class="type">RelativeLayout</span>)view.FindViewById (Resource.Id.rlListViewItem);
<span class="keyword">if</span>(position == selectedListItem) {
rlListViewItem.SetBackgroundDrawable(bgHighlight);
} <span class="keyword">else</span> {
rlListViewItem.SetBackgroundDrawable(bgDefault );
}
<span class="keyword">return</span> view;
}
}
}<!--[if IE]>
<![endif]--></pre>
</div>
Jaredhttp://www.blogger.com/profile/00323032321674321584noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-60834261447512841702013-06-09T10:07:00.000-07:002013-06-16T12:56:46.051-07:00Sepia Tone UIViewController Xamarin.IOS. <div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOicGFLCFUiuqOx9JYQKkzv47axA4BNBChQD-7jU1GwM3fL5utAvPqEh3v9Qq7bjjywrwb9O7QgHdyThax_KSU4RzDdymcywcvvn49z8oH6UWfIh0GOjRcgNNMW2XK053mMYzqAF7BAiVw/s1600/Screen+Shot+2013-06-09+at+10.16.53+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOicGFLCFUiuqOx9JYQKkzv47axA4BNBChQD-7jU1GwM3fL5utAvPqEh3v9Qq7bjjywrwb9O7QgHdyThax_KSU4RzDdymcywcvvn49z8oH6UWfIh0GOjRcgNNMW2XK053mMYzqAF7BAiVw/s640/Screen+Shot+2013-06-09+at+10.16.53+AM.png" width="443" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
I made the slider in XCode resolve as "TheSlider"<br />
I made the UIImageView resolve as "TheImage"<br />
I made the Buttons resolve as their text values.<br />
<br />
Below is the Code:<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>public partial class SepiaToneController : UIViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
string path;
MonoTouch.CoreImage.CISepiaTone filter = new MonoTouch.CoreImage.CISepiaTone();
public SepiaToneController (string Path)
: base (UserInterfaceIdiomIsPhone ? "SepiaToneController_iPhone" : "SepiaToneController_iPad", null)
{
path = Path;
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.Title = "Sepia Tone";
TheSlider.MinValue = 0;
TheSlider.MaxValue = 1;
TheSlider.Value = 0;
Preview.TouchUpInside += delegate {
UpdateImage();
};
Save.TouchUpInside += delegate {
SaveImage();
};
}
public void UpdateImage()
{
BTProgressHUD.Show ("Applying Filter. . .", -1, BTProgressHUD.MaskType.Black);
BTProgressHUD.InvokeInBackground (delegate {
this.TheImage.ContentMode = UIViewContentMode.ScaleAspectFit;
if (TheSlider.Value == 0) {
var image = UIImage.FromFile (path);
filter.Intensity = TheSlider.Value;
filter.Image = new CIImage (UIImage.FromFile(path));
UIImage blah = new UIImage (new CIImage(UIImage.FromFile(path)),1,image.Orientation);
this.TheImage.Image = blah;
} else {
var image = UIImage.FromFile (path);
filter.Intensity = TheSlider.Value;
filter.Image = new CIImage (UIImage.FromFile(path));
var newimage = filter.OutputImage;
UIImage returnImage = new UIImage(newimage);
UIImage blah = new UIImage (filter.OutputImage,1,image.Orientation);
//.ImageByCroppingToRect(new RectangleF(0, 0, this.View.Bounds.Width, this.View.Bounds.Height * 9 / 16)
this.TheImage.Image = blah;
}
BTProgressHUD.Dismiss();
});
}
public void SaveImage()
{
BTProgressHUD.Show ("Applying Filter. . .", -1, BTProgressHUD.MaskType.Black);
BTProgressHUD.InvokeInBackground (delegate {
var temp = UIImage.FromFile(path);
filter.Intensity = TheSlider.Value;
filter.Image = new CIImage (UIImage.FromFile(path));
CIImage meh = filter.OutputImage;
UIImage blah = new UIImage(meh,1,temp.Orientation);
SizeF newSize = new SizeF(UIImage.FromFile(path).Size.Width,UIImage.FromFile(path).Size.Height);
UIGraphics.BeginImageContextWithOptions(size:newSize, opaque:false, scale:0.0f);
blah.Draw (new RectangleF(0,0,blah.Size.Width,blah.Size.Height));
UIImage croppedImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
NSData data = croppedImage.AsJPEG();
byte[] dataBytes = new byte[data.Length];
if(!Directory.Exists(LocationHelper.FilterLocation()))Directory.CreateDirectory(LocationHelper.FilterLocation ());
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
FileStream f = File.OpenWrite(LocationHelper.FilterLocation()+Path.GetFileName(path));
f.Write(dataBytes,0,dataBytes.Length);
f.Close();
BTProgressHUD.Dismiss();
});
}
}
</code></pre>
<br />
<br />
My end product :<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpqlWO0YJ4HAT7LhIqSrJWC9ItjEx0gCrNWKFPnj8-wN5av8BlMqpJ2nVYz_izFPXN5ryVcM8YtgkDohpiZ1_LDl1MXPtlF-_0T9dvNaYw92eccPywi-7fnMc88QIPTHwqs-WOxr_fGwXG/s1600/IMG_0028.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpqlWO0YJ4HAT7LhIqSrJWC9ItjEx0gCrNWKFPnj8-wN5av8BlMqpJ2nVYz_izFPXN5ryVcM8YtgkDohpiZ1_LDl1MXPtlF-_0T9dvNaYw92eccPywi-7fnMc88QIPTHwqs-WOxr_fGwXG/s640/IMG_0028.PNG" width="360" /></a></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-20361168023537693132013-06-01T09:01:00.000-07:002013-06-01T09:02:36.010-07:00Adding Email functionality to a Monotouch DialogViewController. <pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
RootElement re = new RootElement("Example");
Section Email = new Section("Email");
if (MFMailComposeViewController.CanSendMail)
{
Email.Add(new ImageStringElement("Email",delegate {
{StaticClassReference}.EmailFile(path);
},UIImage.FromFile("Email@2x.png")));
re.Add(Email);
}
</code></pre>
<div>
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>public static void EmailFile(string path)
{
BTProgressHUD.Show ("Loading. . .",-1,BTProgressHUD.MaskType.Black);
BTProgressHUD.InvokeInBackground (delegate {
UIApplication.SharedApplication.Windows[0].InvokeOnMainThread(delegate {
MFMailComposeViewController mail = new MFMailComposeViewController ();
mail.MailComposeDelegate = new CustomMailComposeDelegate ();
mail.AddAttachmentData(NSData.FromFile(path),MIMEAssistant.GetMIMEType(path),Path.GetFileName(path));
UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(mail,true,null);
BTProgressHUD.Dismiss();
});
});
}
</code></pre>
<div>
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>public class CustomMailComposeDelegate : MFMailComposeViewControllerDelegate
{
public override void Finished (MFMailComposeViewController controller,
MFMailComposeResult result, NSError error)
{
controller.DismissViewController (true, null);
}
}
</code></pre>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILepnUvx3bVS-3knSZLoLGtHCdyX4YBIQcahmzhk4FWzgCuFBLUi1ykjluWZaxXsuA037UGDRX-IQPKclTObcLlNP2lOKaiFEpaWvNaVsgAVLJU5dArpVWZ-LPGkihSJ05WmQZegYKydq/s1600/Monotouch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="51" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILepnUvx3bVS-3knSZLoLGtHCdyX4YBIQcahmzhk4FWzgCuFBLUi1ykjluWZaxXsuA037UGDRX-IQPKclTObcLlNP2lOKaiFEpaWvNaVsgAVLJU5dArpVWZ-LPGkihSJ05WmQZegYKydq/s640/Monotouch.png" width="640" /></a></div>
<br />
My only note on this, is that you'll need a consistent way to determine mimetype.<br />
<br />
Behavior for the OS shifts based on Mimetype. Example, if the file is a picture, the mail controller will load the image within the email, so that you can see it. There could be other mimetypes it has special behavior for at some point. The mimetype that is sent doesn't really matter to the mail controller, for the most part. <br />
<br />
You do however really need the "CanSendMail" statement, which tells you whether someone has setup an email account on their device, whether IPhone or IPad. <br />
<br />
You only want the Email option to show if they have configured their email accounts. Otherwise serious breakage occurs.<br />
<br />
: )</div>
Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-6227221802520794302013-05-27T02:25:00.001-07:002013-06-01T08:41:17.212-07:00Monotouch Dialog Simple pattern.<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>public class PrintDialog : DialogViewController
{
string path;
public PrintDialog (string Path) : base (new RootElement(""))
{
path = Path;
this.Pushing = true;
this.Root = GetUI ();
this.RefreshRequested += delegate {
this.Root = GetUI();
this.ReloadComplete();
};
}
public RootElement GetUI()
{
// Generate Your Root Element
}
}
</code></pre>
<br />
<br />
I like having my Monotouch Dialogs refresh on drag.<br />
<br />
I also like my navigation controller. Decided I'd post a small bit of code without implementation details that makes me very happy.Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com1tag:blogger.com,1999:blog-8077726125007140137.post-49187854847086264752013-05-27T02:05:00.000-07:002013-06-09T14:16:12.409-07:00Print Hub Update.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8o7TQ6TBe1-4L4Odsf23SJK084VCPuIydgiaYic2mtSH71laVgcMJgVTjdaj0VmRaa4tkelhyphenhyphenElPl0XJXMGy_TJ4OKw9EEDTNFY1UxSTbmAeFlwnsNOey5Xz6WQ3J-tdPsoBVACRlGhlk/s1600/IMG_0043.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8o7TQ6TBe1-4L4Odsf23SJK084VCPuIydgiaYic2mtSH71laVgcMJgVTjdaj0VmRaa4tkelhyphenhyphenElPl0XJXMGy_TJ4OKw9EEDTNFY1UxSTbmAeFlwnsNOey5Xz6WQ3J-tdPsoBVACRlGhlk/s400/IMG_0043.PNG" width="300" /></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS9oqHp2NtvoQ9gfYrU_8Jz7-HAXe37VTSTSQMJLemMGkS5w_NQRTPZXakvbibuYpKImXdozgoVorUiwAEKrTNdwgtyXVevVWjCAvZxCUBn_CyKtcDPe8O2v1NeKCEBXVYIG2CBZqwTsav/s1600/IMG_0044.PNG" imageanchor="1" style="clear: right; display: inline !important; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS9oqHp2NtvoQ9gfYrU_8Jz7-HAXe37VTSTSQMJLemMGkS5w_NQRTPZXakvbibuYpKImXdozgoVorUiwAEKrTNdwgtyXVevVWjCAvZxCUBn_CyKtcDPe8O2v1NeKCEBXVYIG2CBZqwTsav/s400/IMG_0044.PNG" width="300" /> </a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-g48r8AsKadcHT_b1N5M9NSvMHN0eCb5gNwQAjGLlfY0KtUAZRFASph0BWzEVY28MPs54UKAJdaXB7Snbjxv0zSrcNyQR335iszsSwZMC3mEu1L-UB6kfuwSjvYStOzDmBEyhx8pTooVU/s1600/IMG_0045.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-g48r8AsKadcHT_b1N5M9NSvMHN0eCb5gNwQAjGLlfY0KtUAZRFASph0BWzEVY28MPs54UKAJdaXB7Snbjxv0zSrcNyQR335iszsSwZMC3mEu1L-UB6kfuwSjvYStOzDmBEyhx8pTooVU/s400/IMG_0045.PNG" width="300" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFRfWjO6LlV71l5QCqrvQiMtsWZitQsF-DsaJhyphenhyphen6RhaINJrpNFABHx1f290ap_vBSnmTlU6xaAt-oFv2la4qEmQ72ZKdszu2rSTRw7XlYPjG5Bnf_cdvilM1q0706_pBY3HQX1O_375Lw/s1600/IMG_0021.PNG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFRfWjO6LlV71l5QCqrvQiMtsWZitQsF-DsaJhyphenhyphen6RhaINJrpNFABHx1f290ap_vBSnmTlU6xaAt-oFv2la4qEmQ72ZKdszu2rSTRw7XlYPjG5Bnf_cdvilM1q0706_pBY3HQX1O_375Lw/s400/IMG_0021.PNG" width="225" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghxpXdeAMlmYwJCQZbgeoqcN1S4H2zwqG6K5k8O0n_aFmVNTEVNdicuiXP9ZjPHxd6HOWCxE7HlkTa7FOi-hhSDzDzyUNZEUzPMBmdCB_9q5WyStKJcSwQRRqXJy_PEx1CWXh6C22TdCcF/s1600/IMG_0020.PNG" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"> </a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiS83JYlB7BmNCVGTUYulpeKbpxqZo8TAFP0uaoDrud2TODPOgp6JnLimy0gEjpKpOqpAbIGiHpvO5VGj4WBn-L_jvz09Way4CMaHUUW8PvSCGQWSFruo9JTd7Jz4BXDKVe4ffmlRvCekP5/s1600/IMG_0019.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiS83JYlB7BmNCVGTUYulpeKbpxqZo8TAFP0uaoDrud2TODPOgp6JnLimy0gEjpKpOqpAbIGiHpvO5VGj4WBn-L_jvz09Way4CMaHUUW8PvSCGQWSFruo9JTd7Jz4BXDKVe4ffmlRvCekP5/s400/IMG_0019.PNG" width="225" /></a></div>
<br />
Spent a bit of time on making the interface better for Print Hub. Have a ton of features that are.. "Developed", but can't quite be released yet. Yeah, it's 3:00am in the morning. Life is brutal. <br />
<br />
Sometimes, I feel like Thulsa Doom, talking to my inner Conan.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/wgN1sLcAQnw?feature=player_embedded' frameborder='0'></iframe></div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/14902042414537205798noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-43193954549695744782013-05-20T10:09:00.002-07:002013-05-20T18:02:24.083-07:00Building a Prototype - Part 1We hav<span style="font-family: inherit;">e an idea l</span>ocked down for our first commercial release. Design Doc follows:<br />
<br />
<br />
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Project Serious</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
A top down turn based tactical dungeon crawler, targeted to mobile platforms.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Gameplay:</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Hub Screen: services to buy/sell, craft, access stash, recruit heroes and obtain jobs(quests)</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Player is offered a selection of quests from a random quest list and must pick only one. Dungeon areas for quest are randomly generated.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Player manages a party of up to 4 characters, chosen from a roster of heroes. Heroes can be customised via points earned from levelling them up.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
After picking heroes and equiping them, Player can enter quest area and embark on quest and main game begins.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Main Game:</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Exploration phase: Player explores randomly generated dungeon. All non-combat actions take place in this phase. Can move each hero up to a maximum of 12 squares. If enemy is spotted, exploration phase immediately ends and combat phase begins.</div>
<div style="background-color: white;">
<span style="color: #222222; font-family: arial, sans-serif; font-size: x-small;">Combat Phase: All combatants(heroes and enemies) take turns to act. Each unit has 'action points' they can spend on moving, attacking and performing special skills.</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Combat Phase runs until either all heroes are dead, or all enemies are dead or subdued. If all heroes die, player is returned to the hub screen. He can recruit new adventurers to continue the quest, they can also loot the bodies of fallen heroes if they can make it back to the scene and defeat what killed them.</div>
<div style="background-color: white;">
<span style="color: #222222; font-family: arial, sans-serif; font-size: x-small;">Death is permanent but Resurrection exists, for a price. To return a life, a life must be given.</span></div>
<div style="background-color: white;">
<span style="color: #222222; font-family: arial, sans-serif; font-size: x-small;">These phases run as needed until the victory conditions for the quest are completed and player receives quest reward + dungeon loot and is returned to the hub screen.</span></div>
<div style="background-color: white;">
<span style="color: #222222; font-family: arial, sans-serif; font-size: x-small;">Player can upgrade his guild hall to attract more powerful heroes and to better equip new recruits. Player can add apothecary, enchanters, blacksmiths, leather-workers, etc</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
CO-OP Mode.</div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
Up to 3 other players can sub in their own heroes from their own rosters in your game, while maintaining the maximum of 4 heroes per adventure. </div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">Its one thing to write down an idea, and quite another thing to bring it to life. Before we dive in and start seriously investing our time and resources to this idea, we need to make sure it's actually fun to play. It sure sounds it on paper (at least to me), but the game execution may not be. A prototype is needed.</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">To start we need something to look at. I can reuse my grid code to store the level layout and the cube creation code from my Maze project to create the actual walls and floor.</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">In the maze game I used a 2D Int array to store the layout. The values were always either 0 or 1. 0 denoted an open space (no cube), 1 denoted impassible space(create cube). If I used this structure as is, it would work, but leave me no flexibility to add anything interesting to the dungeon - right now each 'grid cell' only contains enough information to know if they should be a wall or not. What if there is a trap in this cell? Or a chest full of loot? Or the mysterious glowing well? A secret doorway? We can create a new structure to store as much information as we need, and store that in a 2D array instead of using Int's. I made Code a read only property because I really don't want this variable being changed once set, but it will be often checked against.</span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
<div style="background-color: white;">
<div>
<div>
<span style="color: #222222; font-size: x-small;">public class GridCell : MonoBehaviour</span></div>
<div>
<span style="color: #222222; font-size: x-small;">{<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public bool IsPassable; //If false, will be a wall.</span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"><span style="color: #222222; font-size: x-small;"> </span></span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private string code; //Will be used to determine any cell features</span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"><span style="color: #222222; font-size: x-small;"> </span></span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public string Code</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{ get { return code;}}<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="color: #222222; font-size: x-small; white-space: pre;"> </span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public void SetData(bool isPassable, string code)</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>IsPassable = isPassable;</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>this.code = code;</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div>
<span style="color: #222222; font-size: x-small;">}</span></div>
</div>
<div style="color: #222222; font-family: inherit;">
<br /></div>
</div>
<div style="background-color: white; color: #222222;">
The GridCell class. I dont need to attach this script to an object - instances are created through code and stored directly in an array. I created the following loop for a test run. As each cell in the level is created, it randomly sets the IsPassable flag to either true or false.</div>
<div style="background-color: white; color: #222222;">
<br /></div>
<div style="background-color: white;">
<div>
<span style="color: #222222; font-size: x-small;">for(int x = 0; x < Width; x++)</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int y = 0; y < Height; y++)</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> GridCell cell = new GridCell();</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int i = Random.Range(0,2);</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(i == 0)</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cell.SetData(true, string.Empty);</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cell.SetData(false, string.Empty);<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>LevelLayout[x,y] = cell;</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div>
<span style="color: #222222; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
</div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;">And the result with a structure that is 20 cubes high and 40 cubes wide...note the upside down cross in the top right middle of the layout... a sign?</span></div>
<div style="background-color: white; color: #222222;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyqhVTqTslB4ytJH_ZHNhA3bbfysTTBP4pY87_-PE6SOJo-AAYctFc4vGDa7tyrKFuNjoZSf7zOX_ZXo-S2z0tIGK2yIYAIa8rl7ERjNF3jT3udqAPcTgg7m8SssMCYvciY0T_bD7t6xI/s1600/prototype1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyqhVTqTslB4ytJH_ZHNhA3bbfysTTBP4pY87_-PE6SOJo-AAYctFc4vGDa7tyrKFuNjoZSf7zOX_ZXo-S2z0tIGK2yIYAIa8rl7ERjNF3jT3udqAPcTgg7m8SssMCYvciY0T_bD7t6xI/s640/prototype1.PNG" width="640" /></a></div>
<div style="background-color: white; color: #222222;">
<br /></div>
<div style="background-color: white;">
<span style="color: #222222;">Not much to look at, but it's proves my structure is functioning. Next - applying some </span><span style="background-color: transparent;"><span style="color: #222222;">algorithms to make this an actual playable dungeon.</span></span></div>
<div style="background-color: white; color: #222222;">
<br /></div>
<div style="background-color: white; color: #222222;">
<span style="font-family: inherit;"><br /></span></div>
Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-67805967867651172332013-05-18T10:42:00.000-07:002013-05-20T18:02:41.923-07:00Realtime Terrain ManipulationNow that I have a game world split into cells, it can allow me to easily do some fancy things, such as targetted real-time terrain manipulation. Think Populous where you would raise or lower the game world or spells or technology that can cause a mountain or crater appear at the feet of an enemy (or player!), and have that mountain or crater become an actual part of the game level.<br />
<br />
There are other things to focus on before this. Camera setups, entity management, path finding - they take priority. But I am going to revisit this.<br />
<br />
I found a script on the forums. Its in Java, I'll convert it to c# at a later date.<br />
<a href="http://forum.unity3d.com/threads/87086-Realtime-Unity-Terrain-Manipulation-Possible?p=755093&viewfull=1#post755093">http://forum.unity3d.com/threads/87086-Realtime-Unity-Terrain-Manipulation-Possible?p=755093&viewfull=1#post755093</a><br />
<br />
I ran the script as directed. The end result is nothing fancy, just random heights being applied to a specific section of the map without recalculating the entire terrain. That last part is important because recalculating the entire terrain mesh every frame is a massive performance hit. <br />
<br />
All I need is a script to simulate curves...... mmmm curves...Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-13333986145582999392013-05-16T17:48:00.002-07:002013-05-20T18:03:03.711-07:002D Grid on a 3D TerrainQuick post tonight.<br />
<br />
I wanted to mess about with an idea that has bouncing around my head. Taking a Unity terrain and building a 'grid' over it, similar to what you would find in most tactical turn based games.<br />
<br />
So to start:<br />
Create a Terrain. Resolution does not matter, the grid will adapt.<br />
Create an empty gameobject, I called mine GridOrigin.<br />
Attach the following script to it.<br />
<br />
<span style="font-size: xx-small;">using UnityEngine;</span><br />
<span style="font-size: xx-small;">using System.Collections;</span><br />
<span style="font-size: xx-small;">using System.Collections.Generic;</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">public class Grid : MonoBehaviour {</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Terrain terrain; //terrain grid is attached to</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public bool ShowGrid = false;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public int CellSize = 10;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private Vector3 terrainSize;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private Vector3 origin;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private int width;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private int height;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private List<GameObject> objects;</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Start ()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>terrainSize = terrain.terrainData.size;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>origin = terrain.transform.position;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>width = (int)terrainSize.z / CellSize;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>height = (int)terrainSize.x / CellSize;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objects = new List<GameObject>();</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BuildGrid();<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Update ()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>foreach(GameObject obj in objects)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>obj.SetActive(ShowGrid);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void BuildGrid()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int x = 0; x < width; x++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int y = 0; y < height; y++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 pos = GetWorldPosition(new Vector2(x,y));</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pos += new Vector3(CellSize / 2, terrain.SampleHeight(GetWorldPosition(new Vector2(x,y))), CellSize /2);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.transform.position = pos;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(x==0)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.renderer.material.color = Color.red;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(y==0)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.renderer.material.color = Color.green;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.transform.localScale = new Vector3(CellSize /2, CellSize /2, CellSize/2);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.transform.parent = transform;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>go.SetActive(false);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objects.Add(go);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Vector3 GetWorldPosition(Vector2 gridPosition)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return new Vector3(origin.z + (gridPosition.x * CellSize), origin.y, origin.x + (gridPosition.y * CellSize));</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Vector2 GetGridPosition(Vector3 worldPosition)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return new Vector2(worldPosition.z / CellSize, worldPosition.x / CellSize);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;">}</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">Attach your terrain to the script.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFmP3aa5idZavyF4Ry-b6PDg6f1mkS8d4SnHsa6IQFRMMUj80_PGerjOrDwESMLDEuzyRbD3ts_BsQP9npN_gj-kLDNs4l-RU0A_2GHvZvZG-ifvOL_O1YIUsACu4x34hahuasuV96ELA/s1600/gridorigininspector.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFmP3aa5idZavyF4Ry-b6PDg6f1mkS8d4SnHsa6IQFRMMUj80_PGerjOrDwESMLDEuzyRbD3ts_BsQP9npN_gj-kLDNs4l-RU0A_2GHvZvZG-ifvOL_O1YIUsACu4x34hahuasuV96ELA/s320/gridorigininspector.PNG" width="320" /></a></div>
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">When you run, you should see your terrain as normal:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz2qcUDTETKtJ1Oq21pAHAeOWRx8u3lIKj4UJfAUB8v97y62Nnsnq_Ser0-GPFDlClXePLAcUlbWyG31JhAUiPhYURHCb62KmmDApodTVqLGUU8rovwKlootaabcWI0mmd5ODWXaQDjEc/s1600/terrainnogrid.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="195" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz2qcUDTETKtJ1Oq21pAHAeOWRx8u3lIKj4UJfAUB8v97y62Nnsnq_Ser0-GPFDlClXePLAcUlbWyG31JhAUiPhYURHCb62KmmDApodTVqLGUU8rovwKlootaabcWI0mmd5ODWXaQDjEc/s400/terrainnogrid.PNG" width="400" /></a></div>
<br />
<span style="font-size: xx-small;">In the GridOrigin object in the inspector, you can toggle a visual display of the grid on and off. The cubes appear in the exact centre of the gridcell. Green is X dimension and red is Z.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWTlJTJ9m1kVPyNx6AAX0IFq0TmFsnYmR3itBy0xD_JVeOGuAL4z9f0tAGtEBVYZOV5m35UfCQ-2oNa3vCboDfbIH1aFXpF834tB7FnB8cPMejcf0xJu_rBmeGSdJlOhugagJHhUpJ3ec/s1600/TerrainGrid.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="191" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWTlJTJ9m1kVPyNx6AAX0IFq0TmFsnYmR3itBy0xD_JVeOGuAL4z9f0tAGtEBVYZOV5m35UfCQ-2oNa3vCboDfbIH1aFXpF834tB7FnB8cPMejcf0xJu_rBmeGSdJlOhugagJHhUpJ3ec/s400/TerrainGrid.PNG" width="400" /></a></div>
<br />
<span style="font-size: xx-small;">Each gridcell can be referenced by supplying an X and a Y local co-ordinate. 5,7 for example, refers to the grid cell that is 5 cells in the x dimension and 7 cells in the Z dimension.</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">There are two methods at the end of the script GetWorldPosition and GetGridPosition. This is really the heart of the script - GetWorldPosition will return a Vector3 that corresponds to the passed GridLocation. You can use this to position objects. For example, if you wanted to move your skeleton object to the grid location 5,7 you can use skeleton.transform.position - grid.GetWorldPosition(5,7). GetGridPosition will return the grid location of a passed Vector3 as a Vector2.</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">Using a loop you can quickly create and place a horde of enemies. 900 skeletons in this case...</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy6dycFM8Idm663lbqoULzoHDAVVOfITkqTwCyWnlsp4nRAYDlLMlwO4evHLvcIVxAmvHMgSf5-34wqz2bk-wUzFwrPh22NkE8_ZulOWgt6ISLmqBJovdd40LW1i_KGQePNVFm2BgWi4E/s1600/900DancingSkeletons.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="294" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy6dycFM8Idm663lbqoULzoHDAVVOfITkqTwCyWnlsp4nRAYDlLMlwO4evHLvcIVxAmvHMgSf5-34wqz2bk-wUzFwrPh22NkE8_ZulOWgt6ISLmqBJovdd40LW1i_KGQePNVFm2BgWi4E/s640/900DancingSkeletons.PNG" width="640" /></a></div>
<span style="font-size: xx-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV-_7CphVLjWkHutJtnZFKxMuKeX0_9pTW0a-jzxDqVPMCN7TuD_5-PM21yu7mf_TSLgPdaJoM5m09GRHUppXW2lVIStqixwhdSnz_GT55ypJ9Se_qjuXwBVVUkK5zv1DLUo3OCyffv1A/s1600/900DancingSkeletons2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV-_7CphVLjWkHutJtnZFKxMuKeX0_9pTW0a-jzxDqVPMCN7TuD_5-PM21yu7mf_TSLgPdaJoM5m09GRHUppXW2lVIStqixwhdSnz_GT55ypJ9Se_qjuXwBVVUkK5zv1DLUo3OCyffv1A/s640/900DancingSkeletons2.PNG" width="640" /></a></div>
<br />
<br />Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com2tag:blogger.com,1999:blog-8077726125007140137.post-45657881371194730132013-05-15T20:13:00.001-07:002013-05-15T20:13:41.892-07:00And now for something completely different....<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
I've spent the last few weeks recreating simple game mechanics while learning Unity, with the goal of producing something that can be sold. The fruit of this tinkering so far:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDG1d9ufgzR_zq9SPHam67thKSRfN6lWXlcfe9JeqoyNLVmRXBiwM5JQDfakBCUZvPhOqlvFicjdaiijKdBv6BMEGiK5tHWNeo5Ul61XPAXMOdgvzhA4N3AkmY82-l4IHSE1cIBBnFjdI/s1600/firstpersonangrybirds.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="289" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDG1d9ufgzR_zq9SPHam67thKSRfN6lWXlcfe9JeqoyNLVmRXBiwM5JQDfakBCUZvPhOqlvFicjdaiijKdBv6BMEGiK5tHWNeo5Ul61XPAXMOdgvzhA4N3AkmY82-l4IHSE1cIBBnFjdI/s640/firstpersonangrybirds.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: xx-small; text-align: start;">First person Angry Birds. There be monkeys on top of them towers for you to send plumetting to their deaths. All gameobjects are primitives.</span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsSUKbKqUOPbN-eUaDEvZJcJ__a1gNvkfJi3xf3z7FqF4lMgTaKMRYvUJ_7_nOxdvXcupLq2v4iakmJ7B7oRhF2mG9iMwv61xri0mCMWHGGY_2c283oZUpD5FD6LwnTElbayvcsNKtGUY/s1600/jumping_guy.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="338" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsSUKbKqUOPbN-eUaDEvZJcJ__a1gNvkfJi3xf3z7FqF4lMgTaKMRYvUJ_7_nOxdvXcupLq2v4iakmJ7B7oRhF2mG9iMwv61xri0mCMWHGGY_2c283oZUpD5FD6LwnTElbayvcsNKtGUY/s640/jumping_guy.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Jumping Game - just jump as high as you can without falling. Spiders and Fire will kill you. Using free Asset Store models</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG124G7xyvHL0bagSNAGkMIUpn597Muyo25aobLfUutBeVSn3-Q8icqcOy0lF6E6Yrk2zsSP0o61AB1hgJZaoj09vQ8Z6aFw2SJ8fEtcgijgCSeK13tqie25_pOxk62GfwOIkQx-iy0EU/s1600/BrainCatcher.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="328" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG124G7xyvHL0bagSNAGkMIUpn597Muyo25aobLfUutBeVSn3-Q8icqcOy0lF6E6Yrk2zsSP0o61AB1hgJZaoj09vQ8Z6aFw2SJ8fEtcgijgCSeK13tqie25_pOxk62GfwOIkQx-iy0EU/s640/BrainCatcher.PNG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Brains drop from above and you catch them in the crate. You get a point for every brain collected. Please note the excessive use of particle effects in this scene. Using free Asset store models.<br />
<br />
<br />
<div style="text-align: left;">
So far, basic games. The core mechanic in each has the potential to be commercial successful, but only with significant investment in the art department. You have to catch and hold the eyes and ears of the demographic likely to spend any kind of money for such a simple game. The other key to success with this kind of game is the level of social interaction it provides - updates to Facebook, Twitter, etc. This is an area I have zero experience in.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
The next step is to consider some more sophisticated game mechanics. Things like random level layouts add re-playability to a game. I tried that out next, the result is this maze generator. It's not really a 'maze' thats being generated, but I couldnt think of a better word to describe it. If you want to follow along, I think it's a good start for your own levels or just learning how to do stuff if you are just starting to peek under the hood of Unity.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Create a new scene.</div>
<div style="text-align: left;">
Create an empty GameObject and position it at 0,0,0. Rename it to Maze Generator</div>
<div style="text-align: left;">
Attach the following script to it:</div>
<div style="text-align: left;">
<br />
<br /></div>
<div style="text-align: left;">
<br />
<span style="font-size: xx-small;">using UnityEngine;</span><br />
<span style="font-size: xx-small;">using System.Collections;</span><br />
<span style="font-size: xx-small;">using System.Collections.Generic;</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">public class Maze : MonoBehaviour {</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Transform playerPrefab;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>internal Vector3 mazeOrigin = Vector3.zero;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public static int MazeWidth = 10; //cubes across</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public static int MazeHeight = 10;//cubes down</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public static int ChanceofWall = 25;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public int PlayerStartX = 1;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public int PlayerStartY = 1;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public static Texture WallMaterial;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public static Texture FloorMaterial;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public int[,] MazeLayout;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>internal List<GameObject> cubes;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Awake()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeLayout = new int[MazeWidth, MazeHeight];</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cubes = new List<GameObject>(); </span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Start () </span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>this.transform.position = mazeOrigin;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MakeFloor();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MakeBoundaries();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MakeLayout();</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>PlacePlayer();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void MakeFloor()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int x = 0; x < MazeLayout.GetLength(0); x++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int y = 0; y < MazeLayout.GetLength(1); y++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 pos = new Vector3(mazeOrigin.x + x, -1f, mazeOrigin.y + y);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.position = pos;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.tag = "Floor";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.renderer.material.mainTexture = FloorMaterial;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.parent = this.transform;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cubes.Add(cube);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void MakeBoundaries()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int x = 0; x < MazeLayout.GetLength(0); x++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int y = 0; y < MazeLayout.GetLength(1); y++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(x==0 || y == 0 || x == MazeWidth - 1 || y == MazeHeight - 1)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 pos = new Vector3(mazeOrigin.x + x, 0, mazeOrigin.y + y);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.position = pos;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.tag = "Wall";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.renderer.material.mainTexture = WallMaterial;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.parent = this.transform;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cubes.Add(cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void MakeLayout()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int x = 0; x < MazeLayout.GetLength(0); x++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(int y = 0; y < MazeLayout.GetLength(1); y++)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(x > 1 && y > 1 && x < MazeWidth -2 && y < MazeHeight -2)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int wall = Random.Range(0, 100);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(wall<ChanceofWall)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Vector3 pos = new Vector3(mazeOrigin.x + x, 0, mazeOrigin.y + y);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.position = pos;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.tag = "Wall";</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.renderer.material.mainTexture = WallMaterial;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cube.transform.parent = this.transform;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cubes.Add(cube);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void PlacePlayer()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Instantiate(playerPrefab, new Vector3(PlayerStartX, 0.1f, PlayerStartY), Quaternion.identity);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;">}</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: x-small;">I made a player prefab out of a cylinder. I also moved the camera directly above the cylinder, pointing directly downwards and made it a child of the player object. This will cause it to always follow the player. Assign the player prefab to the Maze script in the inspector. Add a character controller component. Attach the following script to the Player object (contains controls for keyboard and xbox gamepad movement)</span><br />
<br />
<span style="font-size: xx-small;">using UnityEngine;</span><br />
<span style="font-size: xx-small;">using System.Collections;</span><br />
<span style="font-size: xx-small;"><br /></span>
<span style="font-size: xx-small;">[RequireComponent(typeof(AudioSource))]</span><br />
<span style="font-size: xx-small;">public class Controller : MonoBehaviour {</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public float MovementSpeed = 6.0f;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public float RotationSpeed = 100f;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public float JumpSpeed = 16.0f;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public float Gravity = 20.0f;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private Vector3 moveDirection = Vector3.zero;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void FixedUpdate ()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>checkMovement();</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void checkMovement()</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CharacterController controller = GetComponent<CharacterController>();</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (controller.isGrounded)</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection = transform.TransformDirection(moveDirection);</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection *= MovementSpeed;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (Input.GetButton("Jump"))</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-size: xx-small;"> moveDirection.y = JumpSpeed;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>moveDirection.y -= Gravity * Time.deltaTime;</span><br />
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>controller.Move(moveDirection * Time.deltaTime);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-tab-span" style="font-size: xx-small; white-space: pre;"> </span><span style="font-size: xx-small;">}</span><br />
<span style="font-size: xx-small;">}</span><br />
<br />
<br /></div>
<div style="text-align: left;">
<br />
At this point, if you run it, you will see a 10x10 maze with white textures. I made WallMaterial and FloorMaterial static members because I needed to access them from a setup menu I made. If you do not intend to also create the setup scene then you will need to assign textures to those members yourself. If you remove the static prefix they will show up in the inspector. The setup screen will allow you to adjust the height and width of the generated maze, adjust the chance that a wall will appear, and select the textures to use on the walls and floor.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Creating the setup screen.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Download the texture pack at <a href="https://www.assetstore.unity3d.com/#/content/351" style="text-align: center;">https://www.assetstore.unity3d.com/#/content/351</a></div>
<div style="text-align: left;">
Create a folder in the root of your project called Resources. Drag each texture into this folder.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg39DTg00AmaUw_9PbOnLBy07XKEJ6eXIdCxti8z2-2AFfCW7KqQnXTqTFriMzWdenp5_pvrjXA98yT7-yT1np3_jESCnHhF2zQNDe4HqNlUtjVU8TA0V5XZqLaCrReaTr5pThg83yN0X8/s1600/resources.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg39DTg00AmaUw_9PbOnLBy07XKEJ6eXIdCxti8z2-2AFfCW7KqQnXTqTFriMzWdenp5_pvrjXA98yT7-yT1np3_jESCnHhF2zQNDe4HqNlUtjVU8TA0V5XZqLaCrReaTr5pThg83yN0X8/s1600/resources.PNG" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Create a new scene</div>
<div style="text-align: left;">
Create an empty game object, call it GUIObject.</div>
<div style="text-align: left;">
Attach the following script to it:</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
</div>
<div style="text-align: left;">
<span style="font-size: xx-small;">using UnityEngine;</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;">using System.Collections;</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;">using System.Collections.Generic;</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;">public class GUIScript : MonoBehaviour {</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>public Texture2D icon;</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private List<Texture> walltextures;</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private List<Texture> floortextures;</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private List<string> wallnames;</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>private List<string> floornames;</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void Start () {</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>walltextures = new List<Texture>();</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floortextures = new List<Texture>();</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames = new List<string>();</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames = new List<string>();</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate01");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate01b");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate02");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate02b");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate03");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Crate04");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Wall01");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Wall02");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("Rock01");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>wallnames.Add("ScifiPanel03");</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Floor01");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Floor02");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Floor03");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Floor04");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("MetalBasic01");<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Rock02");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Rock03");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("Rock04");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("ScifiPanel01");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floornames.Add("ScifiPanel02");</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>loadTextures();</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void OnGUI()</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//Make Background Box</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Box (new Rect(10,10,670,300), "Maze Setup");</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#region Height and Width</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(15,35,80, 20), "Maze Width");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(105, 35, 20, 20), "-"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.MazeWidth--;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(125, 35, 20, 20), "+"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.MazeWidth++;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(150, 35, 30,20), MazeSettings.MazeWidth.ToString());</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(15,55,80, 20), "Maze Height");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(105, 55, 20, 20), "-"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.MazeHeight--;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(125, 55, 20, 20), "+"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.MazeHeight++;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(150, 55, 30, 20), MazeSettings.MazeHeight.ToString());</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#endregion</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#region Randoms</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(15, 75, 110, 20), "Chance of Wall");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(105, 75, 20, 20), "-"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.ChanceofWall--;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(125, 75, 20, 20), "+"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.ChanceofWall++;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(150, 75, 100, 20), MazeSettings.ChanceofWall.ToString() + "%");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#endregion</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#region Textures</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(15, 95, 100, 20), "Wall Texture");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15, 115, 64, 64), walltextures[0]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[0];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64, 115, 64, 64), walltextures[1]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[1];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 2, 115, 64, 64), walltextures[2]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[2];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 3, 115, 64, 64), walltextures[3]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[3];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 4, 115, 64, 64), walltextures[4]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[4];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 5, 115, 64, 64), walltextures[5]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[5];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 6, 115, 64, 64), walltextures[6]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[6];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 7, 115, 64, 64), walltextures[7]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[7];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 8, 115, 64, 64), walltextures[8]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[8];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 9, 115, 64, 64), walltextures[9]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.WallMaterial = walltextures[9];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>GUI.Label(new Rect(15, 95 + 84, 100, 20), "Floor Texture");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15, 199, 64, 64), floortextures[0]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[0];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64, 199, 64, 64), floortextures[1]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[1];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 2, 199, 64, 64), floortextures[2]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[2];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 3, 199, 64, 64), floortextures[3]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[3];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 4, 199, 64, 64), floortextures[4]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[4];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 5, 199, 64, 64), floortextures[5]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[5];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 6, 199, 64, 64), floortextures[6]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[6];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 7, 199, 64, 64), floortextures[7]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[7];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 8, 199, 64, 64), floortextures[8]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[8];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15 + 64 * 9, 199, 64, 64), floortextures[9]))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MazeSettings.FloorMaterial = floortextures[9];</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>#endregion</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(GUI.Button(new Rect(15, 275, 110, 20), "Generate Maze"))</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Application.LoadLevel("maze");</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>void loadTextures()</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>foreach(string name in floornames)</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>floortextures.Add(Resources.Load(name) as Texture);<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-size: xx-small;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>foreach(string name in wallnames)</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>walltextures.Add(Resources.Load(name) as Texture);<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div>
<div style="text-align: left;">
<span style="font-size: xx-small;">}</span></div>
<br />
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
The string being entered into wallnames and floornames must match the names in the resources folder. The resources folder is required to load assets on the fly. You will need to adjust the line near the end '<span style="font-size: xx-small;">Application.LoadLevel("maze");'. </span><span style="font-size: x-small;">Replace</span><span style="font-size: xx-small;"> </span><span style="font-size: x-small;">maze with the name of the scene you just saved. Set this setup scene as the default scene.</span></div>
<div style="text-align: left;">
<span style="font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaTaD629KfcRxqE2UNI2mJSUpOIcEZs3esyJATDN2ikjiYouoq_s6tCg04WfVXmd3fj-6smCDkfVRTDok17I1Dp2_l0ONSpWyeGvOzuqCY6_RniXRf7Lne-SYuOHGFQFFpd6xFNRUYxLc/s1600/mazesetup.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaTaD629KfcRxqE2UNI2mJSUpOIcEZs3esyJATDN2ikjiYouoq_s6tCg04WfVXmd3fj-6smCDkfVRTDok17I1Dp2_l0ONSpWyeGvOzuqCY6_RniXRf7Lne-SYuOHGFQFFpd6xFNRUYxLc/s320/mazesetup.PNG" width="320" /></a></div>
<div style="text-align: center;">
<span style="font-size: x-small;">Setup Screen</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdVsTjTedQ3PqGlR096qVHeZLuxmJF-ks8qiW-BJyhQg4-qJTA9PD5Pwwt3fDDqbGt7xG1OX_3xDUCAuEEEklgwTDSMGNG8wGjQoaO5g8S9eHxwKLrTHPAbEKoeEGs959iOQtZ97Eszq0/s1600/maze2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="217" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdVsTjTedQ3PqGlR096qVHeZLuxmJF-ks8qiW-BJyhQg4-qJTA9PD5Pwwt3fDDqbGt7xG1OX_3xDUCAuEEEklgwTDSMGNG8wGjQoaO5g8S9eHxwKLrTHPAbEKoeEGs959iOQtZ97Eszq0/s320/maze2.PNG" width="320" /></a></div>
Game View. Notice the camera is position above the player and looking straight down.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjorrp7TiAauEf9oZRry0EmiOGx_k9V1cvimUMDVVvXAuEwb0Xtu3oIPZKSpIDNpRd5ccDniVC0rJmQmQOyWLGO3h-AimOGHTJPSLYvN_-3DnNO_H00y3PeOZgsJfAzcorpgua0wZCkemU/s1600/maze30x30.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="214" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjorrp7TiAauEf9oZRry0EmiOGx_k9V1cvimUMDVVvXAuEwb0Xtu3oIPZKSpIDNpRd5ccDniVC0rJmQmQOyWLGO3h-AimOGHTJPSLYvN_-3DnNO_H00y3PeOZgsJfAzcorpgua0wZCkemU/s320/maze30x30.PNG" width="320" /></a></div>
30x30 maze seen from scene view<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxg_ICAjm13AFgyJiVh5P1mniTmzbXudEO3WtTzxb-aaICXoOwPSuf7exdZFgv4oTspeblJmbKj7gyp2rOBen73XtH8i0eR_jJ1k-peEWnZdMUCjim4P6q8nEWHEIaH3aK2zvV-Sv4OSI/s1600/maze150x150.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxg_ICAjm13AFgyJiVh5P1mniTmzbXudEO3WtTzxb-aaICXoOwPSuf7exdZFgv4oTspeblJmbKj7gyp2rOBen73XtH8i0eR_jJ1k-peEWnZdMUCjim4P6q8nEWHEIaH3aK2zvV-Sv4OSI/s320/maze150x150.PNG" width="320" /></a></div>
150x150 maze seen from scene view<br />
<br />
<br />
<br />
<br /></td></tr>
</tbody></table>
<br />Adohttp://www.blogger.com/profile/17837009382065679085noreply@blogger.com0tag:blogger.com,1999:blog-8077726125007140137.post-73656660849544765692013-05-14T18:43:00.003-07:002013-05-14T18:43:49.616-07:00Defining ContextMenus for ListView Items in Xamarin AndroidWhile working on my Android app I had need to display a list of items with position-dependent context menus. It took me awhile to develop a clean solution so I'd like to share my work with anyone who would like dynamic menus available on their ListViews that display over items using a long-press.<br />
<br />
Inside of my Activity class I have declared three important variables:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">private</span> <span class="type">ListView</span> itemList;
<span class="keyword">private</span> <span class="keyword">int</span> selectedItemNumber;
<span class="keyword">private</span> <span class="keyword">string</span> selectedItemText;</pre>
</div>
<br />
What each variable tracks should be self explanatory from the declaration, but please comment if you have questions on anything in my posts. The reason it's important to declare these within scope of the Activity class and not within a method is because we lose focus of what ListView item is being interacted with in-between the step of creating a menu and when that menu is used. There might be a way to extract that information from the second step, but none was obvious to me and I found the approach of using private variables an easy solution. <br />
<br />
In addition to those three variables I've also created constant values to track the int-based menu options:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">private</span> <span class="keyword">const</span> <span class="keyword">int</span> EDIT_ITEM = 0;
<span class="keyword">private</span> <span class="keyword">const</span> <span class="keyword">int</span> VIEW_ITEM = 1;
<span class="keyword">private</span> <span class="keyword">const</span> <span class="keyword">int</span> DELETE_ITEM = 2;
</pre>
</div>
<br />
These allow me to refer to actions in a clear way in the code. In the <span style="background-color: #f0f0f0;">OnCreate</span> method of my Activity there are two important steps needed to use context menus:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">protected</span> <span class="keyword">override</span> <span class="keyword">void</span> OnCreate (<span class="type">Bundle</span> bundle)
{
<span class="keyword">base</span>.OnCreate (bundle);
SetContentView (Resource.<span class="type">Layout</span>.SendTickets);
<span class="comment">//Two important steps to for my context menus</span>
itemList = (<span class="type">ListView</span>) FindViewById(Resource.Id.myListViewName);
RegisterForContextMenu(itemList);
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
Now that I've associated my ListView with a private variable and have registered it for ContextMenus I only have to define two additional methods for everything to work. The first is the method that is triggered when an item is selected because of the <span style="background-color: #f0f0f0;">RegisterForContextMenu</span> call made in <span style="background-color: #f0f0f0;">OnCreate</span>, and it creates the menu that is displayed:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> OnCreateContextMenu(<span class="type">IContextMenu</span> menu, <span class="type">View</span> v, <span class="type">IContextMenuContextMenuInfo</span> info)
{
AdapterView<span class="type">AdapterContextMenuInfo</span> menuInfo = (AdapterView.<span class="type">AdapterContextMenuInfo</span>) info;
selectedItemText = ((TextView) menuInfo.TargetView).<span class="type">Text</span>;
selectedItemId = menuInfo.Id;
<span class="comment">//My listview is set to have a "No Data" item on the first row if it's empty</span>
<span class="keyword">if</span> (!selectedTicketText.Equals(<span class="string">"No Data"</span>))
{
menu.SetHeaderTitle(<span class="string">"My Menu Header"</span>);
<span class="comment">//All items can be viewed</span>
menu.Add(0, VIEW_ITEM, 0, <span class="string">"View Item"</span>);
<span class="comment">//But only the first item in the list can be edited</span>
<span class="keyword">if</span> (selectedItemId== 0)
menu.Add(0, EDIT_ITEM, 0, <span class="string">"Edit Item"</span>);
<span class="keyword">if</span> (!selectedTicketText.Contains (<span class="string">"Words that mean it can be deleted"</span>))
menu.Add (0, DELETE_ITEM, 0, <span class="string">"Delete Item"</span>);
}
<span class="keyword">else</span> <span class="comment">//This won't create any menu at all</span>
{
menu.SetHeaderTitle(<span class="string">"No Options"</span>);
}
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
Okay, so now my menu will show up and it will look different based on what text the item in the ListView contains, and what item number it is assigned, which is the 0-based index in the listview. You can see in my menu code above that I have added the ability to View to any-and-all items, but only the first item in the list can be edited, and only items containing my special text can be deleted.<br />
<br />
The last step is to specify what actions occur when the menu is used. We do this in the <span style="background-color: #f0f0f0;">OnContextItemSelected</span> method:<br />
<br />
<div class="csharpcode">
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; color: black; overflow-x: auto; overflow-y: hidden; padding: 0px; text-align: left; word-wrap: normal;"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">bool</span> OnContextItemSelected(<span class="type">IMenuItem</span> item)
{
<span class="keyword">if</span> (item.ItemId.Equals (VIEW_ITEM))
{
MethodThatViewsMyItem(selectedItemText);
}
<span class="keyword">else</span> <span class="keyword">if</span> (item.ItemId.Equals(EDIT_ITEM))
{
MethodThatEditsMyItem(selectedItemNumber);
}
<span class="keyword">else</span> <span class="keyword">if</span> (item.ItemId.Equals(DELETE_ITEM))
{
MethodThatDeletesMyItem(selectedItemNumber);
}
<span class="keyword">return</span> base.OnOptionsItemSelected(item);
}<!--[if IE]>
<![endif]--></pre>
</div>
<br />
This is where the information captured as selectedItemText and selectedItemNumber from <span style="background-color: #f0f0f0;">OnCreateContextMenu</span> comes in handy. Since this method only has access to the item that was clicked, and that IMenuItem contains no information about the ListView item we have to refer to our Activity-scope variables selectedItemText and selectedItemNumber.<br />
<br />
As always, feel free to post questions or comments, even if it's to suggest a better way of doing this!Jaredhttp://www.blogger.com/profile/00323032321674321584noreply@blogger.com0Utah, USA39.3209801 -111.0937311000000133.0545611 -121.4208796 45.5873991 -100.76658260000002