Testing in Unity3d – Part 1

I don’t like writing tests. Do you? Well, ok, what I actually mean is that I don’t like writing unit tests. In one of my projects the assumption (and TeamCity setting) was that we’ll have 100% test coverage. There was no .net core yet, so we couldn’t write functional tests actually checking the integrations between different parts of the system and therefore we had to mock them. Oh boy, and we mocked them hard! Because of the requirement to have 100% of the code covered by tests, we had many tests doing no more than checking those mocks, because some methods were only reaching to multiple microservices and the results aggregation was done one layer above that. That’s what you get in most big enough codebases and our client wasn’t really keen on refactoring. So yep, I hated that period of time in my career (it’s actually just a tip of an iceberg, but that would be a topic for another, long post 😉 ).

Continue reading “Testing in Unity3d – Part 1”

Checking if a Transform is behind another Transform in Unity3d

The title is a bit misleading, because what I’m actually trying to figure out today is if a Transform sees another one from behind. The reason why I used this title is because I saw a lot of people asking questions formulated like the topic of this entry when they were actually trying to find a way to check if their game characters saw the backs of their opponents. The most popular SO / Unity forum answers only mentioned the Vector3.Dot method which is insufficient in this case.

Continue reading “Checking if a Transform is behind another Transform in Unity3d”

RPG – like formation algorithm

Well, it’s about time I wrote something Unity-related, eh? This time, from the depths of my disk, I’m pulling out a thing called a formation algorithm. For the sake of simplicity it’s designed for a team of three characters. Ok, you got me – for the sake of simplicity and also because that’s how I’m doing it in my amateur project 🙂

Continue reading “RPG – like formation algorithm”

Coloring HTML5 canvas regions on mouse over – Part 1

It’s gonna be about JS. Well, the blog name says MOSTLY Unity right? 😉

Some time ago I had a client who had a very fun request. He wanted to be able to upload an image of a thing – let it be a piece of furniture or anything else – and while hovering over that image, the user would see a tooltip with information about the specific part he would be pointing at with his mouse. Fun, right? Long story short, after some tough negotiations I explained that given the timeframe it’s impossible or at least impossibly hard to make a component that would allow his company to upload just any image containing different colors, shapes etc. and create an algorithm that would recognize sections of that image in order for the client employees to label and describe them. I mean, yeah, we could probably achieve something with AI… Anyway, it all boiled down to uploading just a template that would contain only one color + transparency. Then my client would be able to mark a given section of that template as anything and everything.

In this (and the upcoming one) article, I will present you a minimal version of the code I used. Continue reading “Coloring HTML5 canvas regions on mouse over – Part 1”