目前進展
我已經完成本週上一篇博客所說的動態加載並綁定出一組圖片和視頻文件。其具體做法是:
首先,我們應該先把已經做好的一組ImageTarget和帶有videoplayer腳本的Plane綁定爲一個prefab,然後在一個manager中動態的生成這個prefab。其代碼如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EasyAR;
public class ImageTargetManager : MonoBehaviour {
public GameObject videoPrefab;
// Use this for initialization
void Awake () {
GameObject videoPlayer = Instantiate(videoPrefab);
var ITbehaviour = videoPlayer.GetComponent<ImageTargetBehaviour>();
ITbehaviour.Path = "image1.jpg";
ITbehaviour.Name = "image1";
ITbehaviour.Storage = StorageType.Assets;
ITbehaviour.Bind(GameObject.Find("ImageTracker").GetComponent<ImageTrackerBehaviour>());
ITbehaviour.Size = new Vector2(8.0f, 4.5f);
var VPbehaviour = videoPlayer.transform.GetChild(0).GetComponent<VideoPlayerBehaviour>();
VPbehaviour.Path = "video1.mp4";
VPbehaviour.Storage = StorageType.Assets;
VPbehaviour.VideoScaleMode = EasyAR.VideoPlayerBaseBehaviour.ScaleMode.Fill;
VPbehaviour.EnableAutoPlay = true;
VPbehaviour.EnableLoop = true;
VPbehaviour.OpenWhenStart = true;
VPbehaviour.VideoScaleFactorBase = 0.1f;
}
}
下步目標
當然,目前還僅僅是使用在StreamingAssets中的文件,還不是真正意義上的動態加載,我要等做服務器的小夥伴完成之後,使用在persistentAssets文件夾中的圖片和視頻文件進行動態的綁定。