博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity经验之谈
阅读量:6429 次
发布时间:2019-06-23

本文共 15197 字,大约阅读时间需要 50 分钟。

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/1610MBSystem Physical Total/Available: 0MB/2921MBSystem Process Count: 36System Thread Count: 534System Handle Count: 13328Disk 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:   0x0a448760EBX:    0x0a75dfe0  ECX: 0x3a226572  EDX:   0xff52f000EIP:    0x73880af6  EBP: 0x00a0f7a8  SegCs: 0x00000023EFlags: 0x00010206  ESP: 0x00a0f7a8  SegSs: 0x0000002bBytes 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_unmanaged0x73880A28 (mono-2.0-bdwgc) mono_type_to_unmanaged0x7381E91C (mono-2.0-bdwgc) mono_conc_hashtable_foreach_steal0x73879D5D (mono-2.0-bdwgc) mono_metadata_blob_heap0x7385B21A (mono-2.0-bdwgc) mono_image_close0x7382866E (mono-2.0-bdwgc) mono_assembly_close0x73825AC5 (mono-2.0-bdwgc) mono_domain_free0x738FCA51 (mono-2.0-bdwgc) mono_unity_unlock_dynamic_function_access_tables64ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 7465D982)0x7465D982 (UnityPlayer) (function-name not available)ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 7458BCA5)0x7458BCA5 (UnityPlayer) (function-name not available)ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 74B22D09)0x74B22D09 (UnityPlayer) (function-name not available)ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 74B220F8)0x74B220F8 (UnityPlayer) (function-name not available)ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 74B24531)0x74B24531 (UnityPlayer) (function-name not available)0x74B24705 (UnityPlayer) UnityMainERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 00F51015)0x00F51015 (XESAIMandarin) (function-name not available)ERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 00F511D0)0x00F511D0 (XESAIMandarin) (function-name not available)0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainStacks for Running Threads:Call Stack for Thread 3304:0x77D90DA8 (ntdll) NtWaitForSingleObjectERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 745DCB19)0x745DCB19 (UnityPlayer) (function-name not available)0x74B4A5D8 (UnityPlayer) UnityMain0x74B51A8A (UnityPlayer) UnityMain0x74B51B78 (UnityPlayer) UnityMainERROR: SymGetSymFromAddr64, GetLastError: '试图访问无效的地址。' (Address: 745DC06D)0x745DC06D (UnityPlayer) (function-name not available)0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainCall Stack for Thread 3932:0x77D90DA8 (ntdll) NtWaitForSingleObject0x75AE10B4 (KERNELBASE) WaitForSingleObject0x72B72398 (IMSCCORE) CreateUDicProxy0x72B6EA6A (IMSCCORE) CreateUDicProxy0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainCall Stack for Thread 2240:0x77D92828 (ntdll) NtWaitForWorkViaWorkerFactory0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainCall Stack for Thread 3416:0x77D92828 (ntdll) NtWaitForWorkViaWorkerFactory0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainCall Stack for Thread 1992:0x77D90DF8 (ntdll) NtRemoveIoCompletion0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainCall Stack for Thread 1372:0x77D92828 (ntdll) NtWaitForWorkViaWorkerFactory0x766F8543 (KERNEL32) BaseThreadInitThunk0x77DAAC69 (ntdll) RtlInitializeExceptionChain0x77DAAC3C (ntdll) RtlInitializeExceptionChainStack Memory [0x00A0F7A8-0x00A10000]:0x00a0f7a8: 00a0f7c8 73880a28 3a226572 081c7b20 ....(..sre": {..0x00a0f7b8: 00000003 0a6c56b0 0816d418 081c7b20 .....Vl..... {..0x00a0f7c8: 00a0f7ec 7381e91c 0a75a250 0a75a250 .......sP.u.P.u.0x00a0f7d8: 00a0f80c 081c7b20 0a70f310 0816d4d8 .... {....p.....0x00a0f7e8: 0a70f384 00a0f81c 73879d5d 0a720108 ..p.....]..s..r.0x00a0f7f8: 738809f0 00a0f80c 081c7b20 00000000 ...s.... {......0x00a0f808: 77d9f4d0 081c7b20 0ab8ca88 081c7b20 ...w {...... {..0x00a0f818: 00000000 00a0f838 7385b21a 081c7b20 ....8......s {..0x00a0f828: 081a6568 080d0ff0 080d0ff0 ffffffff he..............0x00a0f838: 00a0f848 7382866e 081c7b20 02ab2e70 H...n..s {..p...0x00a0f848: 00a0f888 73825ac5 080d0ff0 00000040 .....Z.s....@...0x00a0f858: 00000001 73ad8714 00d0ae08 02ab2e70 .......s....p...0x00a0f868: 0a4ee537 080d0ff0 00000001 02ab2e70 7.N.........p...0x00a0f878: 00d2b0e0 762c7462 00d01668 00000000 ....bt,vh.......0x00a0f888: 00a0f8b0 738fca51 02ab2e70 00000001 ....Q..sp.......0x00a0f898: 00d2b0e0 00d367a8 00d2b0e0 00d2b0e0 .....g..........0x00a0f8a8: 762d5dbc 762b7f50 00a0f8cc 7465d982 .]-vP.+v......et0x00a0f8b8: 02ab2e70 00a0f8c8 00000000 762b7f50 p...........P.+v0x00a0f8c8: 02ab2e70 00a0f8e0 7458bca5 00000000 p.........Xt....0x00a0f8d8: 00000000 00a0f8fc 00a0f8fc 74b22d09 .............-.t0x00a0f8e8: 00000000 74b220c4 00a0f910 00000000 ..... .t........0x00a0f8f8: 00000000 00a0f930 74b220f8 00000001 ....0.... .t....0x00a0f908: 00000001 00000000 00040d0c 00000200 ................0x00a0f918: 00000000 018e0274 001c8ad1 000003b2 ....t...........0x00a0f928: 000001f5 00000584 00a0f9f4 74b24531 ............1E.t0x00a0f938: ff529000 00f6327c 00000000 00ce0100 ..R.|2..........0x00a0f948: 00a0f8c8 00000000 00a0fa64 77e335f2 ........d....5.w0x00a0f958: c57085d1 02cb3c70 00000051 77da32ff ..p.p<..Q....2.w0x00a0f968: 00000800 00000808 00000051 00000044 ........Q...D...0x00a0f978: 00000000 65726170 5748746e 0000444e ....parentHWND..0x00a0f988: 00000000 0000000a 00000044 00000000 ........D.......0x00a0f998: 006c6174 206e776f 646e6556 0000726f tal.own Vendor..0x00a0f9a8: 00000003 00000044 00000000 00000000 ....D...........0x00a0f9b8: 65646968 646e6957 0000776f 77e335f2 hideWindow...5.w0x00a0f9c8: 0000000a 00000044 00000500 00000000 ....D...........0x00a0f9d8: 6f747561 6974616d 772d6e6f 00006265 automation-web..0x00a0f9e8: 0000000e 00000044 00a0f9f4 00a0fa10 ....D...........0x00a0f9f8: 74b24705 00f50000 00000000 00ce0b5a .G.t........Z...0x00a0fa08: 00000001 00f6327c 00a0fa28 00f51015 ....|2..(.......0x00a0fa18: 00f50000 00000000 00ce0b5a 00000001 ........Z.......0x00a0fa28: 00a0fa74 00f511d0 00f50000 00000000 t...............0x00a0fa38: 00ce0b5a 00000001 c51c4769 00000000 Z.......iG......0x00a0fa48: 00000000 ff529000 fffff800 c0000005 ......R.........0x00a0fa58: 00000000 00a0fa40 00a0f1d4 00a0fab4 ....@...........0x00a0fa68: 00f51ba0 c54ab0bd 00000000 00a0fa80 ......J.........0x00a0fa78: 766f8543 ff529000 00a0fac4 77daac69 C.ov..R.....i..w0x00a0fa88: ff529000 b209a8cd 00000000 00000000 ..R.............0x00a0fa98: ff529000 c0000005 fffff803 00a0f1bc ..R.............0x00a0faa8: 75b705d2 00a0fa8c 00a0f1bc 00a0fad4 ...u............0x00a0fab8: 77e335f2 c570ba09 00000000 00a0fadc .5.w..p.........0x00a0fac8: 77daac3c 00f51242 ff529000 ffffffff <..wB.....R.....0x00a0fad8: 77e21d86 00000000 00000000 00f51242 ...w........B...0x00a0fae8: ff529000 00000000 00000000 00000000 ..R.............0x00a0faf8: 00000000 00000000 00000000 00000000 ................0x00a0fb08: 00000000 00000000 00000000 00000000 ................0x00a0fb18: 00000000 00000000 00000000 00000000 ................0x00a0fb28: 00000000 00000000 00000000 00000000 ................0x00a0fb38: 00000000 00000000 00000000 00000000 ................0x00a0fb48: 00000000 00000000 00000000 00000000 ................0x00a0fb58: 00000000 00000000 00000000 00000000 ................0x00a0fb68: 00000000 00000000 00000000 00000000 ................0x00a0fb78: 00000000 00000000 00000000 00000000 ................0x00a0fb88: 00000000 00000000 00000000 00000000 ................0x00a0fb98: 00000000 00000000 00000000 00000000 ................0x00a0fba8: 00000000 00000000 00000000 00000000 ................0x00a0fbb8: 00000000 00000000 00000000 00000000 ................0x00a0fbc8: 00000000 00000000 00000000 00000000 ................0x00a0fbd8: 00000000 00000000 00000000 00000000 ................0x00a0fbe8: 00000000 00000000 00000000 00000000 ................0x00a0fbf8: 00000000 00000000 00000000 00000000 ................0x00a0fc08: 00000000 00000000 00000000 00000000 ................0x00a0fc18: 00000000 00000000 00000000 00000000 ................0x00a0fc28: 00000000 00000000 00000000 00000000 ................0x00a0fc38: 00000000 00000000 00000000 00000000 ................0x00a0fc48: 00000000 00000000 00000000 00000000 ................0x00a0fc58: 00000000 00000000 00000000 00000000 ................0x00a0fc68: 00000000 00000000 00000000 00000000 ................0x00a0fc78: 00000000 00000000 00000000 00000000 ................0x00a0fc88: 00000000 00000000 00000000 00000000 ................0x00a0fc98: 00000000 00000000 00000000 00000000 ................0x00a0fca8: 00000000 00000000 00000000 00000000 ................0x00a0fcb8: 00000000 00000000 00000000 00000000 ................0x00a0fcc8: 00000000 00000000 00000000 00000000 ................0x00a0fcd8: 00000000 00000000 00000000 00000000 ................0x00a0fce8: 00000000 00000000 00000000 00000000 ................0x00a0fcf8: 00000000 00000000 00000000 00000000 ................0x00a0fd08: 00000000 00000000 00000000 00000000 ................0x00a0fd18: 00000000 00000000 00000000 00000000 ................0x00a0fd28: 00000000 00000000 00000000 00000000 ................0x00a0fd38: 00000000 00000000 00000000 00000000 ................0x00a0fd48: 00000000 00000000 00000000 00000000 ................0x00a0fd58: 00000000 00000000 00000000 00000000 ................0x00a0fd68: 00000000 00000000 00000000 00000000 ................0x00a0fd78: 00000000 00000000 00000000 00000000 ................0x00a0fd88: 00000000 00000000 00000000 00000000 ................0x00a0fd98: 00000000 00000000 00000000 00000000 ................0x00a0fda8: 00000000 00000000 00000000 00000000 ................0x00a0fdb8: 00000000 00000000 00000000 00000000 ................0x00a0fdc8: 00000000 00000000 00000000 00000000 ................0x00a0fdd8: 00000000 00000000 00000000 00000000 ................0x00a0fde8: 00000000 00000000 00000000 00000000 ................0x00a0fdf8: 00000000 00000000 00000000 00000000 ................0x00a0fe08: 00000000 00000000 00000000 00000000 ................0x00a0fe18: 00000000 00000000 00000000 00000000 ................0x00a0fe28: 00000000 00000000 00000000 00000000 ................0x00a0fe38: 00000000 00000000 00000000 00000000 ................0x00a0fe48: 00000000 00000000 00000000 00000000 ................0x00a0fe58: 00000000 00000000 00000000 00000000 ................0x00a0fe68: 00000000 00000000 00000000 00000000 ................0x00a0fe78: 00000000 00000000 00000000 00000000 ................0x00a0fe88: 00000000 00000000 00000000 00000000 ................0x00a0fe98: 00000000 00000000 00000000 00000000 ................0x00a0fea8: 00000000 00000000 00000000 00000000 ................0x00a0feb8: 00000000 00000000 00000000 00000000 ................0x00a0fec8: 00000000 00000000 00000000 00000000 ................0x00a0fed8: 00000000 00000000 00000000 00000000 ................0x00a0fee8: 00000000 00000000 00000000 00000000 ................0x00a0fef8: 00000000 00000000 00000000 00000000 ................0x00a0ff08: 00000000 00000000 00000000 00000000 ................0x00a0ff18: 00000000 00000000 00000000 00000000 ................0x00a0ff28: 00000000 00000000 00000000 00000000 ................0x00a0ff38: 00000000 00000000 00000000 00000000 ................0x00a0ff48: 00000000 00000000 00000000 00000000 ................0x00a0ff58: 00000000 00000000 00000000 00000000 ................0x00a0ff68: 00000000 00000000 00000000 00000000 ................0x00a0ff78: 00000000 00000000 00000000 00000000 ................0x00a0ff88: 00000000 00000000 00000000 00000000 ................0x00a0ff98: 00000000 00000000 00000000 00000000 ................0x00a0ffa8: 00000000 00000000 00000000 00000000 ................0x00a0ffb8: 00000000 00000000 00000000 00000000 ................0x00a0ffc8: 00000000 00000000 00000000 00000000 ................0x00a0ffd8: 00000000 00000000 00000000 00000000 ................0x00a0ffe8: 00000000 00000000 00000000 00000000 ................0x00a0fff8: 00000000 00000000                   ........Module 1C:\Program Files (x86)\ѧ��˼��У\AI��ʦ��ͨ����ѧ\xxx.exeImage Base: 0x00f50000  Image Size: 0x000a1000File Size:  637952      File Time:  2019-03-01_111200Version:   Company:       Product:       FileDesc:      FileVer:    2018.2.15.57457   ProdVer:    2018.2.15.57457Module 2C:\Windows\SYSTEM32\MSVCR120.dllImage Base: 0x72590000  Image Size: 0x000ee000File Size:  970912      File Time:  2013-10-05_023822Version:   Company:    Microsoft Corporation   Product:    Microsoft® Visual Studio® 2013   FileDesc:   Microsoft® C Runtime Library   FileVer:    12.0.21005.1   ProdVer:    12.0.21005.1Crash Report configuration: * App Name: XESAIMandarin * App Version: Unity 2018.2.15f1_65e0713a5949 * Mono DLL: C:\Program Files (x86)\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll * Bug Reporter App Path:  * Crash Report Path: C:\Users\CUIZON~1\AppData\Local\Temp\Crashes * Is Editor: falseCrash Report metadata:Additional report files: * "C:\Users\cuizongyao\AppData\LocalLow\output_log.txt" (Output log file)== [end of error.log] ==

  

6、unity动画中的SetTrigger方法只有用过以后才置回,如果你将一个动画片段设置SetTrigger而一直没有走到该动画,则SetTrigger的状态会一直为ture,直到播放到该动画片段,SetTrigger才置回原来的状态即false。

7、快速的将sting[ ]或者List<sting>转为sting,比for循环快多了

void Awake()    {        List
list = new List
(); list.Add("1"); list.Add("2"); list.Add("3"); string value = string.Join("-",list); Debug.Log(value); }

  

输出:

 

转载于:https://www.cnblogs.com/Jason-c/p/9329778.html

你可能感兴趣的文章
android SQL 理解
查看>>
杂七杂八荟萃
查看>>
项目中使用mybatis,日志不输出问题
查看>>
Linux Tar Split压缩解压缩分片压缩解压缩
查看>>
Quartz2D
查看>>
jQuery温度计,支持摄氏度华氏度同时展示
查看>>
Cloudstack+Glusterfs+Kvm 集群(笔记)
查看>>
Dubbo与Zookeeper、SpringMVC整合和使用
查看>>
Python中set 和dict 的总结
查看>>
mysql 相关
查看>>
超人学院Hadoop大数据资源分享
查看>>
pip安装更新
查看>>
中国人与欧洲人的想法
查看>>
android客户端Pad客户端开发,屏幕分辨率的不同究竟会怎么影响界面显示效果
查看>>
修复mysql表
查看>>
局域网
查看>>
2014诺贝尔物理学奖:蓝光LED
查看>>
CentOS 下Nginx 配置详解
查看>>
HTTP报文
查看>>
Jenkins系列1--初步了解
查看>>