Wednesday, 4 November 2015

Dark arts 1: Generics

This week we had the first of our ‘Dark Arts’ sessions with Richard Weeks. Richard is head of a company called Total Monkery that operates from Plymouth and we’ve been lucky enough for him to come in and teach us some industry standard programming methods. Having somebody who runs his own company and has experienced the games industry first hand come in to teach us is an excellent opportunity. While what I’ve learnt so far at University has been essential, Richard is going through ways to make Unity work in ways it normally wouldn’t, hence why these are called ‘Dark Arts’ sessions.


The first session covered generics. This allows us to make custom types for classes, methods and variables which has lots of uses. When used for a class, it allows the user to get the variables and constructors, meaning you can create objects in the generic class from another. When using a generic method, the type of object you want to pass in must be specified before the parameter, this way a single generic method can perform an operation on many varying data types. One example (shown below) is a method to create entities where a list of different entities can all be passed in. Dictionaries can use generics to form lists with a variety of different types by having a generic key with a corresponding value.

In an example we were shown, one method assigned class types and names, while the other passed in a large variety of different types of entities.This is something I could use in my game to make it less prone to errors and easier to work with as a whole.
Entity inheritance example

No comments:

Post a Comment