Wednesday, March 25, 2020

Order in Hierarchy affect drawcall

The whole draw call thing is a pretty complex topic.
Draw calls are essentially based on the number of materials used. So if you have 20 text objects all using the same Font Asset and Material Preset, you will get 1 draw call. On the other hand, if you are using material instances (which masking requires due to how the Stencil works), you will get more draw calls. Although some of the masking materials can batch, using masking typically results in more draw calls. It is also important to note that Dynamic batching must be enabled for batching between material to occur.
There is also a catch with the Canvas system and Sorting Order / Layer and Canvas batching. If you have several objects in a Canvas which are using the same material but not in a sequential order, batching will be break due to how the objects are sorted / batched. So 3 text objects using the same material would be 1 draw call and 3 images using the same texture 1 draw call. However if the hierarchy is text, image, text, image, text, image. You would get 6 draw calls. This is all controlled by Unity.
See the following post which contains additional information. http://digitalnativestudios.com/forum/index.php…

Texture painting

https://codeartist.mx/dynamic-texture-painting/?fbclid=IwAR3pSkvBavPhTDKPbyMaWorY6nD_I1SOFun2sVE-TwyP6ENKfMH7QqfZs2Q

Tuesday, March 10, 2020

Understanding yield keyword in C#

Yield one of the most useful keywords in C# but it’s not used in many cases due to that most of us don’t know about this keyword purpose or how to use it
yield keyword effectively creates a lazy enumeration over collection items that can be much more efficient.
For example, yield return is a .NET sugar to return an IEnumerable with the only needed items.
Code without yield:
class MyItem{public MyItem() { }static public IEnumerable CreateListOfItems(){
return new List {
new MyItem(),
new MyItem(),
new MyItem() };
}
}
Same code using yield:
class MyItem
{
public MyItem() { }static public IEnumerable CreateListOfItems()
{
yield return new MyItem();
yield return new MyItem();
yield return new MyItem();
}
}
The advantage of using yield is that if the function consuming your data simply needs the first item of the collection, the rest of the items won’t be created so it’s more efficient.
The yield operator allows the creation of items as it is demanded. That’s a good reason to use it.
For example, if your foreach loop iterates over just the first 3 items of 2 million items then that’s all yield returns, and you didn’t build up a collection of 2 million items internally first. Likewise you will want to use yield with IEnumerable return values in your own programming scenarios to achieve the same efficiencies.
Another example: inefficient code that call method that returns list of million item but we actually need the first 3 items:
// Method returns all  million items before anything can loop over them. 
List<object> GetAllItems() {
    List<object> millionCustomers = GetMillionCustomerFromDatabase(); 
    return millionCustomers;
}// Caller code sample:
int num = 0;
foreach(var item in GetAllItems())  {
    num++;
    if (num == 3)
        break;
}
// Note: One million items returned, but only 5 used.
To solve this issue we will simply using yield keyword:
// Yields items one at a time as the caller's foreach loop requests them
IEnumerable<object> IterateOverItems() {
    for (int i; i < database.Customers.Count(); ++i)
        yield return database.Customers[i];
}// Caller code sample:
int num = 0;
foreach(var itm in IterateOverItems())  {
    num++;
    if (num == 3)
        break;
}
// Note: Only 3 items were yielded and used out of the million.

Monday, March 9, 2020

Slay the Spire Map in Unity


https://github.com/silverua/slay-the-spire-map-in-unity?fbclid=IwAR3Bi4KcYK4bl-WsztI5iQlQ3r6MSxEDJNl3Arzyv3PeyHj5rNUiOnJ2JIA



This repo contains an implementation of the Slay the Spire Map in Unity3d. Key features:
  • Pick any orientation (left to right, right to left, top to bottom, bottom to top)
  • Map appearance and player position get saved between game sessions
  • Node position randomization
  • Cross nodes elimination
  • Scrolling map content for long maps
Free resources and assets used in the project: