我有一个非常简单的脚本,它更新我的正交相机在给定的分辨率,以便它准确地缩放视图,以像素完美。
下面是一些相关的代码:
OrthographicSetting get_override(int size)
{
return Overrides.FirstOrDefault(x => x.OrthographicSize == size);
}
void update_ortho()
{
m_last_size = Screen.height;
float ref_size = (OrthographicSize / PixelsPerUnit) * 0.5f;
OrthographicSetting or = get_override(m_last_size);
float ppu = or != null ? or.PixelsPerUnit : PixelsPerUnit;
float ortho_size = (m_last_size / ppu) * 0.5f;
float multiplier = Mathf.Max(1, Mathf.Round(ortho_size / ref_size));
ortho_size /= multiplier;
this.GetComponent<Camera>().orthographicSize = ortho_size;
Debug.Log(m_last_size + " " + ortho_size + " " + multiplier + " " + ppu);
}
[System.Serializable]
public class OrthographicSetting
{
public int OrthographicSize;
public float PixelsPerUnit;
}
OrthographicSetting get_override(int size)
{
return Overrides.FirstOrDefault(x => x.OrthographicSize == size);
}有了这个,我可以为每个解决方案指定一组覆盖。
我目前的设置是每单位使用100像素。我所有的精灵都使用无压缩的点过滤。然而,我仍然得到了奇怪的结果。90%的精灵渲染正常,但有些似乎渲染不正确。
这里有一个截图来说明:

发布于 2018-02-01 08:17:32
我可能已经解决了这个问题。我使用的是开启了像素捕捉的精灵着色器。如果我关闭像素捕捉,这个问题似乎或多或少会消失。我仍然偶尔会遇到游戏对象位置不好的问题,但我不知道如何避免这个问题……
https://stackoverflow.com/questions/48553246
复制相似问题