在 XNA 中,我实例化模型如下:
protected override void LoadContent()
{
this.model = this.Game.Content.Load<Model>("Units/Vehicles/Palladium");
base.LoadContent();
}
我在像 Tank 这样的类(class)中这样做。我在这里要问的是,我应该为每个 Tank 实例实例化(加载它)该模型实例,还是应该实例化一次并将其分配给该 Tank 类的静态属性?
我不确定坦克实例是否需要所有自己的实例,但我也不确定实例化新模型在性能方面是否昂贵。
感谢您的帮助!
最佳答案
来自 MSDN for the ContentManager.Load generic method :
Return Value
The loaded asset. Repeated calls to load the same asset will return the same object instance.
所以从本质上讲,从您的角度来看,虽然答案是“只加载一次模型并跨实例重用它”,ContentManager类会为您处理。
关于c# - 我应该在 XNA 中重用模型实例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5425548/