Monthly Archives: December 2015

Renaming c# classes and Unity…

As far as I know, there is no ‘correct’ way to rename a class that you’ve built inside a Unity C# file with ease and 0 pain…  but there is certainly a wrong way to do it:

Approach it in this order:

Rename the ????.cs file using the Unity Editor.  Click on the file in the project explorer and use what ever method you’d like to rename it to the new class name.  This means that Unity will keep a reference to the newly named file and any instances of that class file attached to objects in the scene will get updated.

Now, open the file in your text editor (Mono, VS, whatever) and use ‘Refactor or Rename’ on the actual class name and let the editor change all references in the project.  Save all the changed files and you should be able to build just fine.

Go back to Unity and the project should build and run without any errors.

If you do what I did – rename the class first in your text editor, then you’ll end up replacing every ‘missing script’ error by hand – not so much fun — you’ve been warned!

Health Insurance… Obamacare & Grinding Gears…

Ok, so I’m not entirely dumb & I’d like to think I’ve got a clue, but oh my goodness, this ObamaCare crap really grinds my gears…

Turns out the plan I selected doesnt support an HSA – why the hell not, I mean, if you’re going to spend any money on medical crap, why the hell would I not use an HSA – so because I selected it via the marketplace, I’ve got to go back to them and wait for hours on hold to figure it out…

Talk about gear grinding…

 

Sorted Hashtable Keys

By default, a hashtable does not keep a sorted list of keys, but sometimes it’s useful to do so.

In order to do this in one line with linq, you’ll need to cast the keys to an array of strings, and then order them as follows:

dailyStatsKeys = dailyStats.Keys.Cast<string>().OrderByx => x).ToList();

or

dailyStatsKeys = dailyStats.Keys.Cast<string>()
.
OrderByDescendingx => x).ToList();

where dailyStats is a hashtable declared and populated elsewhere.

C# System.Func

I needed to create a hook into a class I’m working on that will return a GameObject for a given index.  Now, I could have just built that function into my class, but I’d rather make this class re-usable by other projects down the line (and even other classes within the same project).

public System.Func<int,Transform,TransformrowForRowIndex;

The first two parameters are passed to the function from the calling method, while the third is the returned object.  So in this case, I would invoke the function as follows:

row = rowForRowIndex(r,cachedRow);

Where, r is the index of the row I want to generate, and cachedRow is a row object that has been previously created but is free for use.

You can obviously use different parameters & return type than I am, just remember, the last entry is always the return type, so

public System.Func<bool> isValid;

will return a bool and takes no parameters, while

public System.Func<int,float> rootOfInt;

will return a float and take 1 int as a parameter.

You can also use lambdas to create in-line functions using this syntax:

public System.Func<int,float> rootOfInt = (x) => Mathf.Sqrt(x);

While this is similar to System.Action, the big difference is that System.Func can return a value, System.Action is always type Void.

Fixed it!

Finally got my WP install updated to the latest & greatest… turns out a few files/folders where still owned by root and not www-data so the auto-upgrade feature was unable to work…

Now I just need to figure out my permalink issue and get rid of these ugly ones, but I’ll save that for another day.