/**************************************************************************** * 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> dicBtns = new Dictionary>(); private Dictionary> dicCMVBtns = new Dictionary>(); private string oldSpoitName; private MaterialBtn selectBtn; public void Initialized(string spoitName, List listObjs, MaterialBtn materialBtn) { oldSpoitName = ""; group = UIMaterialContent.GetComponent(); dicBtns.Add(spoitName, new List()); 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()); 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.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().anchoredPosition3D; // btn.GetComponent().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.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().anchoredPosition3D; btn.GetComponent().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.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().anchoredPosition3D; btn.GetComponent().anchoredPosition3D = new Vector3(pos.x, pos.y, 0); btn.transform.localEulerAngles = Vector3.one; materialitem = btn; }) .Show(); UIMaterialContent.GetComponent().sizeDelta += new Vector2(0, 100 ); return materialitem; } /// /// 选择当前景点 ,目前用扫图触发的方式 /// /// 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().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()); 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().localEulerAngles = Vector3.zero; // Toggle toggle = btn.GetComponent(); // 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().anchoredPosition3D; // btn.GetComponent().anchoredPosition3D = new Vector3(pos.x,pos.y,0); // }) // .Show(); // AddMaterialBtn.transform.SetAsLastSibling(); // UIMaterialContent.GetComponent().sizeDelta += new Vector2(0, 70); //} #endregion } }