DLC system to AR App with Unity Addressables, Vuforia, and Firebase

故事扮演 提交于 2020-12-13 17:55:38

问题


I am about 3 months into the AR scene and I feel somewhat familiar with building an AR app with Vuforia in Unity. I want to add a DLC system to my AR app so that I can build and publish once, and update the content after the build. I will be doing future updates with new content for the app because it is a serialized book series with AR functions, and they file size will be huge with all the content on it.

My workflow is as follows: PRefabs with Images Targets and AR content 1)I have prefabs that with ImageTarget => AR content to display (3D models, Animation, graphics, and audio) I have them selected as Addressable and Labled "ARPages" Files Exported as Addressables 2)I also have my Vuforia Database (Images, .xml, and .dat) as Addressable.I want to be able to update and add to the database post build then sync it with new prefabs that I make Addressable. ARCamera Scene with Empty GameObject 3)I build out the lightweight AR app without the AR content as prefabs, but I have an empty game object in my AR Scene (ARCamera => GameObject) with a script that calls an AssetLabelReference labeled "ARPages".

using UnityEngine.SceneManagement;
using UnityEngine;
using System;
using System.Collections.Generic;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement;
using Vuforia;

public class GameManager1 : MonoBehaviour
{

    public AssetLabelReference comicbookName;
    private bool mLoaded = false;
    private DataSet mDataset = null;

void Awake()
    {
        Addressables.DownloadDependenciesAsync(comicbookName);
    }
    void Start()
    {

        Addressables.InstantiateAsync(comicbookName);
    }


    void Update()
    {
        if (VuforiaRuntimeUtilities.IsVuforiaEnabled() && !mLoaded)
        {
            string externalPath = Application.persistentDataPath;

            if (mDataset == null)
            {
                // First, create the dataset
                ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
                mDataset = tracker.CreateDataSet();
            }

            if (mDataset.Load(externalPath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
            {
                mLoaded = true;
            }
            else
            {
                Debug.LogError("Failed to load dataset!");
            }
        }
    }

}

Firebase Storage Files 4)Build Addressable packages and upload them to firebase Storage where they are downloaded to my device on startup Menu Scene using a script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.AddressableAssets;
using Vuforia;

public class LoadAssetsFromRemote : MonoBehaviour
{

    [SerializeField] private AssetLabelReference _label;

    // Start is called before the first frame update
   private void Start()
    {
        Get(_label);
    }

private async Task Get(AssetLabelReference label)
{
 var locations = await Addressables.LoadResourceLocationsAsync(label).Task;
 foreach (var location in locations)
 {
await Addressables.InstantiateAsync(location).Task;
 }
}

    // Update is called once per frame
    void Update()
    {

    }
}

5)When I click and open the AR Scene, I use a script to load and initialize Vuforia and the Database, but nothing happens when I shine my phone over the image target.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class MultiRecoScript : MonoBehaviour, ITrackableEventHandler
{
    public AudioClip musicFx;
    public Animator[] myAnimator;

    private TrackableBehaviour mTrackableBehaviour;

    void Start()
    {
        //Fetch the Animator from your GameObject
        myAnimator = GetComponentsInChildren<Animator>();

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
    }

    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            //lancio la musica
            Debug.Log("sound");
            AudioManagerScript.current.PlaySound(musicFx);

            foreach (Animator animator in myAnimator)
            {
                animator.speed = 1f;
                animator.gameObject.SetActive(true);

            }

        }
        else
        {
            // stoppo la musica
            AudioManagerScript.current.StopSound();
            //  Debug.Log("stoppo");

            foreach (Animator animator in myAnimator)
            {
                animator.gameObject.SetActive(false);

            }
        }
    }


}

I am stuck. Could use help and feedback. I want to be able to load new content to firebase using addressables system in unity, and have the app download the new content and implement the new content without having to rebuild the app everytime I want to update the content.

来源:https://stackoverflow.com/questions/60593471/dlc-system-to-ar-app-with-unity-addressables-vuforia-and-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!