123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using QFramework;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SandTable : MonoSingleton<SandTable>
- {
- 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();
- }
-
- }
-
- /// <summary>
- /// 返回素材
- /// </summary>
- /// <param name="msg"></param>
- private void HandleMsg(Msg msg)
- {
- LoadMaterial(msg.Value);
- }
- /// <summary>
- /// 加载素材
- /// </summary>
- /// <param name="loaderObj"> 返回加载物体 </param>
- 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<GameObject>(path);
- GameObject objText = (GameObject)mText.Instantiate();
- objText.GetComponent<SetTextV>().SetText(loaderObj.ToString());
- objText.transform.SetParent(transform);
- objText.name = value.name;
- objText.transform.Identity();
- break;
- case MaterialType.Image:
- var image = loader.LoadSync<GameObject>("Resources/Template/Prefab/Image");
- GameObject objImage = image.Instantiate();
- objImage.GetComponent<SetImageV>().SetImage((Sprite)loaderObj);
- objImage.transform.SetParent(transform);
- objImage.name = value.name;
- objImage.transform.Identity();
-
- break;
- case MaterialType.Video:
- var video = loader.LoadSync<GameObject>("Resources/Template/Prefab/Video");
- GameObject objVideo = video.Instantiate();
- objVideo.GetComponent<VideoControl>().VideoURL = loaderObj.ToString();
- objVideo.transform.SetParent(transform);
- objVideo.name = value.name;
- objVideo.transform.Identity();
-
- break;
- case MaterialType.Model:
- List<GameObject> listobj = (List<GameObject>)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));
- }
- /// <summary>
- /// 加载本地素材
- /// </summary>
- 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<GameObject>(path);
- GameObject objText = (GameObject)mText.Instantiate();
- objText.GetComponent<SetTextV>().SetText(value.textContent);
- objText.transform.SetParent(transform);
- objText.name = value.name;
- objText.transform.Identity();
- break;
- case MaterialType.Image:
- var image = loader.LoadSync<GameObject>("Resources/Template/Prefab/Image");
- GameObject objImage = image.Instantiate();
- objImage.GetComponent<SetImageV>().SetImage(loader.LoadSync<Sprite>(value.DownloadPath));
- objImage.transform.SetParent(transform);
- objImage.name = value.name;
- objImage.transform.Identity();
- break;
- case MaterialType.Video:
- var video = loader.LoadSync<GameObject>("Resources/Template/Prefab/Video");
- GameObject objVideo = video.Instantiate();
- objVideo.GetComponent<VideoControl>().VideoURL = value.DownloadPath;
- objVideo.transform.SetParent(transform);
- objVideo.name = value.name;
- objVideo.transform.Identity();
- break;
- case MaterialType.Model:
- GameObject model = loader.LoadSync<GameObject>(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);
- }
- }
|