void Update(int i) { #if USE_HANDLE_HOLDER if ((_handleHolder == null) || (_handleHolder.GetComponent <Kayac.LoadHandleHolder>().handleCount < HandleCount)) #else if (_handles[i] == null) #endif { var path = MakeRandomAssetName(); _texts[i].text = path + " loading..."; #if USE_CALLBACK #if USE_HANDLE_HOLDER if (_handleHolder == null) { _handleHolder = new GameObject("HandleHolder"); _handleHolder.transform.SetParent(gameObject.transform, false); } _loader.Load(path, asset => { if (asset != null) { OnLoadComplete(asset, i); } }, _handleHolder); #else _handles[i] = _loader.Load(path, asset => { if (asset != null) { OnLoadComplete(asset, i); } }); #endif #elif USE_COROUTINE StartCoroutine(CoLoad(i, path)); #else _handles[i] = _loader.Load(path); #endif } #if !USE_CALLBACK && !USE_COROUTINE if ((_handles[i] != null) && _handles[i].succeeded) { OnLoadComplete(_handles[i], i); } #endif _dump.text = _loader.Dump(); }
public void Load() { if (_handleHolder != null) // ロード済みなので抜ける { return; } // ハンドル保持オブジェクトを生成 _handleHolder = new GameObject("HandleHolder"); _handleHolder.transform.SetParent(gameObject.transform, false); for (int i = 0; i < HandleCount; i++) { int indexCaptured = i; // ラムダから使う値をコピー var path = _fileList[UnityEngine.Random.Range(0, _fileList.Count)]; _loader.Load(path, typeof(Texture2D), OnError, onComplete: asset => { if (asset != null) { var texture = asset as Texture2D; if (texture != null) { _images[indexCaptured].texture = texture; } else { Debug.LogError("asset is not texture2D. name:" + asset.name + " type:" + asset.GetType() + " index:" + indexCaptured); } } }, holderGameObject: _handleHolder); } }