Learning C# Syntax

I was never ‘taught’ c# – I’ve grown into it from other languages and there are certain nuances and quirky syntax that I might have read/seen at one point or another, but forgotten.  It’s with that in mind that I’m sharing this recent ‘discovery’ by me.

C# has a ?? operator.  It’s kind of like the standard conditional operator ?: but is specifically setup as a null check shortcut.

These two sections of code are functionally equivalent

	parentToggle = gameObject.GetComponent();
	if (parentToggle==null)
		parentToggle = gameObject.GetComponentInParent();
	parentToggle = gameObject.GetComponent() ?? gameObject.GetComponentInParent();

In other words, ‘arg1 ?? arg2’ is the same as saying return arg1, unless arg1 == null in which case return arg2.

You could also use ‘arg1!=null?arg2:arg1’ but the ?? pattern is less typing 🙂

Candy Bubble Drop updated

Icon-180My Candy Bubble Drop update for iOS is now live.  As everyone who submits something to Apple does, I was hoping for some kind of promotion from them, but nothing.  Oh well, maybe next time.

You can check it out in iTunes by following this link.  Now to make a paid ad-free version along with the Android version.

Debugging Unity on Android

Android debugging can be a fairly intense process when using Unity. There are times your app will crash or not work correctly, and finding why can be a real pain.  A couple of things I do to make adb more usable.

Use ‘adb logcat -c’ to clear the logcat buffer.  I’ll do this after killing my app using ‘Advanced Task Killer’.

On the Mac, use CMD-K to clear the Terminal window in which you are running adb.

Use ‘adb logcat -s Unity’ to have logcat only display Unity Debug.Log messages – which you sprinkle throughout your code.  This keeps the logcat display from printing all the normal stuff you see when you run it in it’s default mode.

Unity3D ReorderableList from Rotorz

I wanted to use a List<> object to contain my level information, allowing me to adjust/edit the level data within the editor.  In the past I’ve used CSVs & Excel to create a text list for level information, even using Google Docs to keep an online copy and download it directly into the App when it changes.

This time I wanted to use a GameObject with a bunch of properties and hooks to materials/prefabs that are used to populate each level.  Not sure if it’s the best way to do this, but I like experimenting with various approaches so I can learn what works & what doesn’t.

Then I’d create a list of these level objects in the order they will be used in the game, so if I reuse the same level data, it only needs to exist once, but will occur twice in my list.  The problem I ran into was that editing the list was a real pain.  Unity, by default, will let you duplicate an entry, delete an entry, and overwrite an entry.  Not very flexible.

After a little Google-Fu I came across an editor extension that lets you manipulate a list in the editor with a lot more control.  It’s open source and has great documentation.  You can find it at https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity/overview.

Screen Shot 2015-06-12 at 10.09.03 PMI was able to use it in my project and created a custom editor object that allows it to operate on my list.  You can see from the attached screenshot, that it gives me all the control over the list that I’d want.

I can drag & re-order the entries, I can add new ones, delete existing entries, and even use the handy pop-up for additional actions.

I great tool that will speed up my level editing plans.

Kudos & Thanks to the Rotorz guys.

 

RANT: AT&T Online ordering…

So, this is just a rant.

I wanted to upgrade my old AT&T cellular modem from a USB stick to one of the new fancy WiFi devices – Unite Pro – would let me use the cellular modem across multiple devices at the same time.

Turns out, their online system will not let you order an item unless it’s in stock at your local store??? Seriously, why have an online ordering system that uses your ZIP to determine stock levels – even the customer service folks couldn’t order one online for me.