code refactoring and improvement

add more "Unity" way of handling static object
add RequireComponent to ensure that object have mesh and texture
add some handling of empty texture on objects
removed repetition from code
set all formatting to be the same
This commit is contained in:
aliaksei.kalosha
2025-03-18 01:11:45 +01:00
parent 3e914ac71f
commit e2a9c13fe5
4 changed files with 153 additions and 166 deletions

View File

@@ -74,9 +74,9 @@ namespace SplashEdit.RuntimeCode
int atlasWidth = group.Key switch
{
PSXBPP.TEX_16BIT => 256,
PSXBPP.TEX_8BIT => 128,
PSXBPP.TEX_4BIT => 64,
_ => 256
PSXBPP.TEX_8BIT => 128,
PSXBPP.TEX_4BIT => 64,
_ => 256
};
// Create a new atlas for this group.
@@ -87,7 +87,7 @@ namespace SplashEdit.RuntimeCode
foreach (var obj in group.OrderByDescending(obj => obj.Texture.QuantizedWidth * obj.Texture.Height))
{
// Remove duplicate textures
if (uniqueTextures.Any(tex => tex.OriginalTexture.GetInstanceID() == obj.Texture.OriginalTexture.GetInstanceID() && tex.BitDepth == obj.Texture.BitDepth))
if (uniqueTextures.Where(tex => tex.OriginalTexture != null).Any(tex => tex.OriginalTexture.GetInstanceID() == obj.Texture.OriginalTexture.GetInstanceID() && tex.BitDepth == obj.Texture.BitDepth))
{
obj.Texture = uniqueTextures.First(tex => tex.OriginalTexture.GetInstanceID() == obj.Texture.OriginalTexture.GetInstanceID());
continue;