0%

Some issues about Unity and their solutions

I have to say that Unity is a good game engine, but not the best! Unity offers all basic functionality that you need, but if you want to achive you requirement, you must do many extra works. From this perspective, Unity is a bit like C programming language.

2D Map

One month ago, I wrote a tilemap generator. I was going to generate some basic 2D maps by this tool. But recently I realised that I shouldn’t use a MonoBehaviour to generate 2D maps because the generation of terrain should be done by brushes, and that sounds more rational. So how to do that? The answer is Scriptable Brushes. So I created a couple of brushes to do that, and of course, using brushes to generate maps is more flexible than using a MonoBehaviour because you can paint or erase specific areas.

ChunkBrush

2D Frame Animation

So the next problem is Frame Animation. Just like the walking animation, 2D artists usually paint all frames releated to the walking animation into a sprite sheet. For example, in the sprite sheet below, it contains many animations releated to different skin color, and the number of sprites is 3135!

A example sprite sheet

The problem is, should I drag sprites from the sprite sheet and create animation clips one by one? That’s incredible! This means I have to perform the same operation - dragging - at least 3135 times. In fact, one asset package usually contains dozens of such sprite sheets to support character customization. This means you also have to create a basic animator controller and thousands of override controller of the basic controller! So I wrote severals script to do that and finally I got almost 2500 controllers in a few minutes. Without that, it could have taken me months to create these controllers. The below script snippet may be useful to you, which could save you tons of time in the process of creating thousands of controllers. Btw, try-catch is not necessary but is recommended.

1
2
3
4
5
6
7
8
9
10
11
12
13
try {
AssetDatabase.StartAssetEditing();
for (int i=0; i<frameAnimations.Count; i++) {
AnimationDetail detail = frameAnimations[i];
AnimationClip clip = CreateAnimationClip(detail);
AssetDatabase.CreateAsset(clip, $"{rootPath}/{detail.animName}.anim");
}
}
finally {
//AssetDatabase.SaveAssets();
AssetDatabase.StopAssetEditing();
//AssetDatabase.Refresh();
}

Selecting multiple sprites in the Sprite Editor

Feature request: selecting multiple sprites in the sprite editor

The Sprite Editor doesn’t support multiple selections! That’s unbelivable! I’d like to ask the Unity development team, What are you doing every day? There are many such feature requests in Unity forum, but after so many years, the Sprite Editor still doestn’t support that operation! And the offical document doesn’t give you any useful information. So I have to read the source code of the Sprite Editor. Finally I made an extension module of the Sprite Editor. Actually, if the Unity development team provides enough information in the documentation, it is not difficult to make an extension module for the Sprite Editor, and I think that ISpriteEditorDataProvider already provides everything for creating an Sprite Editor.

TileSetEditor

Making Rule Tiles

I wrote a Rule Tile maker to make rule tiles based on the QuickRuleTileEditor, but making rule tiles should be done in the Sprite Editor, isn’t it? After making TileSetEditor, I realised that making a rule tile editor is very easy! Just remove some code from TileSetEditor.

RuleTileEditor