using SC.XR.Unity; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 单排平铺 /// public class SRTitleLayout : MonoBehaviour { /// /// 根据素材数量对物体进行布局组合 /// 忽略文字类型 /// /// 素材 /// 素材父物体,景点 /// public static List CalLayout(SpoitValue spoitjd, MaterialObl materialObls, GameObject par, out MaterialObl newmaterial,string type ="1") { Debug.Log("CalLayoutCalLayoutCalLayoutCalLayout"); var yangshi = ResMgr.Instance.Load("yangshi" + materialObls.typesetting); GameObject ys = Instantiate((yangshi as GameObject), par.transform); YangShiManager ysm = ys.GetComponent(); ys.transform.localEulerAngles = Vector3.zero; ys.transform.localScale = new Vector3(1, 1, 1); newmaterial = materialObls; BaseTemPlate text = new BaseTemPlate(); List noText = new List(); MaterialObjValue textmat = null; List objectValues = new List(); ysm.yangshiText.gameObject.SetActive(false); Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + materialObls.materialList.Count); for (int i = 0; i < materialObls.materialList.Count; i++) { var mat = materialObls.materialList[i]; Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.type); GameObject go = null; switch (mat.type) { case (int)MaterialType.None: ysm.yangshiList[i].Close(); break; case (int)MaterialType.Image: go = ysm.yangshiList[i].showimg(); var imageitem = go.AddComponent(); go.SetActive(true); imageitem.SetData(mat, materialObls.updateTime); noText.Add(imageitem); break; case (int)MaterialType.Video: go = ysm.yangshiList[i].showvideo(); var videoitem = go.AddComponent(); videoitem.autoplay = materialObls.autoplay; go.SetActive(true); videoitem.SetData(mat, materialObls.updateTime); noText.Add(videoitem); break; case (int)MaterialType.Text: textmat = mat; go = ysm.yangshiText.gameObject; var textitem = go.AddComponent(); go.SetActive(true); Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.textPosition); Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.textContent); textitem.SetData(mat, materialObls.updateTime); text = textitem; break; default: ysm.yangshiList[i].Close(); break; } if (go != null) { if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString())) { GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary>()); } if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(materialObls.id.ToString())) { GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(materialObls.id.ToString(), new Dictionary()); } if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()].ContainsKey(mat.id.ToString())) { GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()].Add(mat.id.ToString(), go); } else { GameManager.Instance.allobjs[spoitjd.id.ToString()][materialObls.id.ToString()][mat.id.ToString()] = go; } Debug.Log("HJJSSSSSSSSSSSSSSSS获取 ===》" + spoitjd.id.ToString() + "_" + materialObls.id.ToString() + "_" + mat.id.ToString()); go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name; go.AddComponent().Type = (MaterialType)(mat.type); if (materialObls.select) { go.transform.localPosition = mat.ObjectTransform.nowPos; go.transform.localEulerAngles = mat.ObjectTransform.nowRot; go.transform.localScale = mat.ObjectTransform.nowScale; } else { if (mat.type != (int)MaterialType.Text) { go.transform.localPosition = Vector3.zero; } else { //Set text position if (mat.textPosition == "top") { go.transform.localPosition = new Vector3(0, ysm.yangshiText.topf, 0); } else if (mat.textPosition == "bottom") { go.transform.localPosition = new Vector3(0, ysm.yangshiText.buttomf, 0); } } mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale); } ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go); objectValues.Add(objectValue); } } #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回 if (!materialObls.select) { if(type !="1") // 判断是不是巨幕 { if (objectValues.Count > 0) { objectValues[0].Object.transform.parent.localScale=new Vector3(3,3,3); } } } if (textmat != null) { text.gameObject.SetActive(true); } #endregion return objectValues; } /// /// 根据素材数量对物体进行布局组合 /// 忽略文字类型 /// /// 素材 /// 素材父物体,景点 /// public static IEnumerator CalLayout(ModelList materialObls, GameObject par,Action callback) { Debug.Log("CalLayoutCalLayoutCalLayoutCalLayoutCalLayoutCalLayoutCalLayout"); var yangshi = ResMgr.Instance.LoadAsync("yangshi" + materialObls.typesetting); yield return yangshi; GameObject ys = Instantiate((yangshi.asset as GameObject), par.transform); YangShiManager ysm = ys.GetComponent(); ys.transform.localEulerAngles = Vector3.zero; ys.transform.localScale = new Vector3(1, 1, 1); BaseTemPlate text = new BaseTemPlate(); List noText = new List(); ModelItem textmat = null; List objectValues = new List(); Debug.Log("HJj................" + materialObls.materialList.Count); ysm.yangshiText.gameObject.SetActive(false); for (int i = 0; i < materialObls.materialList.Count; i++) { var mat = materialObls.materialList[i]; GameObject go = null; switch (mat.type) { case (int)MaterialType.None: ysm.yangshiList[i].Close(); break; case (int)MaterialType.Image: go = ysm.yangshiList[i].showimg(); var imageitem = go.AddComponent(); go.SetActive(true); // imageitem.SetData(mat, materialObls.updateTime); noText.Add(imageitem); break; case (int)MaterialType.Video: go = ysm.yangshiList[i].showvideo(); var videoitem = go.AddComponent(); videoitem.autoplay = materialObls.autoplay; go.SetActive(true); // videoitem.SetData(mat, materialObls.updateTime); noText.Add(videoitem); break; case (int)MaterialType.Text: go = ysm.yangshiText.gameObject; var textitem = go.AddComponent(); go.SetActive(true); // textitem.SetData(mat, materialObls.updateTime); Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.textPosition); Debug.LogError("TextTextTextTextText.select DRFanLayout.CreateImage_Video_Text " + mat.textContent); text = textitem; break; default: ysm.yangshiList[i].Close(); break; } if (go != null) { go.name = string.IsNullOrWhiteSpace(mat.name) ? par.name + "-" + i.ToString() : mat.name; go.AddComponent().Type = (MaterialType)(mat.type); Debug.Log("materialObls.select===>" + materialObls.select); Debug.Log("materialObls.select===>" + mat.objectTransform.nowPos); if (materialObls.select) { go.transform.localPosition = mat.objectTransform.nowPos; go.transform.localEulerAngles = mat.objectTransform.nowRot; go.transform.localScale = mat.objectTransform.nowScale; } else { if (mat.type != (int)MaterialType.Text) { go.transform.localPosition = Vector3.zero; } else { //Set text position if (mat.textPosition == "top") { go.transform.localPosition = new Vector3(0, ysm.yangshiText.topf, 0); } else if (mat.textPosition == "bottom") { go.transform.localPosition = new Vector3(0, ysm.yangshiText.buttomf, 0); } } mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale); } mat.prefabModel = go; // mat.initFrist(); } } #region 需要判断是否是第一次编辑坐标,若是则执行下方代码,不是则直接返回 if (textmat != null) { text.gameObject.SetActive(true); } callback.Invoke(); #endregion } /// /// 排列顺序 /// /// /// public static void Column(List data, GameObject game) { var scgrid = game.AddComponent(); scgrid.IsIgnoreInactiveObj = true; scgrid.LayoutType = LayoutTypes.Vertical; scgrid.Rows = 1; scgrid.SpaceX = 0.7f; scgrid.RefreshInfo(); Destroy(scgrid); } }