using QFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SandTable : MonoSingleton { public MaterialObjValue value; public int updateTime; public void OpenSandTable() { if(value ==null) { GameManager.Instance.OpenPlanel(); } else if ( value.DownloadPath != value.localSavePath) { MsgHandler.AddListener(value.DownloadPath, HandleMsg); LoadManager.Instance.LoadMaterial(value, updateTime); } else if( value.DownloadPath == value.localSavePath) { LoadLocalMaterial(); } } /// /// 返回素材 /// /// private void HandleMsg(Msg msg) { LoadMaterial(msg.Value); } /// /// 加载素材 /// /// 返回加载物体 public void LoadMaterial(object loaderObj) { var loader = ResLoader.Allocate(); switch ((MaterialType)int.Parse(value.type)) { case MaterialType.Text: string path = "Resources/Template/Prefab/Text"; //if (int.Parse(value.TextBJ) == 1) //{ // path = "Resources/Template/Prefab/Text"; //} var mText = loader.LoadSync(path); GameObject objText = (GameObject)mText.Instantiate(); objText.GetComponent().SetText(loaderObj.ToString()); objText.transform.SetParent(transform); objText.name = value.name; objText.transform.Identity(); break; case MaterialType.Image: var image = loader.LoadSync("Resources/Template/Prefab/Image"); GameObject objImage = image.Instantiate(); objImage.GetComponent().SetImage((Sprite)loaderObj); objImage.transform.SetParent(transform); objImage.name = value.name; objImage.transform.Identity(); break; case MaterialType.Video: var video = loader.LoadSync("Resources/Template/Prefab/Video"); GameObject objVideo = video.Instantiate(); objVideo.GetComponent().VideoURL = loaderObj.ToString(); objVideo.transform.SetParent(transform); objVideo.name = value.name; objVideo.transform.Identity(); break; case MaterialType.Model: List listobj = (List)loaderObj; GameObject model = listobj[0]; GameObject objModel = model.Instantiate(); objModel.transform.SetParent(transform); objModel.name = value.name; objModel.transform.Identity(); break; default: break; } MsgHandler.RemoveListener(value.DownloadPath, HandleMsg); StartCoroutine(OpenPlanel(15)); } /// /// 加载本地素材 /// public void LoadLocalMaterial() { Debug.Log(value.name + " 本地素材@@@@@@@@@@@@@"); var loader = ResLoader.Allocate(); switch ((MaterialType)int.Parse(value.type)) { case MaterialType.Text: string path = "Resources/Template/Prefab/Text"; if (int.Parse(value.TextBJ) == 1) { path = "Resources/Template/Prefab/Text111111111111111"; } var mText = loader.LoadSync(path); GameObject objText = (GameObject)mText.Instantiate(); objText.GetComponent().SetText(value.textContent); objText.transform.SetParent(transform); objText.name = value.name; objText.transform.Identity(); break; case MaterialType.Image: var image = loader.LoadSync("Resources/Template/Prefab/Image"); GameObject objImage = image.Instantiate(); objImage.GetComponent().SetImage(loader.LoadSync(value.DownloadPath)); objImage.transform.SetParent(transform); objImage.name = value.name; objImage.transform.Identity(); break; case MaterialType.Video: var video = loader.LoadSync("Resources/Template/Prefab/Video"); GameObject objVideo = video.Instantiate(); objVideo.GetComponent().VideoURL = value.DownloadPath; objVideo.transform.SetParent(transform); objVideo.name = value.name; objVideo.transform.Identity(); break; case MaterialType.Model: GameObject model = loader.LoadSync(value.DownloadPath); GameObject objModel = model.Instantiate(); objModel.transform.SetParent(transform); objModel.name = value.name; objModel.transform.Identity(); break; default: break; } StartCoroutine(OpenPlanel(15)); } IEnumerator OpenPlanel( float times) { yield return new WaitForSeconds(times); GameManager.Instance.OpenPlanel(); gameObject.SetActive(false); } }