C# 事件编程在游戏开发的应用
2D碰撞检测:http://wenku.baidu.com/view/45544cfcfab069dc50220145.html
1.Action
System.Action 等于快捷创建一个委托
2.Action<T>
// 使用泛型方式定义 public void CallUI<T>(Action<T, object[]> callback, params object[] args) where T : CUIBase
.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, “Courier New”, courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }
使用
CUIManager.Instance.CallUI<CUIMidMsg>( (_ui, _arg) => _ui.ShowMsg((string)_arg[0]), string.Format(szMsg, format));
3.Func<T, TResult>
封装具有参数并返回TResult的方法
.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, “Courier New”, courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }
例如:System.Func<CHero, Vector2, bool> _Teleport = null;
4.EventHandler<TEventArgs>
[SerializableAttribute] public delegate void EventHandler<TEventArgs>( Object sender, TEventArgs e )
TEventArgs 由该事件生成的事件数据的类型
Object Sender:事件源
TEventArgs e:包含事件数据的args
5.读表反射执行函数
技能表中的Name列对应代码中的功能函数,如下图所示:
Skill中的技能全部做成功能单元,让策划填表自由组合
注:本文写于2014-05-30,一直躺在草稿箱,现才发布