Thursday, 5 September 2019

Unity - Scriptable Wizzard tool to create weapon

Recently I was working on prototype game based on old school isometric games such as Fallout. I wanted to be able to create weapons quickly without having to copy and paste game objects. Using ScriptableWizzard base class helped me to achieve my goal. Thanks to that script I am able to quickly create new weapon from Unity editor.
Full code below.

CreateWeaponWizard must be inside Editor folder.

And Weapon class. Make sure you will place this class outside Editor folder.

Monday, 26 August 2019

Unity - Using editor tool to find all elements with selected tag

So you have 500 objects in your project and some of them have specific tag assigned to them. You want to select them all and perform some modification. There is painful way - go through all objects in hierarchy one by one and check what tag the object have or the second way use unity editor ScriptableWizzard.

I wrote simple class that will enable to you to easily find all elements by the tag name in the editor.

In order for the script to work you need to place in inside Editor folder.

Friday, 9 August 2019

Unity 3d on build screen goes to black

Recently I updated one of my projects - to Unity 2019.1.6f1 and when I run it in unity editor everything was working as expected, however when I build it for desktop and run I got black screen. I could not find solution online even tough I tried all tricks and tips I found. For instance setting Clear Flags on on all camera to Don't clear, reducing texture resolution.
After playing around and scratching my head I realised that I made all cameras into prefabs in my previous version of unity, when I right clicked in project hierarchy window and selected Unpack Prefab Completely it magically started to work again as expected.
Hope that helps someone out there ans save a lot of time.

Wednesday, 3 July 2019

Modern Interior 3d design in Unity 3d

I always wanted to create 3d interior design but always had some other projects in the way. Finally found some spare time and released Modern Interior asset.

Wednesday, 20 March 2019

Different case styles in programming

Camel case 

"theQuickBrownFoxJumpsOverTheLazyDog" or "TheQuickBrownFoxJumpsOverTheLazyDog"
First letter of each word is capitalised. In languages such as C# it is almost imperative to use low case for the first word

Snake case 

Spaces are replaced by underscore. Words can be lower case, upper case or mixed.

Kebab case

Same as Snake case, however underscores are replaced with hyphens.

Studly caps

Complete chaos and pattern whatsoever - use it if you want to offend other programmers. 

Sunday, 17 February 2019

Blender - Quick tips to reduce poly count


 If mesh is made out of quads in edit mode, select the mesh, then ctrl+e and choose Un-Subdivide

Delete Edge Loops

Quite common tactic to reduce poly count in oval shapes objects.
In edit mode select edge loop by pressing alt+right click, then space and type Delete Edge Loop

Limited Dissolve

One of my favorite and quickest techniques. Quickly remove unnecessary vertices without breaking the mesh structure. Still might require some manual adjustment but dramatically reduce poly counts.
We reduced poly count from 49,216 to 436. You can also play with max angle value under limited dissolve menu. It works well on square objects with lots of edge loops.

Decimate modifier

Select object and add Decimate modifier

9750 polygons on the the top photo vs 436 after using decimate modifier.

Wednesday, 6 February 2019

Use of @Input in Angular 6+

According to official angular documentation it declares a data-bound input property.

Let's have a look at this simple example.


The following example creates a component with two input properties.

See the Pen
by Adam Bielecki (@adambielecki)
on CodePen.

Thursday, 31 January 2019

Using Singleton in C#

Singleton is used in application when we want to store consistent unique data in an object disallowing creating a new instances of this object in the same time.

Here are the bullet points that defines Singleton.

  • cannot be instantiated (private constructor instead of public)
  • cannot be inherited (sealed class)
  • public static instance has to be available across the whole application
Singleton concept is quite popular in mobile apps and video games, less in web/desktop applications.

Here is a simple example of Singleton usage.

Wednesday, 30 January 2019

Understanding Predicate delegate with simple example in C#

Predicate is a delegate that always returns boolean value (True or False).

Predicate is used in conjunction with lambda expression.

Below example shows how can we simply replace static method with Predicate.

public class Program
 public static void Main()
  Predicate<int> isGreaterThan5Predicate = m => m > 5;
  Console.WriteLine("Using Predicate to determine condition - 4 is not greater than 5 hence: " + isGreaterThan5Predicate(4));
  Console.WriteLine("Using static method to determine condition - 6 is greater than 5 hence: " + isGreaterThan5(6));

 public static bool isGreaterThan5(int number)
  return number > 5? true: false;

Running above code will produce those messages in the console.

Using Predicate to determine condition - 4 is not greater than 5 hence: False
Using Predicate to determine condition - 6 is greater than 5 hence: True

Wednesday, 12 December 2018

Capturing exceptions with Nunit in .NET

In this tutorial we are going to capture exception that service throw using nUnit test framework. It is quite important writing unit tests or integration tests to be able to specify scenario that will force method to threw an exception so we are prepared for that eventuality.

We are having fruit service that stores info regarding fruit availability in the fridge. 

public class FruitService
    public async Task CheckIfFruitIsInTheFridge(string fruit)
      // To keep it simple call Fridge method. In real environment we would call
      // some external api and we want to create new thread for that.

      var fruitInTheFridge = Fridge(fruit);

      if(fruitInTheFridge == null)
        throw new Exception("Could not find fruit in the fridge."); 

      return await fruitInTheFridge;

    private async Task<string> Fridge(string fruit)
      // Ok beer is not part of the fruit company, but beer must always be in the fridge :)

      List currentfruitsInTheFridge = new List<string> { "Apple", "Pearl", "Beer" };

      return currentfruitsInTheFridge.FirstOrDefault(m => m.Equals(fruit));

Now we are going to run tests.

  public class WhenCallingCheckIfFruitIsInTheFridge
    private FruitService _fruitService;

    public void SetUp()
      this._fruitService = new FruitService();

    public void ItThrowsAnExceptionWhenfruitIsNotFoundInTheFridge()
      var ex = Assert.ThrowsAsync<exception>(async () => await this._fruitService.CheckIfFruitIsInTheFridge("Grapes"));

      Assert.That(ex.Message, Is.EqualTo("Could not find fruit in the fridge."));