私は店舗のページに取り組んでいます。このページはパネルのプレハブで埋められています。何らかの理由でプレハブを埋めるときは、プレハブの大きさの倍以上になります。プレハブを適切な場所にドラッグすると、期待どおりに機能します。縮尺の問題をデバッグする方法は?
プログラムターゲティングスケールにコードがありません。私はどこから来ているのか分かりません。
これは、リストの人口に使用しているコードです。
[System.Serializable]
public class Item
{
public string itemName;
public int price;
}
public class ShopScrollList : MonoBehaviour {
public List<Item> itemList;
public Transform contentPanel;
public Text storeDisplayText;
public SimpleObjectPool buttonObjectPool;
void Start() {
RefreshDisplay();
}
private void RefreshDisplay()
{
AddButtons();
}
private void AddButtons()
{
for (int i = 0; i < itemList.Count; i++)
{
Item item = itemList[i];
GameObject newButton = buttonObjectPool.GetObject();
newButton.transform.SetParent(contentPanel);
ButtonDetails buttonDetails = newButton.GetComponent<ButtonDetails>();
buttonDetails.Setup(item, this);
}
}
}
SimpleObjectPoolスクリプト:私は、問題がどこから来ている把握するためにデバッグすることができますどのように
// A very simple object pooling class
public class SimpleObjectPool : MonoBehaviour
{
// the prefab that this object pool returns instances of
public GameObject prefab;
// collection of currently inactive instances of the prefab
private Stack<GameObject> inactiveInstances = new Stack<GameObject>();
// Returns an instance of the prefab
public GameObject GetObject()
{
GameObject spawnedGameObject;
// if there is an inactive instance of the prefab ready to return, return that
if (inactiveInstances.Count > 0)
{
// remove the instance from teh collection of inactive instances
spawnedGameObject = inactiveInstances.Pop();
}
// otherwise, create a new instance
else
{
spawnedGameObject = (GameObject)GameObject.Instantiate(prefab);
// add the PooledObject component to the prefab so we know it came from this pool
PooledObject pooledObject = spawnedGameObject.AddComponent<PooledObject>();
pooledObject.pool = this;
}
// put the instance in the root of the scene and enable it
spawnedGameObject.transform.SetParent(null);
spawnedGameObject.SetActive(true);
// return a reference to the instance
return spawnedGameObject;
}
// Return an instance of the prefab to the pool
public void ReturnObject(GameObject toReturn)
{
PooledObject pooledObject = toReturn.GetComponent<PooledObject>();
// if the instance came from this pool, return it to the pool
if (pooledObject != null && pooledObject.pool == this)
{
// make the instance a child of this and disable it
toReturn.transform.SetParent(transform);
toReturn.SetActive(false);
// add the instance to the collection of inactive instances
inactiveInstances.Push(toReturn);
}
// otherwise, just destroy it
else
{
Debug.LogWarning(toReturn.name + " was returned to a pool it wasn't spawned from! Destroying.");
Destroy(toReturn);
}
}
}
// a component that simply identifies the pool that a GameObject came from
public class PooledObject : MonoBehaviour
{
public SimpleObjectPool pool;
}
。ここでは変換に影響を与えるのは1つだけですが、スケールを調整すべきではありません。
'SimpleObjectPool'スクリプトがなければほとんど助けがありません。 – Programmer
SimpleObjectPoolスクリプト –
Okを追加しました。 'spawnedGameObject =(GameObject)GameObject.Instantiate(prefab);を' spawnedGameObject =(GameObject)Instantiate(prefab);に置き換えてください。問題がまだ残っている場合は教えてください。 – Programmer