控制 Cell 批量生成的代码在哪里?
protected sealed override GameObject CellPrefab => cellGroupTemplate;
protected sealed override GameObject CellPrefab => cellGroupTemplate;
//等价于上面的代码
public GameObject GetCellPrefab()
{
return cellGroupTemplate;
}
GameObject cellGroupTemplate;
Mathf.Ceil() 向上取整
Mathf.Ceil(10.1f);//返回11
Mathf.Ceil(-10.1f);//返回-10
Mathf.CeilToInt() 返回大于或等于 f
的最小整数
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Start()
{
// Prints 10
Debug.Log(Mathf.CeilToInt(10.0f));
// Prints 11
Debug.Log(Mathf.CeilToInt(10.2f));
// Prints 11
Debug.Log(Mathf.CeilToInt(10.7f));
// Prints -10
Debug.Log(Mathf.CeilToInt(-10.0f));
// Prints -10
Debug.Log(Mathf.CeilToInt(-10.2f));
// Prints -10
Debug.Log(Mathf.CeilToInt(-10.7f));
}
}
Debug.Assert() 检查条件 ;如果条件为 false
,打出调用堆栈
泛型约束
public abstract class FancyGridViewCell<TItemData, TContext> : FancyScrollRectCell<TItemData, TContext> where TContext : class, IFancyGridViewContext, new()
Where T:Class,new()的使用
当我们使用泛型的时候,有时候就会提示我们 T 必须是 引用类型 而无法进行下去,其实我们学泛型的时候也应该了解到这个 T 的使用场合,他可以是 值类型 也可以是 引用类型 ,但是我们某些场合就只能使用 引用类型 比如 EF 中的集合,所以我们就需要 强制标识这个 T 只能用于引用类型,这里就用到了 Where T :class,这就是标识这个 T 为引用类型;而 new() 则表示这个 泛型必须有构造函数 否则不能使用。