Unity经验之谈

1、全屏与非全屏之间的切换

       if (Input.GetMouseButtonDown(1))
        {
            Screen.fullScreen = !Screen.fullScreen;
        }

2、Camera适应所有的分辨率

    void Start () {
        Camera.main.aspect = 16 / 10f;
     }

3、字符串分割时,一定要注意空格,空格在日志中不好看出来。

            string a = "a,b,c ";
            string[] aa = a.Split(',');
            string value=aa[2];//最后会得到"c "
            //最好的方式是多加一个"," 
            string b = "a,b,c,";
            string[] bb = b.Split(',');
            string value1 = bb[2];//最后会得到"c"            

4、win10和win7 进程名称不同

win10 的进程名是PlayerSettings里的Product Name,

而比较坑的是在win7系统下,同一个程序,进程名居然是.exe的名字,例如你的unity 打包的exe名字叫做 Test.exe,

而Product Name名字叫 MyTest,则win10的进程名为 MyTest,而win7的进程名却TM是 Test ,坑死。

5、unity在调用外部的库时(如:dll, jar,so),传递的参数一定要注意C#的垃圾回收机制。

如果传入外部的参数,如果被垃圾回收掉GC.Collect(),可能会导致程序崩溃,报非法访问内存的错误。

解决的办法就是将参数设置为静态的全局变量,因为 static 是不会被GC掉的。

如:在PC端,会报如下错误

xxx by xxx [version: Unity 2018.2.15f1_65e0713a5949]

mono-2.0-bdwgc.dll caused an Access Violation (0xc0000005)
  in module mono-2.0-bdwgc.dll at 0023:73880af6.

Error occurred at 2019-03-01_160714.
C:\Program Files (x86)\xxx.exe, run by xxx.

14% physical memory in use.
8192 MB physical memory [0 MB free].
396 MB process peak paging file [289 MB used].
378 MB process peak working set [273 MB used].
System Commit Total/Limit/Peak: 1275MB/1216MB/1610MB
System Physical Total/Available: 0MB/2921MB
System Process Count: 36
System Thread Count: 534
System Handle Count: 13328
Disk space data for 'C:\Users\xxx\Crash_2019-03-01_080711713\': 39757352960 bytes free of 64422408192 total.

Read from location 3A226578 caused an access violation.

Context:
EDI:    0x0a75dfe8  ESI: 0x00000000  EAX:   0x0a448760
EBX:    0x0a75dfe0  ECX: 0x3a226572  EDX:   0xff52f000
EIP:    0x73880af6  EBP: 0x00a0f7a8  SegCs: 0x00000023
EFlags: 0x00010206  ESP: 0x00a0f7a8  SegSs: 0x0000002b


Bytes at CS:EIP:
0f be 41 06 83 e8 0f 83 f8 0f 77 29 0f b6 80 ac 



Stack Trace of Crashed Thread 4044:
0x73880AF6 (mono-2.0-bdwgc) mono_type_to_unmanaged
0x73880A28 (mono-2.0-bdwgc) mono_type_to_unmanaged
0x7381E91C (mono-2.0-bdwgc) mono_conc_hashtable_foreach_steal
0x73879D5D (mono-2.0-bdwgc) mono_metadata_blob_heap
0x7385B21A (mono-2.0-bdwgc) mono_image_close
0x7382866E (mono-2.0-bdwgc) mono_assembly_close
0x73825AC5 (mono-2.0-bdwgc) mono_domain_free
0x738FCA51 (mono-2.0-bdwgc) mono_unity_unlock_dynamic_function_access_tables64
ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。
' (Address: 7465D982)
0x7465D982 (UnityPlayer) (function-name not available)
ERROR: SymGetSymFromAddr64, GetLa
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值