Ending Learning for Day 14
来源:互联网 发布:pcb电路图设计软件 编辑:程序博客网 时间:2024/05/16 06:07
Unity 协程
协程:协程(Coroutine)不同于线程(Thread),他目标解决的不是线程阻塞一类的问题。以我个人的理解,它主要解决有某些必须在游戏循环中运行的代码,而你又不想把它写到Update()中的情况。
游戏与一般应用程序的区别在于,一般应用程序是事件驱动,而游戏则拥有游戏循环这一特性。
游戏中自然也会有”事件”,基本都可以写在Update()中,但是由于游戏循环的存在,Update()会风雨无阻的在每一帧调用,为了让代码适时的执行,一般都会设置几个bool或int/float来控制Update()中的代码。
这时你会发现,如果你的Update()中有太多这样的代码时,代码的可读性会越来越糟。
http://gypsumlabs.github.io/2015/12/08/unity-tips-coroutine/
C# Lamdba表达式
我们在C#2.0之前就有委托了,在2.0之后又引入了匿名方法,C#3.0之后,又引入了Lambda表达式,他们三者之间的顺序是:委托->匿名变量->Lambda表达式
http://www.cnblogs.com/chenwolong/p/5669440.html
C# (事件触发)回调函数
//事件发送者 class Dog { //1.声明关于事件的委托; public delegate void AlarmEventHandler(object sender, EventArgs e); //2.声明事件; public event AlarmEventHandler Alarm; //3.编写引发事件的函数; public void OnAlarm() { if (this.Alarm != null) { Console.WriteLine("\n狗报警: 有小偷进来了,汪汪~~~~~~~"); this.Alarm(this, new EventArgs()); //发出警报 } } } //事件接收者 class Host { //4.编写事件处理程序 void HostHandleAlarm(object sender, EventArgs e) { Console.WriteLine("主人: 抓住了小偷!"); } //5.注册事件处理程序 public Host(Dog dog) { dog.Alarm += new Dog.AlarmEventHandler(HostHandleAlarm); } } //6.现在来触发事件 class Program { static void Main(string[] args) { Dog dog = new Dog(); Host host = new Host(dog); //当前时间,从2008年12月31日23:59:50开始计时 DateTime now = new DateTime(2015, 12, 31, 23, 59, 50); DateTime midnight = new DateTime(2016, 1, 1, 0, 0, 0); //等待午夜的到来 Console.WriteLine("时间一秒一秒地流逝... "); while (now < midnight) { Console.WriteLine("当前时间: " + now); System.Threading.Thread.Sleep(1000); //程序暂停一秒 now = now.AddSeconds(1); //时间增加一秒 } //午夜零点小偷到达,看门狗引发Alarm事件 Console.WriteLine("\n月黑风高的午夜: " + now); Console.WriteLine("小偷悄悄地摸进了主人的屋内... "); dog.OnAlarm(); Console.ReadLine(); } }
阅读全文
0 0
- Ending Learning for Day 14
- Ending Learning for Day 5
- Ending Learning for Day 6
- Ending Learning for Day 11
- Ending Learning for Day 4
- Unity Learning for Day 14
- Crazy Learning for Day 14
- #Paper Reading# Toward an Architecture for Never-Ending Language Learning
- Unity Learning for Day 2
- Unity Learning for Day 3
- Unity Learning for Day 5
- Unity Learning for Day 6
- Unity Learning for Day 9
- Unity Learning for Day 12
- Unity Learning for Day 13
- Unity Learning for Day 15
- Unity Learning for Day 16
- Unity Learning for Day 17
- HDU
- Eclipse如何修改指定项目的JDK版本
- SSM框架搭建配置问题(1)--------spring和Mybatis整合包版本冲突
- Pots POJ
- 秦时明月哲理
- Ending Learning for Day 14
- eclipse build workspace 慢的问题如何解决
- Number Sequence 矩阵快速幂
- 1061. 判断题(15)
- struts2 核心与工作原理
- C. Journey(dfs求期望+Codeforces Round #428 (Div. 2))
- Python 陷阱与缺陷列表
- Java String.split()用法小结
- [第七季]5.常用DIV操作兼论JQuery语法