Portal belajar membuat aplikasi Augmented Reality dan Virtual Reality

Rabu, 19 September 2018

AssetBundle Loader

01.06 Posted by Dicky Rachmat Iskandar No comments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Video;

public class Loader : MonoBehaviour {
    
    public string assetBundleName;
    public GameObject videoPlane;
    public GameObject imagePlane;

    // Use this for initialization
    void Start () {
        //StartCoroutine(InstantiateVideoClip());
    }
    
    // Update is called once per frame
    void Update () {
        CloudContentLoader loader = GameObject.Find("System").GetComponent<CloudContentLoader>();
        if (loader.IsDone)
        {
            if (Input.GetKeyDown("space"))
            {
                AssetBundle bundle = loader.GetAssetBundleByKey(assetBundleName);
                PlayVideoClip(bundle.LoadAsset<VideoClip>("Video"));
                DisplayImageFile(bundle.LoadAsset<Texture2D>("Image"));

                Debug.Log("[Loader] " + assetBundleName + " is loaded");
            }
        }
    }
    

    void PlayVideoClip(VideoClip videoClip)
    {
        var VideoPlayer = videoPlane.GetComponent<VideoPlayer>();
        VideoPlayer.clip = videoClip;
        VideoPlayer.Play();
    }

    void DisplayImageFile(Texture2D image)
    {
        var material = imagePlane.GetComponent<Renderer>().material;
        material.SetTexture("_MainTex", image);
    }
}