Unity3d-C#之语法特性
来源:互联网 发布:讲题数学软件 编辑:程序博客网 时间:2024/05/16 09:45
?? 运算符:http://msdn.microsoft.com/zh-cn/library/ms173224(v=VS.100).aspx
?? 运算符称为 null 合并运算符,用于定义可以为 null 值的类型和引用类型的默认值。 如果此运算符的左操作数不为 null,则此运算符将返回左操作数;否则返回右操作数。
下面代码源于Unity3d 4.6UI系统源码:UI / UnityEngine.UI / EventSystem / Raycasters / PhysicsRaycaster.cs
public override Camera eventCamera { get { if (m_EventCamera == null) m_EventCamera = GetComponent<Camera>(); return m_EventCamera ?? Camera.main; } }
ref 关键字:http://msdn.microsoft.com/zh-cn/library/14akc2c7.aspx
ref 关键字通过引用(而非值)传递参数。 通过引用传递的效果是,对所调用方法中的参数进行的任何更改都反映在调用方法中
下面代码源于:UI / UnityEngine.UI / UI / Core / SetPropertyUtility.cs
public static bool SetClass<T>(ref T currentValue, T newValue) where T : class { if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) return false; currentValue = newValue; return true; }
out 关键字通过引用传递参数:http://msdn.microsoft.com/zh-cn/library/t3c3bfhx.aspx
下面代码源于:UI / UnityEngine.UI / EventSystem / InputModules / PointerInputModule.csprotected bool GetPointerData(int id, out PointerEventData data, bool create) { if (!m_PointerData.TryGetValue(id, out data) && create) { data = new PointerEventData(eventSystem) { pointerId = id, }; m_PointerData.Add(id, data); return true; } return false; }隐式类型 var:http://msdn.microsoft.com/zh-cn/library/bb383973.aspx下面代码源于:UI / UnityEngine.UI / EventSystem / InputModules / PointerInputModule.cs
protected static PointerEventData.FramePressState StateForMouseButton(int buttonId) { var pressed = Input.GetMouseButtonDown(buttonId); var released = Input.GetMouseButtonUp(buttonId); if (pressed && released) return PointerEventData.FramePressState.PressedAndReleased; if (pressed) return PointerEventData.FramePressState.Pressed; if (released) return PointerEventData.FramePressState.Released; return PointerEventData.FramePressState.NotChanged; }
0 0
- Unity3d-C#之语法特性
- VS08新特性之C# 3.0 新语法
- C#语法的一般特性
- [Unity3D]Unity3D 游戏开发之Unity3D Native2D特性研究
- unity3d之 C# WaitFOrSeconds()
- Unity3d-C#之where
- Unity3d-C#之where
- unity3d之 C# WaitFOrSeconds()
- unity3d c# 之事件
- 扩展Unity3d 组件方法,简化API使用 - C#特性之 Extension Method
- 【Unity3D自学记录】C#语法笔记
- 语法篇8之特性
- C#特性之Obsolete
- C# 3.0新特性之QuerySyntax(查询语法)和AnonymousTypes(匿名类型)
- C#语法小知识(七)特性
- C#语法之数组
- C#学习之语法
- C#语法之函数
- 页面记录输出
- VMware Workstation中安装Hyper-v
- iOS 控件拖到代码区没有反应的问题
- 实战iOS7之NSURLSession
- 23种设计模式-13-迭代器模式
- Unity3d-C#之语法特性
- chmod 是一条在Unix系统中用于控制用户对文件的权限的命令
- 第十六周OJ平台 Problem D: 指针引出奇数因子
- oracle三对内存参数间关系之6pga_aggrate_target参数和memory_参数这两类上下级层次参数间的关系
- 目前一个比较权威的各类杀毒软件在线检测的网站
- Android:QQ空间分享
- 关于mysql数据库在输入密码后,滴的一声直接退出界面的解决办法(详细办法)
- flask框架学习
- Web安全字体