I’m trying to achieve a level editor behavior working with pixeled png to create stages, but I’ve found a strange behavior when I getting pixels from image and don’t found some info about it. I’ve annexed a small scene to show the problem.
-
Let’s use a simple 3x1 image with a red pixel between 2 transparent pixels
-
The method that read png
public class LevelEditor : MonoBehaviour
{
public Texture2D level;
public void CreateMap()
{
for (int y = 0; y < level.height; y++)
for (int x = 0; x < level.width; x++)
Debug.Log($"[{x}, {y}] -> {level.GetPixel(x, y)}");
}
}
- I’ve created a simple button to call CreateMap in playing mode
[CustomEditor(typeof(LevelEditor))]
public class LevelEditorEditor : Editor
{
public LevelEditor _target
{
get => (LevelEditor)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
GUI.enabled = Application.isPlaying;
if (GUILayout.Button("Create map"))
_target.CreateMap();
}
}
-
Texture import settings
-
Log that appears when running
So, all pixels are red, but some are invisible and some not… I think that i’m making something wrong in import settings but don’t found what.
Obs:
- If I change the block to any color, the problem persists
- I can workaround now that I know that the problem is in alpha, but is this the expected behavior?
Hope that someone can help me
Tnks