Unity环境下的常用数值静态引用

1、三角函数

using UnityEngine;

public class TriFun
{
	static float[] _Sin32s;
	public static float[] Sin32s
	{
		get
		{
			if (_Sin32s == null || _Sin32s.Length == 0)
			{
				_Sin32s = new float[32];
				float angleDeta = Mathf.PI / 16;
				_Sin32s[0] = 0;
				_Sin32s[8] = 1;
				_Sin32s[16] = 0;
				_Sin32s[24] = -1;
				for (int i = 1; i < 8; i++)
				{
					_Sin32s[i] = Mathf.Sin(angleDeta * i);
				}
				for (int i = 9; i < 16; i++)
				{
					_Sin32s[i] = _Sin32s[16 - i];
				}
				for (int i = 18; i < 24; i++)
				{
					_Sin32s[i] = -_Sin32s[i - 16];
				}
				for (int i = 25; i < 32; i++)
				{
					_Sin32s[i] = -_Sin32s[i - 16];
				}
			}
			return _Sin32s;
		}
	}

	static float[] _Cos32s;
	public static float[] Cos32s
	{
		get
		{
			if (_Cos32s == null || _Cos32s.Length == 0)
			{
				_Cos32s = new float[32];
				for (int i = 0; i < 32; i++)
				{
					int iSin = i + 8;
					iSin %= 32;
					_Cos32s[i] = Sin32s[iSin];
				}
			}
			return _Cos32s;
		}
	}

	static float[] _Sin16s;
	public static float[] Sin16s
	{
		get
		{
			if (_Sin16s == null || _Sin16s.Length == 0)
			{
				_Sin16s = new float[16];
				for (int i = 0; i < 16; i++)
				{
					_Sin16s[i] = Sin32s[i * 2];
				}
			}
			return _Sin16s;
		}
	}

	static float[] _Cos16s;
	public static float[] Cos16s
	{
		get
		{
			if (_Cos16s == null || _Cos16s.Length == 0)
			{
				_Cos16s = new float[16];
				for (int i = 0; i < 16; i++)
				{
					_Cos16s[i] = Cos32s[i * 2];
				}
			}
			return _Cos16s;
		}
	}

	static float[] _Sin8s;
	public static float[] Sin8s
	{
		get
		{
			if (_Sin8s == null || _Sin8s.Length == 0)
			{
				_Sin8s = new float[8];
				for (int i = 0; i < 8; i++)
				{
					_Sin8s[i] = Sin32s[i * 4];
				}
			}
			return _Sin8s;
		}
	}

	static float[] _Cos8s;
	public static float[] Cos8s
	{
		get
		{
			if (_Cos8s == null || _Cos8s.Length == 0)
			{
				_Cos8s = new float[8];
				for (int i = 0; i < 8; i++)
				{
					_Cos8s[i] = _Cos32s[i * 4];
				}
			}
			return _Cos8s;
		}
	}
}

你可能感兴趣的:(Unity,C#,c#,Unity)