Script調整
使用ExAddChild()方法載入Prefab的過程中, 如果發生瞬白, 或動畫貼圖不正確, 可以做以下調整:
1. 使用Callback方式載入圖檔
- 原始函數
public void ShowCard(IResoruceItem cards)
{
var canvas = GameObject.Find("canvas");
var prefab = Resoruces.Load<GameObject>("/prefab/drawcard");
var go = canvas.ExAddChild(prefab);
go.GetComponent<DrawCardPanel>().init(cards);
PBAudio.Play(AudioID.BG);
}
- 使用ExAddChildAsync()調整後
public void ShowCard(IResoruceItem cards)
{
var canvas = GameObject.Find("canvas");
var prefab = Resoruces.Load<GameObject>("/prefab/drawcard");
canvas.ExAddChildAsync(prefab, go =>
{
go.GetComponent<DrawCardPanel>().init(cards);
PBAudio.Play(AudioID.BG);
});
}
2.使用協程載入圖檔
- 原始函數
public IEnumerator ShowCard()
{
var req = new RIDRequest();
yield return NetManager.Send(req);
var canvas = GameObject.Find("canvas");
var prefab = Resoruces.Load<GameObject>("/prefab/drawcard");
var go = canvas.ExAddChild(prefab);
go.GetComponent<DrawCardPanel>().init(req.Result);
PBAudio.Play(AudioID.BG);
}
- 使用ExPreloadBodies()調整後
public IEnumerator ShowCard()
{
var req = new RIDRequest();
yield return NetManager.Send(req);
var canvas = GameObject.Find("canvas");
var prefab = Resoruces.Load<GameObject>("/prefab/drawcard");
var go = canvas.ExAddChild(prefab);
yield return go.ExPreloadBodies();
go.GetComponent<DrawCardPanel>().init(req.Result);
PBAudio.Play(AudioID.BG);
}