控制 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() 则表示这个 泛型必须有构造函数 否则不能使用。
这篇博客探讨了如何在代码中控制Cell的批量生成,涉及到了GameObjectCellPrefab的获取方法。同时,介绍了Mathf.Ceil和Mathf.CeilToInt在数值处理中的应用,用于向上取整。此外,讲解了Debug.Assert在调试中的作用以及泛型约束在限制泛型类型为引用类型并要求有构造函数时的使用情况。
747

被折叠的 条评论
为什么被折叠?



