本文章由cartzhang编写,转载请注明出处。 所有权利保留。

文章链接:http://blog.csdn.net/cartzhang/article/details/50483316

作者:cartzhang

常需要,常查找!

自己记录下!

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 (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,这样很难调试。

5.常用属性

ContextMenu,在面板功能增加选项。
ContextMenuItemAttribute,对编辑添加右键操作。[ContextMenuItem("Reset", "ResetName")]
HeaderAttribute,在变量前面增加说明:[Header("魔法值")]
MultilineAttribute,[MultilineAttribute]
RangeAttribute,限制输入范围
RequireComponent,依赖组件,[RequireComponent(typeof(Rigidbody))]
[Space(10)],在面板上,增加一个空行。
[Tooltip("This year is 2015!")],鼠标移到对象上,显示提示。

6.MenuItem设置快捷键

[MenuItem("Tools/New Option %#a")]
private static void NewMenuOption()
{
}

菜单快捷键设置,可单独使用,也可以组合使用:


% – CTRL on Windows / CMD on OSX # – Shift & – Alt LEFT/RIGHT/UP/DOWN – Arrow keys F1…F2 – F keys HOME, END, PGUP, PGDN

AddForce和velocity有什么区别?

这是力与速度的区别。

施加恒力,对象获取加速度,然后就加速前进。

直接使用Velocity,速度很平稳,移动为恒定值。

检查那个按键被按下


public void DetectPressedKeyOrButton()
{
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(kcode))
{
Debug.Log("KeyCode down: " + kcode);
}
}
}

7. 对象是否可见


public static class RendererExtensions
{
public static bool IsVisibleFrom(this Renderer renderer, Camera camera)
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
return GeometryUtility.TestPlanesAABB(planes, renderer.bounds);
}
}

然后判断:


if (rend.IsVisibleFrom(Camera.main)) Debug.Log("Visible");
else Debug.Log("Not visible");

若有问题,请随时联系!

非常感谢你!!

最新文章

  1. 在虚拟机中安装CentOS
  2. sql中去除重复的项
  3. unresolved refrence 'execfile'……
  4. magic矩阵 分类: 数学 2015-07-31 22:56 2人阅读 评论(0) 收藏
  5. 解决 Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 的问题
  6. ava中拦截器 过滤器 监听器都有什么区别
  7. ffmpeg, libav学习记录
  8. Eclipse Useful Plugins Links
  9. Java 基础类型
  10. java 7K交通灯管理系统面试题
  11. Define Constraints That Are Minimal and Sufficient 设定不多不少的约束
  12. 部署statspack工具(二)之解决方案2
  13. 图片转换PDF
  14. Java程序设计第五周学习总结
  15. SSD 的介绍 -------转载
  16. python———day04
  17. 【字符串】ZSC-勤奋的计算机系学生
  18. 5分钟学会vue中的路由守卫(导航守卫)
  19. Linux 硬盘格式化、分区、挂载、卸载、删除分区,Linux重新调整分区
  20. python迭代器概念与应用

热门文章

  1. Python爬虫基础--爬取车模照片
  2. Django入门--模型系统(一):模型基础
  3. [Web Worker] Introduce to Web Worker
  4. nyoj19(排列组合next_permutation(s.begin(),s.end()))
  5. 【HNOI 2004】宠物收养所
  6. LigerUI 单独调用插件使用注意项
  7. BZOJ 2212线段树的合并
  8. 9-21 调试javaweb 数据库连接感想
  9. jquery 登录,删除提示信息框
  10. UWP 读取XML文件