Hey Guys & Gals,
It's been a long while since our last update. Our sincere apologies to the two dozen awesome people who cared enough to press the 'Follow' button. We have promised ourselves (new year resolution kind of thing) to start showing some work for a change and with any luck these weekly updates will keep on coming.
So, lots of stuff has happened over the past few months but rather than going over all the iterations and failures we've suffered through I'm going to concentrate on something that has actually survived the upgrade to Unity 5 and more importantly the internal project reboot as it were.
World Chunks or what we lovingly call the Super Duper Randomiser!
WC (funny name I know) is a cool little thingy we wrote for Double Barrelled and its purpose is to randomise stuff obviously. Originally we only wanted to use it to randomise locations and contents of various loot drops but eventually the whole thing mutated into something a little more generic. Once that happened it was pretty easy to get it to randomise the level geometry.
It's not a random dungeon generator kind of thing by any stretch of imagination. To be honest we didn't want it to be that anyways. Its purpose is to make things look different enough to players running the some zone for the umpteenth time while maintaining the original structural integrity of the level as it was designed.
So here is what a slightly randomised level section looks like in the editor and subsequent play throughs.
It's actually pretty cool how the whole thing works. Those of you who are working with Unity might find the next few paragraphs interesting or lame depending on how much you hate XML.
Firstly, due to some peculiarities with how Unity handles resources we need to create a manifest of all the resources available to us at runtime. This is mainly due to the fact that the levels will not be constructed to the full extent at design time hence some of the stuff will need to be loaded at runtime.
To do this we have a manager that handles all manifest related stuff and it looks something like this :
As you can see there is a filter set for some resources to be excluded. We use regular expressions that support wildcards to create filters in order to manage resources with in the World Chunks system.
Once created the manifest looks something like this :
Nothing more than a simple XML file listing of all of the found resources and their full paths. This is the tricky bit really. Unity has a habit hiding the origins of the resources it shoved into the build unless you know where to look for them. This makes runtime selection a bit of a hassle since you don't define your selection patterns at runtime :)
Basically we keep the full paths in the manifest so that we can run regexs to pattern match the paths we are interested in. At runtime the WC system feeds these back to Unity which happily fetches the resources from disk since we gave it the right path to look for them. Best part is that we can have resources with the same name (as long as they are in different folders) and then load them by name alone completely skipping entire path segments. Sounds convoluted but it isn't when you think about it.
Why XML? Because XML is like violence... if it doesn't solve your problem you ain't using enough of it!
Anywho, once this mumbo jumbo is set up we can start adding chunks into the scenes. This is where it starts to get FUN! All we need to do at this point is create an empty game object and add the World Chunk component to it. Like so :
As you can see nothing terribly complicated. A simple list of name patterns of the resource you would like to load and the probability of that particular pattern getting selected over the others in the group. The patterns also support wildcards and just like any other path in the World Chunks system get passed to a regex function.
Despite the simplicity of the system the end result can be quite complex. Putting a few nested chunks and some elaborate search patterns together will let you create some truly awesome stuff.
While the system is not able to generate much on its own it is still quite cable of generating gorgeous randomised mess :D
In the near future we are planing to add linked chunks and look up sheets for resource combinations. These two features will let level designers create some mind bending stuff. Linked chunks will let us chain together resource selections and look up sheets will make it possible to create relationships between loaded chunks and those currently being selected.
We've been considering putting this system on the Asset Store in the near future so if you have any question or perhaps feature requests before this thing hits the market let us know.
That's about it for this week. We will be back with more nonsense soon enough.