Unity3d - 移动相机确实将 FPS 减半?

Unity3d - Moving camera literally cuts FPS in half?

我在 Unity 中遇到相机问题。当相机通过任何方式移动时,它似乎将我的 FPS 减半甚至更多。它在 PC 上并不是很明显,除非我正在查看从 800fps 到大约 150fps 的帧率,但是在移动设备上它会降低我在 Nexus 4 上达到 20fps 的平滑 60fps。这绝对是毁灭性的。

这是我正在使用的相机的属性和脚本,但是如果没有任何这些组件和完全重置的相机组件,这个问题仍然会发生:

public class ViewDrag : MonoBehaviour
{
    public Vector3 hit_position = Vector3.zero;
    public Vector3 current_position = Vector3.zero;
    public Vector3 camera_position = Vector3.zero;
    public Vector2 min_position;
    public Vector2 max_position;
    float z = 0.0f;
    MouseHolder holder;
    hider sidebarHide;

    GameObject gameStructure;

    // Use this for initialization
    void Start()
    {
        gameStructure = GameObject.FindGameObjectWithTag("GameStructure");
        holder = gameStructure.GetComponent<MouseHolder>();
        sidebarHide = GameObject.FindGameObjectWithTag("SidebarBG").GetComponent<hider>();
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            hit_position = Input.mousePosition;
            camera_position = transform.position;

        }
        if (Input.GetMouseButton(0))
        {
            current_position = Input.mousePosition;
            LeftMouseDrag();
        }

        if (!sidebarHide.isHidden)
        {
            //GetComponent<Camera2DFollow>().enabled = true;
        }
        if(gameStructure.GetComponent<ExecuteMovement2>().isExecuted)
        {
            //GetComponent<Camera2DFollow>().enabled = true;
        }
    }

    void LeftMouseDrag()
    {
        // From the Unity3D docs: "The z position is in world units from the camera."  In my case I'm using the y-axis as height
        // with my camera facing back down the y-axis.  You can ignore this when the camera is orthograhic.
        //current_position.z = hit_position.z = camera_position.y;

        // Get direction of movement.  (Note: Don't normalize, the magnitude of change is going to be Vector3.Distance(current_position-hit_position)
        // anyways.  
        Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);

        // Invert direction to that terrain appears to move with the mouse.
        direction = direction * -1;

        Vector3 position = camera_position + direction;

        if (position.x < max_position.x && position.x > min_position.x && position.y < max_position.y && position.y > min_position.y)
        {
            if (!EventSystem.current.IsPointerOverGameObject() && holder.fromSlot == null )
            {
                if (sidebarHide.isHidden)
                {
                    if (!gameStructure.GetComponent<ExecuteMovement2>().isExecuted)
                    {
                        //GetComponent<Camera2DFollow>().enabled = false;
                        transform.position = position;
                    }
                }
            }
        }


    }
}

有没有人知道为什么会发生这种情况,如果不修复它我该如何解决?

通过仔细检查,我认为这与 Canvas 被屏幕 space 有关。但这是需要的。同样,有什么解决方法吗?

查看分析器屏幕截图的评论。

已解决的问题:

在分析器中,我发现 Canvas.SendWillRenderCanvases() 导致了巨大的峰值。我通过在 Canvas 中关闭 Pixel Perfect 完全解决了这个问题。现在像黄油一样光滑。