我使用Unity的地平面功能来放置一个3D动画模型。但是我现在正在使用AssetBundle功能下载这个3D模型,需要使用脚本将它放在地平面舞台上。
然而,当我将它部署到Android设备上时它不会显示...
我正在使用支持GroundPlane检测的小米Redmi 3s。
我已添加脚本以将资产包下载到Plane Finder
AssetbundleDownloadingScript :
public class AssetLoader : MonoBehaviour
{
public static AssetLoader Instance;
public string url = "myurl";
public int version = 1;
public string AssetName;
//public Text infoText;
public string infoText = "";
AssetBundle bundle;
void Awake()
{
Instance = this;
DownloadAsset();
}
void OnDisable()
{
//AssetBundleManager.Unload(url, version);
}
public void DownloadAsset()
{
// bundle = AssetBundleManager.getAssetBundle (url, version);
// Debug.Log(bundle);
if (!bundle)
StartCoroutine(DownloadAssetBundle());
}
IEnumerator DownloadAssetBundle()
{
yield return StartCoroutine(AssetBundleManager.downloadAssetBundle(url, version));
bundle = AssetBundleManager.getAssetBundle(url, version);
if (bundle != null)
infoText = "Download Success.....";
else
infoText = "Download error please retry";
GameObject santaasset = bundle.LoadAsset("animation_keyframes_increase_v1", typeof(GameObject)) as GameObject;
//here script attached to plane finder,get 1st child of planefinder
var child = gameObject.transform.GetChild(0);
if (santaasset != null)
{
santaasset.transform.transform.Rotate(new Vector3(0, 180, 0));
santaasset.transform.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
santaasset.transform.transform.SetParent(child.transform, false);
}
bundle.Unload(false);
}
public void SetInfoText(string text)
{
//infoText.text = text;
}
void OnGUI()
{
GUILayout.Label("Dummy Label:" + infoText);
}
}
有关我做错的任何建议吗?感谢。
答案 0 :(得分:1)
我注意到你AssetbundleDownloadingScript
正在创建一个GameObject santaasset
,但是你永远不会将对象分配给new
或现有的GameObject,甚至Instantiating
。您只需从Asset
分配要加载的bundle
即可。但是,该资产也从未被分配,因为它只是被加载到内存中,因此Unity可以识别它。这就是你所经历的,这就是你在游戏中看到对象的原因,但它不活跃,甚至很难被禁用。
要解决此问题,您必须分配您的GameObject或将其实例化为:
GameObject santaasset = Instantiate(bundle.LoadAsset("animation_keyframes_increase_v1", typeof(GameObject)) as GameObject);