123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- /****************************************************************************
- * 2022.1 SK-20211220VCWK
- ****************************************************************************/
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using UniRx;
- namespace QFramework.MREditor
- {
- public partial class UIMaterials : UIElement
- {
- private void Awake()
- {
- }
- protected override void OnBeforeDestroy()
- {
- }
- private ToggleGroup group;
- private Dictionary<String, List< MaterialBtn>> dicBtns = new Dictionary<string, List<MaterialBtn>>();
- private Dictionary<string, List<MaterialBtn>> dicCMVBtns = new Dictionary<string, List<MaterialBtn>>();
- private string oldSpoitName;
- private MaterialBtn selectBtn;
- public void Initialized(string spoitName, List<CompositeMaterialValue> listObjs, MaterialBtn materialBtn)
- {
- oldSpoitName = "";
- group = UIMaterialContent.GetComponent<ToggleGroup>();
- dicBtns.Add(spoitName, new List<MaterialBtn>());
- InitBtn();
- // AddMaterialBtn.Hide();
- Debug.Log("#### "+listObjs.Count);
- for (int i = 0; i < listObjs.Count; i++)
- {
- Debug.Log((MaterialType)listObjs[i].type);
- switch ((MaterialType)listObjs[i].type)
- {
- case MaterialType.NULL:
- break;
- case MaterialType.Image:
-
- case MaterialType.Video:
-
- case MaterialType.Model:
-
- case MaterialType.Text:
- //CreateMaterialBtn(listObjs[i].materialList[0].name, listObjs[i].name, spoitName, materialBtn);
- //break;
- case MaterialType.ImageorViedoAndText:
-
- case MaterialType.ModelAndText:
- Debug.Log(listObjs[i].name);
- dicCMVBtns.Add(spoitName+listObjs[i].name, new List<MaterialBtn>());
- Debug.Log(listObjs[i].name);
- dicCMVBtns[spoitName + listObjs[i].name].Add(CreateMaterialBtn(listObjs[i].name, listObjs[i].name, spoitName, materialBtn));
- Debug.Log(listObjs[i].name+1111);
- listObjs[i].materialList.ForEach(item =>
- {
- dicCMVBtns[spoitName + listObjs[i].name].Add(CreateMaterialBtn(item.name, listObjs[i].name, spoitName, materialBtn));
- });
- break;
- default:
- break;
- }
- }
- #region Old
- //listObjs.ForEach(item =>
- //{
- // materialBtn.Instantiate()
- // .Parent(UIMaterialContent)
- // .Identity()
- // .ApplySelfTo(btn =>
- // {
- // Toggle toggle = btn.GetComponent<Toggle>();
- // toggle.onValueChanged.AddListener(state =>
- // {
- // if (state)
- // {
- // SendMsg(new OnSelectObjName(item.name, spoitName));
- // selectBtn = btn;
- // }
- // });
- // toggle.group = group;
- // btn.Text.text = item.name;
- // dicBtns[spoitName].Add(btn);
- // Vector3 pos = btn.GetComponent<RectTransform>().anchoredPosition3D;
- // btn.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
- // });
- //});
- #endregion
- }
- public MaterialBtn CreateMaterialBtn(string Name ,string CMVName , string spoitName ,MaterialBtn materialBtn)
- {
- return materialBtn.Instantiate()
- .Parent(UIMaterialContent)
- .Identity()
- .ApplySelfTo(btn =>
- {
- Toggle toggle = btn.GetComponent<Toggle>();
- toggle.onValueChanged.AddListener(state =>
- {
- if (state)
- {
- SendMsg(new OnSelectObjName(Name, CMVName, spoitName));
- selectBtn = btn;
- }
- });
- toggle.group = group;
- btn.Text.text = Name;
- dicBtns[spoitName].Add(btn);
- Vector3 pos = btn.GetComponent<RectTransform>().anchoredPosition3D;
- btn.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
- btn.transform.localEulerAngles = Vector3.one;
- Debug.Log(spoitName + " " + CMVName + " " + Name);
- });
-
- }
- public MaterialBtn CreateMaterialBtn(string Name, string CMVName, string spoitName, MaterialBtn materialBtn ,bool f)
- {
- MaterialBtn materialitem = null;
- materialBtn.Instantiate()
- .Parent(UIMaterialContent)
- .Identity()
- .ApplySelfTo(btn =>
- {
- Toggle toggle = btn.GetComponent<Toggle>();
- toggle.onValueChanged.AddListener(state =>
- {
- if (state)
- {
- SendMsg(new OnSelectObjName(Name, CMVName, spoitName));
- selectBtn = btn;
- }
- });
- toggle.group = group;
- btn.Text.text = Name;
- dicBtns[spoitName].Add(btn);
- Vector3 pos = btn.GetComponent<RectTransform>().anchoredPosition3D;
- btn.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x, pos.y, 0);
- btn.transform.localEulerAngles = Vector3.one;
- materialitem = btn;
- })
- .Show();
- UIMaterialContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, 100 );
- return materialitem;
- }
- /// <summary>
- /// 选择当前景点 ,目前用扫图触发的方式
- /// </summary>
- /// <param name="spoitName"> </param>
- public void SelectSpoit( string spoitName)
- {
- if (!dicBtns.ContainsKey(spoitName))
- return;
- if (oldSpoitName.IsNotNullAndEmpty())
- dicBtns[oldSpoitName].ForEach(item =>
- {
- item.Hide();
- });
- dicBtns[spoitName].ForEach(item =>
- {
- item.Show();
- // Debug.Log(spoitName + " Show");
- });
- UIMaterialContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, (dicBtns[spoitName].Count+2) * 70 + 15);
- oldSpoitName = spoitName;
- Debug.Log(dicBtns[spoitName].Count);
- if(dicBtns[spoitName].Count>0)
- selectBtn = dicBtns[spoitName][0];
- ALLBtn.transform.SetAsFirstSibling();
- AddMaterialBtn.transform.SetAsLastSibling();
- }
- public void RemoveMaterials( string selectName)
- {
- if(selectBtn!=null)
- {
- selectBtn.Hide();
- selectBtn = null;
- if(dicCMVBtns.ContainsKey(selectName))
- {
- dicCMVBtns[selectName].ForEach(item =>
- {
- item.Hide();
- });
- }
- }
- }
- public void AddMaterial(string spoitName, CompositeMaterialValue objValue, MaterialBtn materialBtn)
- {
- switch ((MaterialType)objValue.type)
- {
- case MaterialType.NULL:
- break;
- case MaterialType.Image:
-
- case MaterialType.Video:
-
- case MaterialType.Model:
-
- case MaterialType.Text:
- //CreateMaterialBtn(objValue.materialList[0].name, objValue.name, spoitName, materialBtn, false);
- //break;
- case MaterialType.ImageorViedoAndText:
-
- case MaterialType.ModelAndText:
- dicCMVBtns.Add(spoitName + objValue.name, new List<MaterialBtn>());
- dicCMVBtns[spoitName + objValue.name].Add(CreateMaterialBtn(objValue.name, objValue.name, spoitName, materialBtn, false));
- objValue.materialList.ForEach(item =>
- {
- Debug.Log(item.name);
- dicCMVBtns[spoitName + objValue.name].Add(CreateMaterialBtn(item.name, objValue.name, spoitName, materialBtn, false));
- });
- break;
- default:
- break;
- }
- AddMaterialBtn.transform.SetAsLastSibling();
-
- }
- public void InitBtn()
- {
- ALLBtn.onValueChanged.AddListener(state =>
- {
- if (state)
- {
- // 选择整体
- if (oldSpoitName.IsNotNullAndEmpty())
- SendMsg(new OnSelectObjName(oldSpoitName, oldSpoitName, oldSpoitName));
- }
- });
- AddMaterialBtn.onValueChanged.AddListener(state =>
- {
- if (state)
- {
- SendMsg(new OnUIOpenElenemt(false));
- }
- });
- }
- #region Old
- //public void AddMaterial(string spoitName, MaterialObjValue objValue, MaterialBtn materialBtn)
- // {
- // materialBtn.Instantiate()
- // .Parent(UIMaterialContent)
- // .Identity()
- // .ApplySelfTo(btn =>
- // {
- // btn.GetComponent<RectTransform>().localEulerAngles = Vector3.zero;
- // Toggle toggle = btn.GetComponent<Toggle>();
- // toggle.onValueChanged.AddListener(state =>
- // {
- // if (state)
- // {
- // SendMsg(new OnSelectObjName(objValue.name, spoitName));
- // selectBtn = btn;
- // }
- // });
- // toggle.group = group;
- // btn.Text.text = objValue.name;
- // dicBtns[spoitName].Add(btn);
- // Vector3 pos = btn.GetComponent<RectTransform>().anchoredPosition3D;
- // btn.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(pos.x,pos.y,0);
- // })
- // .Show();
- // AddMaterialBtn.transform.SetAsLastSibling();
- // UIMaterialContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, 70);
- //}
- #endregion
- }
- }
|