public IEnumerator _InstantiateObj(AssetAsyncLoadObjectCB cb, string name, Vector3 position, Vector3 rotation, Vector3 scale, bool setposdir) { AssetBundleRequest request = null; bool isTypeGameObject = false; System.Type otype = null; switch (type) { case Asset.TYPE.TERRAIN_DETAIL_TEXTURE: otype = typeof(UnityEngine.Texture2D); break; default: otype = typeof(UnityEngine.GameObject); isTypeGameObject = true; break; } ; if (mainAsset == null) { try { request = bundle.LoadAsync(source.Replace(".unity3d", ""), otype); } catch (Exception e) { Common.ERROR_MSG("Asset::_InstantiateObj: " + e.ToString()); } } UnityEngine.Object go = null; if (request != null) { yield return(request); mainAsset = request.asset; isLoaded = true; } //if(mainAsset != null) if (!(System.Object.ReferenceEquals(mainAsset, null))) { if (setposdir == true) { go = UnityEngine.GameObject.Instantiate(mainAsset, position, Quaternion.Euler(rotation)); go.name = name; if ((type == TYPE.WORLD_OBJ || type == TYPE.NORMAL) && layerName != "" && layerName != "Default") { ((UnityEngine.GameObject)go).layer = LayerMask.NameToLayer(layerName); } if (isTypeGameObject == true) { ((UnityEngine.GameObject)go).transform.localScale = scale; } Common.DEBUG_MSG("Asset::Instantiate: " + name + "(source=" + source + "), pos:" + position + ", dir:" + rotation + ", scale:" + scale + ", layer:" + layerName); } else { go = UnityEngine.GameObject.Instantiate(mainAsset); go.name = name; if ((type == TYPE.WORLD_OBJ || type == TYPE.NORMAL) && layerName != "" && layerName != "Default") { ((UnityEngine.GameObject)go).layer = LayerMask.NameToLayer(layerName); } if (isTypeGameObject == true) { Common.DEBUG_MSG("Asset::Instantiate(auto): " + name + ", pos:" + ((UnityEngine.GameObject)go).transform.position + ", dir:" + ((UnityEngine.GameObject)go).transform.rotation + ", scale:" + ((UnityEngine.GameObject)go).transform.localScale); } else { Common.DEBUG_MSG("Asset::Instantiate: " + name); } } } else { bundle.LoadAll(); Common.ERROR_MSG("Asset::Instantiate: build [" + name + "], source[" + source.Replace(".unity3d", "") + "], realbundleName[" + bundle.mainAsset.name + "] is failed!"); } cb.onAssetAsyncLoadObjectCB(name, go, this); }
public void Instantiate(AssetAsyncLoadObjectCB cb, string name) { loader.inst.StartCoroutine(_InstantiateObj(cb, name, Vector3.zero, Vector3.zero, Vector3.zero, false)); }
public void Instantiate(AssetAsyncLoadObjectCB cb, string name, Vector3 position, Vector3 rotation, Vector3 scale) { loader.inst.StartCoroutine(_InstantiateObj(cb, name, position, rotation, scale, true)); }
public IEnumerator _InstantiateObj(AssetAsyncLoadObjectCB cb, string name, Vector3 position, Vector3 rotation, Vector3 scale, bool setposdir) { AssetBundleRequest request = null; bool isTypeGameObject = false; System.Type otype = null; switch(type) { case Asset.TYPE.TERRAIN_DETAIL_TEXTURE: otype = typeof(UnityEngine.Texture2D); break; default: otype = typeof(UnityEngine.GameObject); isTypeGameObject = true; break; }; if(mainAsset == null) { try { request = bundle.LoadAsync(source.Replace(".unity3d", ""), otype); } catch (Exception e) { Common.ERROR_MSG("Asset::_InstantiateObj: " + e.ToString()); } } UnityEngine.Object go = null; if(request != null) { yield return request; mainAsset = request.asset; isLoaded = true; } if(mainAsset != null) { if(setposdir == true) { go = UnityEngine.GameObject.Instantiate(mainAsset, position, Quaternion.Euler(rotation)); go.name = name; if((type == TYPE.WORLD_OBJ || type == TYPE.NORMAL) && layerName != "" && layerName != "Default") ((UnityEngine.GameObject)go).layer = LayerMask.NameToLayer(layerName); if(isTypeGameObject == true) ((UnityEngine.GameObject)go).transform.localScale = scale; Common.DEBUG_MSG("Asset::Instantiate: " + name + "(source=" + source + "), pos:" + position + ", dir:" + rotation + ", scale:" + scale + ", layer:" + layerName); } else { go = UnityEngine.GameObject.Instantiate(mainAsset); go.name = name; if((type == TYPE.WORLD_OBJ || type == TYPE.NORMAL) && layerName != "" && layerName != "Default") ((UnityEngine.GameObject)go).layer = LayerMask.NameToLayer(layerName); if(isTypeGameObject == true) { Common.DEBUG_MSG("Asset::Instantiate(auto): " + name + ", pos:" + ((UnityEngine.GameObject)go).transform.position + ", dir:" + ((UnityEngine.GameObject)go).transform.rotation + ", scale:" + ((UnityEngine.GameObject)go).transform.localScale); } else{ Common.DEBUG_MSG("Asset::Instantiate: " + name ); } } } else { bundle.LoadAll(); Common.ERROR_MSG("Asset::Instantiate: build [" + name + "], source[" + source.Replace(".unity3d", "") + "], realbundleName[" + bundle.mainAsset.name + "] is failed!"); } cb.onAssetAsyncLoadObjectCB(name, go, this); }