123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using QFramework;
- using QFramework.MREditor;
- public class MaterialShow : MonoBehaviour
- {
- public MaterialObjValue value;
- public string type;
- public int updateTime;
- public string spoitName;
- private void Start()
- {
- switch ((MaterialType) int.Parse( value.type))
- {
- case MaterialType.NULL:
- break;
- case MaterialType.Image:
-
- case MaterialType.Video:
-
- case MaterialType.Model:
-
- if (value.DownloadPath.IsNotNullAndEmpty()&&value.DownloadPath!=value.localSavePath)
- {
- MsgHandler.AddListener(value.DownloadPath, HandleMsg);
- LoadManager.Instance.LoadMaterial(value, updateTime);
-
- }
- else if (value.DownloadPath.IsNotNullAndEmpty() && value.DownloadPath == value.localSavePath)
- {
- LoadLocalMaterial();
- }
-
- break;
- case MaterialType.Text:
- //string str = value.textContent;
- //object loaderObj = str;
- //LoadMaterial(loaderObj);
- LoadLocalMaterial();
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 返回素材
- /// </summary>
- /// <param name="msg"></param>
- private void HandleMsg(Msg msg)
- {
- try
- {
- LoadMaterial(msg.Value);
- }
- catch (System.Exception e)
- {
- ErrorLogPanel.Instance.Show(" 返回生成素材出现错误 " + e.Message);
- }
- }
- int num = 0;
- /// <summary>
- /// 加载素材
- /// </summary>
- /// <param name="loaderObj"> 返回加载物体 </param>
- public void LoadMaterial(object loaderObj)
- {
- Debug.Log(value.name+" 下载素材@@@@@@@@@@@@@"+ num++);
-
- var loader = ResLoader.Allocate();
- switch ((MaterialType)int.Parse(value.type))
- {
- case MaterialType.Text:
- string path = "Resources/Template/Prefab/Text1";
- //if (int.Parse(value.TextBJ) == 1)
- //{
- // path = "Resources/Template/Prefab/Text";
- //}
- switch (value.TextBJ)
- {
- case "1":
- path = "Resources/Template/Prefab/Text1";
- break;
- case "2":
- path = "Resources/Template/Prefab/Text2";
- break;
- case "3":
- path = "Resources/Template/Prefab/Text3";
- break;
- default:
- break;
- }
-
- 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.LocalIdentity();
- if (value.ObjectTransform.nowScale == Vector3.zero)
- {
- if (value.textPosition == "bottom")
- {
- transform.localPosition = new Vector3(0, -0.5f, 0);
- Debug.Log("bottom" + transform.localPosition);
- }
- else if (value.textPosition == "top")
- {
- transform.localPosition = new Vector3(0, 0.5f, 0);
- Debug.Log("top" + transform.localPosition);
- }
- transform.localEulerAngles = Vector3.zero;
- transform.localScale = Vector3.one;
- }
- else
- {
- // SettingTransform(value.ObjectTransform);
- }
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName+value.name, objText.GetComponent<SelectBJImage>());
- 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.LocalIdentity();
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName + value.name, objImage.GetComponent<SelectBJImage>());
- 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.LocalIdentity();
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName + value.name, objVideo.GetComponent<SelectBJImage>());
- break;
- case MaterialType.Model:
- List<GameObject> listobj = (List<GameObject>)loaderObj;
- GameObject model = listobj[0];
- Debug.Log(model.name);
- GameObject objModel = null;
-
- if (model.name == "Saloon")
- {
- objModel = GameManager.Instance.Saloon;
- objModel.SetActive(true);
- }
- else
- {
- objModel = model.Instantiate();
- }
- if (model.name == "MainDargGames6")
- {
- GameManager.Instance.SZG.transform.SetParent(transform);
- GameManager.Instance.SZG.transform.LocalIdentity();
- }
- objModel.transform.SetParent(transform);
- objModel.name = value.name;
- objModel.transform.LocalIdentity();
- break;
- default:
- break;
- }
- MsgHandler.RemoveListener(value.DownloadPath, HandleMsg);
- SettingTransform(value.ObjectTransform);
- }
- //private void SettingTransform(MaterialObjValue value)
- //{
- // if (value.nowScale == Vector3.zero)
- // {
- // transform.localPosition = value.startPos;
- // transform.localEulerAngles = value.startRot;
- // transform.localScale = value.startScale;
- // }
- // else
- // {
- // transform.localPosition = value.nowPos;
- // transform.localEulerAngles = value.nowRot;
- // transform.localScale = value.nowScale;
- // }
- //}
- /// <summary>
- /// 加载本地素材
- /// </summary>
- public void LoadLocalMaterial()
- {
- try
- {
- Debug.Log(value.name + " 本地素材@@@@@@@@@@@@@");
- var loader = ResLoader.Allocate();
- switch ((MaterialType)int.Parse(value.type))
- {
- case MaterialType.Text:
- string path = "Resources/Template/Prefab/Text";
- switch (value.TextBJ)
- {
- case "1":
- path = "Resources/Template/Prefab/Text1";
- break;
- case "2":
- path = "Resources/Template/Prefab/Text2";
- break;
- case "3":
- path = "Resources/Template/Prefab/Text3";
- break;
- default:
- break;
- }
- 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.LocalIdentity();
- if (value.ObjectTransform.nowScale == Vector3.zero)
- {
- if (value.textPosition == "bottom")
- {
- transform.localPosition = new Vector3(0, -0.5f, 0);
- Debug.Log("bottom" + transform.localPosition);
- }
- else if (value.textPosition == "top")
- {
- transform.localPosition = new Vector3(0, 0.5f, 0);
- Debug.Log("top" + transform.localPosition);
- }
- transform.localEulerAngles = value.ObjectTransform.startRot;
- if (value.ObjectTransform.startScale != Vector3.zero)
- transform.localScale = value.ObjectTransform.startScale;
- else
- transform.localScale = Vector3.one;
- }
- else
- {
- SettingTransform(value.ObjectTransform);
- // value.ObjectTransform.SetObjectTransform(transform);
- }
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName + value.name, objText.GetComponent<SelectBJImage>());
- 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.LocalIdentity();
- SettingTransform(value.ObjectTransform);
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName + value.name, objImage.GetComponent<SelectBJImage>());
- 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.LocalIdentity();
- SettingTransform(value.ObjectTransform);
- UIKit.GetPanel<EditorPanel>().dicSelectBackImage.Add(spoitName + value.name, objVideo.GetComponent<SelectBJImage>());
- 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.LocalIdentity();
- SettingTransform(value.ObjectTransform);
- break;
- default:
- break;
- }
- }
- catch (System.Exception)
- {
- ErrorLogPanel.Instance.Show(" 加载本地素材出现错误 ");
-
- }
-
- //SettingTransform(value.ObjectTransform);
- }
- /// <summary>
- /// 设置Transform
- /// </summary>
- /// <param name="value"></param>
- private void SettingTransform(ObjectTransform value)
- {
- if (value.nowScale == Vector3.zero)
- {
- if (value.startScale == Vector3.zero)
- value.startScale = Vector3.one;
- transform.localPosition = value.startPos;
- transform.localEulerAngles = value.startRot;
- transform.localScale = value.startScale;
- Debug.Log(value.nowScale.x + " Start " + value.startPos.x);
- GameManager.Instance.text4.text = value.nowScale.x.ToString()+" "+ this.value.name + " " + value.nowPos.x.ToString();
- }
- else
- {
- transform.localPosition = value.nowPos;
- transform.localEulerAngles = value.nowRot;
- transform.localScale = value.nowScale;
- Debug.Log("now " + value.nowPos.x);
- GameManager.Instance.text4.text = value.nowScale.x.ToString() + " " + this.value.name + " " + value.nowPos.x.ToString();
- }
-
-
- }
- }
|