游戏优化设置
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 initializationvoid Start () {SetCursorPos(200, 200);}// Update is called once per framevoid 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;}
轉載于:https://www.cnblogs.com/white-L/p/6239565.html
總結
- 上一篇: 某熊周刊:一周推荐外文技术资料(12.2
- 下一篇: 回顾2016,展望2017