/**************************************************************************** * 2022.1 SK-20211220VCWK ****************************************************************************/ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using QFramework; namespace QFramework.MREditor { public partial class UIEditor : UIElement { private void Awake() { } protected override void OnBeforeDestroy() { } public void Close() { gameObject.SetActive(false); } private Transform MaterialObj; private List listAlter; private List listSpoits; public void Initialized(List listSpoits) { MaterialObj = null; this.listSpoits = listSpoits; listAlter = new List(); #region BtnInitialized UCBtn.onClick.AddListener(() => { if (UCElenemt.gameObject.activeSelf) return; UCElenemt.gameObject.SetActive(true); TicElenemt.gameObject.SetActive(false); }); TicBtn.onClick.AddListener(() => { if (TicElenemt.gameObject.activeSelf) return; UCElenemt.gameObject.SetActive(false); TicElenemt.gameObject.SetActive(true); }); RemoveBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SendMsg(new OnRemoveDataSetting("SelectObj")); // 移除当前素材 }); // RemoveBtn.gameObject.SetActive(false); AddSize.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localScale += new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f); }); SubSize.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localScale -= new Vector3(MaterialObj.localScale.x / 10.0f, MaterialObj.localScale.y / 10.0f, MaterialObj.localScale.z / 10.0f); }); AddRot.GetComponent().onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localEulerAngles += new Vector3(0, 10, 0); }); SubRot.GetComponent().onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localEulerAngles -= new Vector3(0, 10, 0); }); // SubRot.onClick.AddListener(() => // { // if (MaterialObj == null) // return; // SaveAlter(); // MaterialObj.localEulerAngles -= new Vector3(0, 10, 0); //}); AddX.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubX.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0.1f, 0, 0); }); AddY.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0.1f, 0); }); SubY.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0.1f, 0); }); ADDXBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubXBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0.1f, 0, 0); }); ADDYBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0.1f, 0); }); SubYBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0.1f, 0); }); AddZBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition += new Vector3(0, 0, 0.1f); }); SubZBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SaveAlter(); MaterialObj.localPosition -= new Vector3(0, 0, 0.1f); }); InitiativeBtn.onClick.AddListener(() => { if (MaterialObj == null) return; InitMaterialObj(); }); RevocationBtn.onClick.AddListener(() => { if (MaterialObj == null) return; MaterialObj.localPosition = listAlter[listAlter.Count - 1].pos; MaterialObj.localEulerAngles = listAlter[listAlter.Count - 1].rot; MaterialObj.localScale = listAlter[listAlter.Count - 1].scale; listAlter.RemoveAt(listAlter.Count - 1); }); SaveBtn.onClick.AddListener(() => { if (MaterialObj == null) return; SendMsg(new OnSaveDataSetting(MaterialObj.name, MaterialObj.localPosition, MaterialObj.localEulerAngles, MaterialObj.localScale)); }); #endregion } /// /// 选择素材 /// /// public void SelectMaterial(Transform MaterialObj) { this.MaterialObj = MaterialObj; listAlter.Clear(); listAlter = new List(); } private void InitMaterialObj() { if (MaterialObj == null) return; string name = MaterialObj.name; listAlter.Clear(); listAlter = new List(); for (int i = 0; i < listSpoits.Count; i++) { if(listSpoits[i].name == name) { } } //查找景点和景点内的组合素材名 List listCMV = new List(); for (int i = 0; i < listSpoits.Count; i++) { if(listSpoits[i].name ==name) { SetObjTransform(MaterialObj, listSpoits[i].spoitTf); return; } for (int j = 0; j < listSpoits[i].material.Count; j++) { switch ((MaterialType)listSpoits[i].material[j].type) { case MaterialType.NULL: break; case MaterialType.Image: break; case MaterialType.Video: break; case MaterialType.Model: break; case MaterialType.Text: break; case MaterialType.ImageorViedoAndText: if (listSpoits[i].material[j].name == name) { SetObjTransform(MaterialObj, listSpoits[i].material[j].objectTransform); return; } break; case MaterialType.ModelAndText: if (listSpoits[i].material[j].name == name) { SetObjTransform(MaterialObj, listSpoits[i].material[j].objectTransform); return; } break; default: break; } listCMV.Add(listSpoits[i].material[j]); } } //查找组合素材内单个素材 for (int i = 0; i < listCMV.Count; i++) { for (int j = 0; j < listCMV[i].materialList.Count; j++) { if (listCMV[i].materialList[j].name == name) { SetObjTransform(MaterialObj, listCMV[i].materialList[j].ObjectTransform); return; } } } } private void SetObjTransform(Transform obj , ObjectTransform objTransform ) { obj.localPosition = objTransform.startPos; obj.localEulerAngles = objTransform.startRot; obj.localScale = objTransform.startScale; } private void SaveAlter() { ObjectTData data = new ObjectTData(); data.pos = MaterialObj.localPosition; data.rot = MaterialObj.localEulerAngles; data.scale = MaterialObj.localScale; listAlter.Add(data); } } }