【发布时间】:2018-04-26 05:04:16
【问题描述】:
我使用 Unity 的地平面功能来放置 3D 动画模型。但是我现在正在使用 AssetBundle 功能下载这个 3d 模型,并且需要使用脚本将它放在 Ground Plane Stage 下。
但是当我将它部署到安卓设备上时它不显示...
我使用的是支持 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);
}
}
关于我做错了什么有什么建议吗?谢谢。
【问题讨论】:
-
您是否在
Editor中测试过您的assetbundle是否已正确下载,并且您从中获取模型? -
在编辑器中,当我按下播放时,资产包被下载,并作为地平面阶段的子节点附加到 [link] (imgur.com/a/FDuAuCS)
-
如果您有网络摄像头,我建议您也可以在
Editor中测试地平面。由于您的手机可能一切正常,唯一的问题是您的模型可能会偏移或未正确缩放。 library.vuforia.com/articles/Solution/ground-plane-guide.html - 本文第 11 点 -
尝试设置 santaasset.transform.transform.SetParent(child.transform, false);首先,然后进行缩放和旋转操作。如果枢轴不在中心,则在添加为子元素之前进行向量和四元数放置可能会使它们放置在其他位置。如果您的飞机在现实世界中改变了位置,它不会更新游戏中的位置,因为您的相关设置会在您稍后附加时丢失。您可以尝试让我们知道这是否有效。
-
@Hristo 好的,我会用网络摄像头试试,让你知道。我使用 adb 检查 debug.log 打印的 logcat 消息,这是我得到的输出.. [link] (imgur.com/a/xPRGJ6N) Hit Test is invalid or anchor stage not set
标签: c# unity3d vuforia assetbundle