# 【拓展类方法】
以下是一些给类增加方法的示例:
using UnityEngine;
public static class ExtensionMethods
{
public static Vector3 Round(this Vector3 v)
{
v.x = Mathf.Round(v.x);
v.y = Mathf.Round(v.y);
v.z = Mathf.Round(v.z);
return v;
}
public static Vector3 Round(this Vector3 v,float size)
{
return (v/size).Round() * size;
}
public static float Round(this float v,float size) {
return Mathf.Round(v / size) * size;
}
public static float AtLeast(this float val, float min) {
return Mathf.Max(val,min);
}
public static int AtLeast(this int val, int min) {
return Mathf.Max(val,min);
}
}