Unity3D自己常用代码
2015-09-02 15:04
495 查看
常需要,常查找!
自己记录下!
1.
2.
提高效率
3. InvokeReapting 的内部实现
4.
Coroutine 和InvokeReapting
协同程序,不是多线程。但是他有自己的堆栈,局部变量,指令指针,与其他协同程序共享全局变量等信息。在多处理器下,多线程同时运行,协同程序,在某时刻之有一个在运行。
若你有个负责的任务,它非常费帧率,就考虑使用协同或InvokeReapting.
若是简单任务,就嫑在协同或InvokeReapting使用,这不会提高效率的。
但是也不用太死板。尽管可能降低效率,代码会更简单和实用。
协同是处理时间序列的一种很好的方法。
它不是线程也不是异步。
协同当脚本未激活或对象为激活时不可用。
协同返回时间的WaitForSeconds依赖于Time.timeScale.
InvokeReapting
/*
void InvokeRepeating(string methodName, float time, float repeatRate)
{
- Find the method called "methodName" in the calling assembly and store it.
- Wait "time" seconds by yielding on WaitForSeconds(time)
Loop until the user cancels this action
{
- Invoke the stored method
- Wait "repeatTime" seconds by yielding on WaitForSeconds(repeatRate)
}
- Remove the method info record from storage.
}
*/
使用Invoke或InvokeReapting,这样很难调试。
自己记录下!
1.
var ray = Camera.main.ScreenPointToRay(Input.mousePosition); //GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = ray.GetPoint(10.0f); transform.LookAt(ray.GetPoint(10.0f));
2.
提高效率
GetComponent(), FindObjectByType() and Instantiate()尽量少使用。
3. InvokeReapting 的内部实现
实现过程 { 找到函数方法名称,存储 等待调用时间,WaitForSeconds(time) 循环知道用户取消 { Invoke 存储的函数方法 等待时间 } 删除记录保存的方法 }
4.
Coroutine 和InvokeReapting
协同程序,不是多线程。但是他有自己的堆栈,局部变量,指令指针,与其他协同程序共享全局变量等信息。在多处理器下,多线程同时运行,协同程序,在某时刻之有一个在运行。
若你有个负责的任务,它非常费帧率,就考虑使用协同或InvokeReapting.
若是简单任务,就嫑在协同或InvokeReapting使用,这不会提高效率的。
但是也不用太死板。尽管可能降低效率,代码会更简单和实用。
协同是处理时间序列的一种很好的方法。
它不是线程也不是异步。
协同当脚本未激活或对象为激活时不可用。
协同返回时间的WaitForSeconds依赖于Time.timeScale.
InvokeReapting
/*
void InvokeRepeating(string methodName, float time, float repeatRate)
{
- Find the method called "methodName" in the calling assembly and store it.
- Wait "time" seconds by yielding on WaitForSeconds(time)
Loop until the user cancels this action
{
- Invoke the stored method
- Wait "repeatTime" seconds by yielding on WaitForSeconds(repeatRate)
}
- Remove the method info record from storage.
}
*/
使用Invoke或InvokeReapting,这样很难调试。
相关文章推荐
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- unity实现摄像头跟随
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- [软件资讯]Unity已支持将3D游戏导出成Flash
- Unity 武器拖尾效果
- unity常见问题之20题
- Unity3D动画存储插件
- unity 赛车相机跟随物体移动
- Unity 预编译宏
- VS2013中 命名空间“UnityEngine”中不存在类型或命名空间名称“UI”。是否缺少程序集引用?
- Unity3D占用内存太大的解决方法
- 【Unity】安卓项目使用带有资源Jar包SDK的打包方法
- Unity2d 5.1 弱联网游戏制作 (一)场景创建、添加组件、精灵移动、主摄像机跟随
- Unity2d 弱联网游戏制作(二) 动画、场景、渲染层、碰撞检测、音乐播放
- 在IOS APP中反复打开和关闭Unity页面