public class TestMatrix : MonoBehaviour
{
//声明一个零矩阵,然后将其第四列改为(1,1,1,1)
//分别将零矩阵单独声明,用数组装,用泛型装
Matrix4x4 matrix;
Matrix4x4[] matrix4x4Array;
List<Matrix4x4> matrix4x4List = new List<Matrix4x4>();
void Start()
{
matrix = Matrix4x4.zero;
matrix4x4Array = new Matrix4x4[1] { Matrix4x4.zero };
matrix4x4List.Add(Matrix4x4.zero);
Debug.Log(matrix);
matrix.SetColumn(3, Vector4.one);
Debug.Log(matrix);
Debug.Log("matrix4x4sBefore" + this.matrix4x4Array[0]);
this.matrix4x4Array[0].SetColumn(3, Vector4.one);
Debug.Log("matrix4x4sAfter" + this.matrix4x4Array[0]);
//单独声明,和数组中都运行正常,但是泛型不可以。
//虽然不报错,但是测试发现当矩阵被添加到泛型中,泛型中的元素的SetColumn方法是无效的,运行之后矩阵没有变化。
Debug.Log("matrix4x4sBefore" + this.matrix4x4List[0]);
this.matrix4x4List[0].SetColumn(3, Vector4.one);
Debug.Log("matrix4x4sAfter" + this.matrix4x4List[0]);
//修改List中的矩阵元素的有效方法
// Debug.Log("matrix4x4sBefore" + this.matrix4x4List[0]);
// Matrix4x4 tempM = this.matrix4x4List[0];
// tempM.SetColumn(3, Vector4.one);
// this.matrix4x4List[0] = tempM;
// Debug.Log("matrix4x4sAfter" + this.matrix4x4List[0]);
}
}
当Matrix4x4是泛型的元素时,他的函数SetRow() 和SetColumn()是无效的。