1.代码方面优化,整合函数,将代码分配到物体上不要全放在主角上,代码清晰。

2.改变camera渲染范围。

3.灯光的使用会增加CPU负担,将光源烘焙为光照贴图,只对static物体有用。Compression。

4.限制鼠标在游戏窗口内功能。

using System.Runtime.InteropServices;

public class shubiao : MonoBehaviour {
    public struct POINTAPI   //POINTAPI是自定义的类名
    {
        public int x;
        public int y;
    }
    //鼠标可以强行冲出窗口,再被代码拉回游戏,效果不是很好
    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(ref POINTAPI p);

    [DllImport("user32.dll")]//导入库,并申明一个命令
    public static extern int SetCursorPos(int x, int y);

    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(ref int x1, ref int y1);
    bool ck = false;
	// Use this for initialization
	void Start () {
        SetCursorPos(200, 200);
	}
	
	// Update is called once per frame
	void Update () {
        if (!ck)
        {
            //if (Input.mousePosition.x < 1) { SetCursorPos(Mathf.RoundToInt(Screen.width * 0.5f), Mathf.RoundToInt(Input.mousePosition.y)); }
            //if (Input.mousePosition.y < 1) { SetCursorPos(Mathf.RoundToInt(Input.mousePosition.x), Mathf.RoundToInt(Screen.height * 0.5f)); }
            //if (Input.mousePosition.x > Screen.width - 5) { SetCursorPos(Mathf.RoundToInt(Screen.width * 0.5f), Mathf.RoundToInt(Input.mousePosition.y)); }
            if (Input.mousePosition.x < 5)
            {
                /*int x1 = 0;
                  int y1 = 0;
                  if (GetCursorPos(ref x1, ref y1))//注意ref用法 
                      SetCursorPos(x1 + 10, y1);   */
                POINTAPI p1 = new POINTAPI();
                if (GetCursorPos(ref p1))
                    SetCursorPos(p1.x + 10, p1.y);        
            }
            if (Input.mousePosition.y < 5)
            {
                /*int x2 = 0;
                  int y2 = 0;
                  if (GetCursorPos(ref x2, ref y2))
                      SetCursorPos(x2, y2 - 10);*/
                POINTAPI p2 = new POINTAPI();
                if (GetCursorPos(ref p2))
                    SetCursorPos(p2.x, p2.y - 10);
            }
            if (Input.mousePosition.x > Screen.width - 5)
            {
                /* int x3 = 0;
                   int y3 = 0;
                   if (GetCursorPos(ref x3, ref y3))
                       SetCursorPos(x3 - 10, y3);*/
                POINTAPI p3 = new POINTAPI();
                if (GetCursorPos(ref p3))
                    SetCursorPos(p3.x - 10, p3.y);
            }
                

        }
	}
    void OnApplicationFocus()
    {
        ck = !ck;
    }