Unity开发中注意
来源:互联网 发布:矩阵不可逆说明什么 编辑:程序博客网 时间:2024/05/05 00:58
由于Unity的部分机制具有特殊性,在此列出需要注意的要点。
1.1. 内置方法
由Unity提供的固定方法,如Start、Update、OnMouseEnter等,除非有特殊的需要,否则请使用protected访问修饰符以保证良好的封装性。必要时可以使用virtual关键字供子类重写。
1.2. 可选参数
public void MethodWithOptionalParameter(int a = 1)
{
}
继承自MonoBehaviour的类,不可以声明带可选参数的方法,否则会导致脚本无法附加到游戏对象上。如果为一个已经附加到游戏对象上的脚本增加可选参数方法,同样会导致报无法加载脚本的警告(Can’t add script)。由于报错信息和错误原因不一致,是Unity一个相当莫名的BUG,必须要注意。
1.3. AOT
有些操作系统不支持动态编译,比如大部分的嵌入式系统以及苹果的IOS。这意味着所有的托管代码都必须使用Full AOT在打包前全部编译成本机代码,因此使用某些泛型机制时会导致抛出如下异常:
ExecutionEngineException: Attempting to JIT compile method….while running with --aot-only.
为考虑到良好的跨平台性,请避免:
使用带泛型的虚方法;
在泛型类中使用P/Invoke;
使用System.Reflection.Emit(其他反射机制可用);
参考文档:
http://docs.xamarin.com/guides/ios/advanced_topics/limitations
http://www.mono-project.com/AOT
Unity中使用C#定时器会报错
CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
untiy异常报错,可查询C:\Documents and Settings\用户名\Local Settings\Application Data\Unity\Editor
Unity中的Path对应各平台中的Path :
IOS:
Application.dataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
Application.persistentDataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches
//**********
CompanyName: DefaultCompanyjqd
ProductName:TestUnityPath
Bundle identifier: com.Company.ProductNamejqd
Android:
Application.dataPath : /data/app/xxx.xxx.xxx.apk
/data/app/com.Company.ProductNamejqd-1.apk
Application.streamingAssetsPath : jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
jar:file:///data/app/com.Company.ProductNamejqd-1.apk!/assets
Application.persistentDataPath : /data/data/xxx.xxx.xxx/files
/data/data/com.Company.ProductNamejqd/files
Application.temporaryCachePath : /data/data/xxx.xxx.xxx/cache
/data/data/com.Company.ProductNamejqd/cache
Windows:
Application.dataPath : /Assets
自己工程/Assets
Application.streamingAssetsPath : /Assets/StreamingAssets
自己工程/Assets/StreamingAssets
Application.persistentDataPath : C:/Users/xxxx/AppData/LocalLow/CompanyName/ProductName
C:/Users/XXXX/AppData/LocalLow/DefaultCompany/TestUnityPath
Application.temporaryCachePath : C:/Users/xxxx/AppData/Local/Temp/CompanyName/ProductName
C:/Users/xxxx/AppData/Local/Temp/DefaultCompany/TestUnityPath
//**********
//****
CompanyName: DefaultCompanyjqd
ProductName:四个中文字
Bundle identifier: com.xxxxxxx.xxxx.xxxx
windows:
assetSteamFilePath: 自己工程文件夹路径/Assets/StreamingAssets
persistentDataPath: C:/Users/电脑用户名/AppData/LocalLow/DefaultCompanyjqd/____________
dataPath: 自己工程文件夹路径/Assets
temporaryCachePath: C:/Users/xxxx/AppData/Local/Temp/DefaultCompanyjqd/____________
android:
assetSteamFilePath: jar:file:///data/app/com.xxxxxxx.xxxx.xxxx-1.apk!/assets(都加了 -1)
persistentDataPath: /storage/emulated/0/Android/data/com.xxxxxxx.xxxx.xxxx/files
dataPath: /data/app/com.xxxxxxx.xxxx.xxxx-1.apk
temporaryCachePath: /storage/emulated/0/Android/data/com.xxxxxxx.xxxx.xxxx/cache
华为 H30-U10 persistent 存储在了 .../Android/bundle indentifier的名字下的文件夹了
//
Mac:
Application.dataPath : /Assets
Application.streamingAssetsPath : /Assets/StreamingAssets
Application.persistentDataPath : /Users/xxxx/Library/Caches/CompanyName/Product Name
Application.temporaryCachePath : /var/folders/57/6b4_9w8113x2fsmzx_yhrhvh0000gn/T/CompanyName/Product Name
Windows Web Player:
Application.dataPath : file:///D:/MyGame/WebPlayer (即导包后保存的文件夹,html文件所在文件夹)
Application.streamingAssetsPath :
Application.persistentDataPath :
Application.temporaryCachePath :
- Unity开发中注意
- Android开发中Unity与Eclipse交互时的一些注意点
- Unity Kinect体感开发注意点
- 开发中注意点
- Unity中js语言使用注意
- Unity 开发中常见问题 Unity bug reporter
- unity 游戏开发过程中需要注意和后期优化的重点方向和难点分析(大白话理论篇)
- IOS开发中注意点
- #开发中注意的问题
- #开发中注意的问题#
- Unity不同平台生成中预处理的注意点
- Unity不同平台生成中预处理的注意点
- Unity不同平台生成中预处理的注意点
- 50 Tips for Working with Unity全面的分析了Unity开发应注意的事
- unity游戏开发----unity中自定义比分倒计时实现
- unity基础开发----常用代码Unity中解析XML
- 【Unity开发】Unity中触摸和鼠标操作的几个问题
- unity调用dll注意
- js选项卡
- Hadoop源代码组织结构
- nutch/solr/lucene//hadoop/hbase 搜索引擎
- 锁类型
- poj 2417 Discrete Logging(求离散对数)
- Unity开发中注意
- 几个常见字符串处理函数的实现原理
- JavaWeb学习笔记 第八记
- Bulk insert 批量导入数据的限制
- ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)
- BMP格式
- 数据仓库和数据库有什么区别
- 简易商品销售
- 德国7-1巴西