• 游戏优化设置


    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;
        }
    

      

  • 相关阅读:
    【Linux】防火墙命令
    【MySQL】mysql分组后重命名
    【SpringBoot】全局配置Long转String,解决前端接收时精度丢失的问题
    【VSCode】vscode运行命令时提示“因为在此系统上禁止运行脚本”
    【Mybatis】mybatisplus代码生成器【逆向工程】搭配Lombok和swagger2
    【Linux】赋予root权限
    【MySQL】mysql模糊匹配多个字段
    idea为新创建的类增加个人注释模板
    【Linux】学习笔记:(一)常用命令大全
    Navicat查看数据库的密码
  • 原文地址:https://www.cnblogs.com/white-L/p/6239565.html
Copyright © 2020-2023  润新知