Hello everyone!
Let's check the progress!
This week I made a sprite size auto adjustment script to improve game performance. First, I created an image resizing script. I was thinking last week that I needed to borrow the power of a painter. However, as a result of devising a reduction method, we came to the conclusion that automatic processing is sufficient. Shadows and lines are reduced using a method that leaves anti-aliasing, and colors are reduced using a method that does not increase the number of colors. Now you can reproduce this with a script and convert with a single button. The state of this work was distributed on Yotube, so please take a look here!

To reduce the sprite's capacity, I need to cut the margins. But in that case I have to set the image pivot separately.

If the pivot is off, the animation will collapse. As you can see, it is rickety. The sprite display used the image component, but this is for UI only and pivot information is not reflected. I found out this week! Correctly, you need to change it to SpriteRenderer, and you need to set all the animation clips again. Regarding the position of the pivot, there is also a method of manually setting one by one on unity, but it is extremely difficult if the number of sprites is large, It's not practical because you have to redo the work every time you change the sprite. A script should be developed to avoid this.
This time we focused on json. json is a file that can exchange information between different software because it can externally save numerical values and coordinate information in text format. Does it have anything to do with Jason in the hockey mask? Since json can also be output from javascript, I decided to record the pivot coordinate information on the Photoshop script. Set the pivot layer on the PSD and calculate the pivot coordinates by checking the number of vertical and horizontal pixels of the sprite. Store the calculated coordinates in an array and record them in a json file in text format. You can read this file with Unity and convert it from text to object to use it as coordinate data. Write the coordinates obtained via metafile to the texture import settings. Since the metafile itself is originally read-only, it doesn't seem to be a very good method, but since unity can't set the pivot with a normal script There is no way.

A sprite sheet combines multiple textures into a single image, It is a technology that reduces the loading load during the game by dividing it again and using it. This requires a high level of coding ability to create, which is beyond my skill set, but thankfully there are some tools available.

・Sprite Atlas: Unity's standard sprite sheet function. It's easy to use, but you can't output a sprite sheet. Also, since the margins cannot be removed to align the pivot, the capacity is allocated for storing the original data.

・Texture Packer: The most famous. Easy to understand and use. The disadvantage is that it costs 10,000 yen. bought. A sprite sheet can be output.
I've spent a lot of time re-pivoting this past week, and it turns out that Texture Packer produces the perfect spritesheet. I have completed the pivot reset script, but there are still some parts where the behavior is unstable. Indie developers can receive a 50% discount for 3 days from the introduction of the trial version.
As a preliminary step to the sprite sheet, texture resizing and png output must be prepared separately. Now that we have processed individual files, let's modify the script so that we can specify a folder and perform batch processing. Unity uses C# as the programming language, but Photoshop uses javascript. But there were many pitfalls here. First of all, js doesn't give me much error warnings. Therefore, it takes time to investigate the cause when it does not work well. In addition, the fact that the description rules are not strict is also a factor in the frequent occurrence of errors. What I experienced this time is that if the variable used exclusively for the for statement is not declared with var, it will be automatically made into a global variable. It took me hours to notice this error because in C# the for statement only variables usually have the same name! I had a hard time, but I completed it successfully.
Most of my time was spent on script development this week, and I didn't get around to testing performance. However, script resizing has been achieved and here are the results.

The image shows the difference in appearance when the script is scaled down. The left is the original size, and in this state it takes 10 minutes to load. The one on the right is shrunk to 25%, and it finishes loading in 10 seconds. However, it does look a little rough. The 50% size that seems to be the most realistic this time will be verified again next week.
Although I expected to deal with sprite load, there are many technical unknowns and I have avoided it until today. However, by using Chat GPT, I was able to develop efficiently. Perhaps I can say that it is a service created to learn programming.
Chat gpt is really great. I will marry them.
That's all today.
Have a nice day!
Rayven Holmes
2023-07-22 00:11:16 +0000 UTC