C# 如何将三维模型动态添加到地平面
我使用Unity的地平面功能来放置一个3d动画模型。但是,我现在使用AssetBundle功能下载此3d模型,需要使用脚本将其放置在地平面舞台下方 但是,当我将它部署到android设备上时,它不会显示 我使用的是小米红米3s,它支持地平面检测 我添加了将资产包下载到Plane Finder的脚本 AssetbundleDownloadingScript:C# 如何将三维模型动态添加到地平面,c#,unity3d,vuforia,assetbundle,C#,Unity3d,Vuforia,Assetbundle,我使用Unity的地平面功能来放置一个3d动画模型。但是,我现在使用AssetBundle功能下载此3d模型,需要使用脚本将其放置在地平面舞台下方 但是,当我将它部署到android设备上时,它不会显示 我使用的是小米红米3s,它支持地平面检测 我添加了将资产包下载到Plane Finder的脚本 AssetbundleDownloadingScript: public class AssetLoader : MonoBehaviour { public static AssetLoa
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);
}
}
以下是我的场景截图:
对我做错了什么有什么建议吗?谢谢。我注意到在您的
AssetbundleDownloadingScript
中,您正在创建一个游戏对象集
,但是您从未将该对象分配给新的
或现有的游戏对象,甚至从未将其实例化。而是分配从捆绑包中加载的资产
。然而,该资产也从未分配,因为它只是加载到内存中,以便Unity能够识别它。这就是你正在经历的,这就是为什么你在游戏中看到这个物体,但它不是活动的,甚至是坚硬的,它没有被禁用
要解决此问题,您必须指定您的游戏对象或按如下方式实例化它:
GameObject santaasset=实例化(bundle.LoadAsset(“动画\关键帧\增加\ v1”,类型(游戏对象))为游戏对象)
您是否在编辑器中进行了测试,以查看您的资产包是否正确下载,以及您是否从中获取了模型?在编辑器中,当我按“播放”时,资产包已下载,并作为地平面舞台[链接]()的子级连接,如果您有网络摄像头,我建议也在编辑器中测试地平面。因为这可能是因为你的手机做的每件事都是正确的,唯一的问题是你的模型可能会被偏移或缩放不正确本文第11点尝试并设置santaasset.transform.transform.SetParent(child.transform,false);首先,然后执行缩放和旋转操作。如果轴不在中心,在添加为子对象之前进行向量和四元数放置可能会使它们放置在其他位置。如果你的飞机在现实世界中改变了位置,它将不会更新游戏中的位置,因为你以后附加它时,你的相对设置将丢失。你可以试着让我们知道这是否有效。@Hristo好的,我会用网络摄像头试试,让你知道。我使用adb检查debug.log打印的logcat消息,这是我得到的输出。。[链接]()命中测试无效或未设置锚定阶段