UnitComponent学习笔记
请大家关注我的微博:@NormanLin_BadPixel坏像素
跟管理Player的PlayerComponent很像,不过这里管理的是Unit。“装置”?
Unit
public sealed class Unit: Entity
{
public VInt3 IntPos;
public GameObject GameObject;
public void Awake()
{
}
public Vector3 Position
{
get
{
return GameObject.transform.position;
}
set
{
GameObject.transform.position = value;
}
}
public Quaternion Rotation
{
get
{
return GameObject.transform.rotation;
}
set
{
GameObject.transform.rotation = value;
}
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
}
}
我们看到,只是对GameObject的Transform.postion 跟Rotation进行了一次封装。而且多了一个VInt3 IntPos。这个VInt3又是什么东西?
我们知道,不同的机器,不同的设备,它们计算浮点数的结果是很难达到一致的。而网络游戏当中,特别是帧同步,我们希望我们相同的指令在不同的设备上计算出来的结果是一致的,这样,我们就得避免使用浮点数。而我们在Unity里面的很多类,都用到了浮点数,最常用的Vector2、3其实就是用到了浮点数。
为了避免浮点数计算结果不一致,作者写了一套相对正确的计算方式,用VInt3来代替Vector3。
我们发现,除了VInt3,还有大量服务于精确计算的类。
1. VInt2
2. VInt3
3. IntMath
4. VFactor
5. …
这些都是一些数学知识。大家有兴趣的去看看,这里就不详讲了。