2015-07-19 51 views
1

我在Unity中遇到了相機問題。當相機通過任何方式移動時,它似乎將我的FPS減半,如果不是更多。這在PC上並不是很明顯,除非我在800fps到150fps之間,但是在移動設備上,它會將Nexus 4上的平滑60fps降低到20fps。這絕對是毀滅性的。Unity3d - 移動攝像頭從字面上將FPS削減一半?

下面是我使用&腳本不過,這問題仍然發生,沒有任何這些組件和一個完全復位相機組件相機的性能:

camera configuration

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正在屏幕空間有關。但它是那種需要的方式。再次,任何解決方法?

查看分析器屏幕截圖的註釋。

+0

您是否嘗試過分析? –

+0

不要傷心。編輯:Woops。只是意識到它現在可供所有統一用戶使用。採取了這個截圖:http://i.imgur.com/NaWSLXt.png尖峯是我移動相機的地方。 –

回答

2

問題就迎刃而解了:

在探查我發現Canvas.SendWillRenderCanvases()是造成巨大的尖峯。我通過關閉畫布中的Pixel Perfect來完全解決問題。現在就像黃油一樣光滑