次のような Texture2D を保持するクラスがあります。
public class TextureData
{
public Texture2D texture;
}
すべてのテクスチャをロードするときは、次のような方法で処理します。
public void LoadAllTextures()
{
foreach(string s in texturesToBeLoaded)
{
TextureData data = new TextureData();
LoadTexture(s, data.texture);
// data.texture is still null.
}
}
public void LoadTexture(string filename, Texture2D texture)
{
texture = content.Load<Texture2D>(filename);
// texture now holds the texture information but it doesn't
// actually retain it when the method ends...why?
}
ここで何か不足していますか?私が変われば
public void LoadTexture(string filename, Texture2D texture)
に
public void LoadTexture(string filename, out Texture2D texture)
それは正常に動作します。
編集:わかりましたので、私が今それを理解する方法はこれです...
public void LoadAllTextures()
{
foreach(string s in texturesToBeLoaded)
{
TextureData data = new TextureData();
// here, data.texture's memory address == 0x0001
LoadTexture(s, data.texture /*0x0001*/);
}
}
public void LoadTexture(string filename, Texture2D texture /* this is now 0x0001 */)
{
texture = content.Load<Texture2D>(filename);
// now the PARAMETER is set to 0x0002, not data.texture itself.
}