123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /****************************************************************************
- * 2022.1 SK-20211220VCWK
- ****************************************************************************/
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using UniRx;
- using System.Collections;
- using System.IO;
- namespace QFramework.MREditor
- {
- public partial class UIAddMaterial : UIElement
- {
- private void Awake()
- {
-
- }
- protected override void OnBeforeDestroy()
- {
- }
- public void Close()
- {
- gameObject.SetActive(false);
- }
- private CompositeMaterialValue selectObj;
-
- /// <summary>
- /// 根据传进来的Json文件 生成对应数据(主要是 用户自己上传的数据)
- /// </summary>
- public void Initialized( List<CompositeMaterialValue> localMaterials ,List<CompositeMaterialValue> upLocalMaterials ,SingleMaterial material )
- {
- selectObj = null;
- UCBtn.onClick.AddListener(() =>
- {
- if (LocalView.gameObject.activeSelf)
- return;
- LocalView.gameObject.SetActive(true);
- UpLoadView.gameObject.SetActive(false);
- });
- TicBtn.onClick.AddListener(() =>
- {
- if (UpLoadView.gameObject.activeSelf)
- return;
- LocalView.gameObject.SetActive(false);
- UpLoadView.gameObject.SetActive(true);
- });
- ADDBtn.onClick.AddListener(() =>
- {
- //Debug.Log(selectObj.name +" ?????????");
- // 添加选中素材
- //if (selectObj==null)
- // return;
- SendMsg(new OnAddNewMaterial(selectObj));
- });
- CloseBtn.onClick.AddListener(() =>
- {
- selectObj = null;
- Debug.Log("Close" + "@@@@");
- SendMsg(new OnUIOpenElenemt(true));
- });
- LocalContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, (localMaterials.Count / 3 + 1) * 140 + 25);
- localMaterials.ForEach(item =>
- {
- material.Instantiate()
- .Parent(LocalContent)
- .Identity()
- .ApplySelfTo(SelfObj =>
- {
- SelfObj.Name.text = item.name;
- SelfObj.GetComponent<Button>().onClick.AddListener(() => { selectObj = item; Debug.Log(item.name); });
- Vector3 pos = SelfObj.GetComponent<RectTransform>().anchoredPosition3D;
- SelfObj.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
- LoadSprite(SelfObj.Image, item);
- })
- .Show();
-
- });
-
- UpLoadContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, (upLocalMaterials.Count / 3 + 1) * 140 + 25);
- upLocalMaterials.ForEach(item =>
- {
- material.Instantiate()
- .Parent(UpLoadContent)
- .Identity()
- .ApplySelfTo(SelfObj =>
- {
- SelfObj.Name.text = item.name;
- SelfObj.GetComponent<Button>().onClick.AddListener(() => { selectObj = item; Debug.Log(item.name); });
- Vector3 pos = SelfObj.GetComponent<RectTransform>().anchoredPosition3D;
- SelfObj.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
- LoadSprite(SelfObj.Image, item);
- })
- .Show();
- });
- // Debug.Log(upLocalMaterials.Count);
- }
- /// <summary>
- /// 加载背景图片
- /// </summary>
- /// <param name="image"></param>
- /// <param name="objValue"></param>
- public void LoadSprite(Image image , CompositeMaterialValue objValue)
- {
- var loader = ResLoader.Allocate();
- if(objValue.icon.IsNullOrEmpty())
- {
- switch ((MaterialType)objValue.type)
- {
- case MaterialType.NULL:
- break;
- case MaterialType.Image:
- objValue.icon = "";
- break;
- case MaterialType.Video:
- objValue.icon = "";
- break;
- case MaterialType.Model:
- objValue.icon = "";
- break;
- case MaterialType.Text:
- objValue.icon = "";
- break;
- case MaterialType.ImageorViedoAndText:
- objValue.icon = "";
- break;
- case MaterialType.ModelAndText:
- objValue.icon = "";
- break;
- default:
- break;
- }
- // image.sprite = loader.LoadSync<Sprite>(objValue.icon);
- }
- else
- {
- if(objValue.icon.Contains("Resources/LocalMaterials"))
- {
- image.sprite = loader.LoadSync<Sprite>(objValue.icon);
- }
- else
- {
- Debug.Log("LoadManager.Instance.GetMaterial");
- object obj = LoadManager.Instance.GetMaterial(objValue.icon, objValue.updateTime);
- if (obj != null)
- image.sprite = (Sprite)obj;
- }
- //image.sprite = loader.LoadSync<Sprite>(objValue.icon);
- }
- //
- }
-
- }
- }
|