using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class AnchorEditorPanel : MonoBehaviour, EventObserver { public event Action OnClickRemoveBtn; [SerializeField] private Button UCBtn; [SerializeField] private Button TicBtn; [SerializeField] private Button RemoveBtn; [SerializeField] private Image UCElenemt; [SerializeField] private Button AddSize; [SerializeField] private Button SubSize; [SerializeField] private Button SubY; [SerializeField] private Button AddY; [SerializeField] private Button SubX; [SerializeField] private Button AddX; [SerializeField] private SCButton SubRot; [SerializeField] private SCButton AddRot; [SerializeField] private Image TicElenemt; [SerializeField] private Button ADDXBtn; [SerializeField] private Button SubXBtn; [SerializeField] private Button ADDYBtn; [SerializeField] private Button SubYBtn; [SerializeField] private Button AddZBtn; [SerializeField] private Button SubZBtn; [SerializeField] private Button InitiativeBtn; [SerializeField] private Button RevocationBtn; [SerializeField] private Button SaveBtn; private Transform anchorObj; /// /// 当前物体移动旋转缩放的操作步骤 /// private List listAlter; private void Awake() { InitEvent(); anchorObj = null; listAlter = new List(); EventManager.Instance.Register(this, EventID.EVENT_3); } public void Init() { //RemoveBtn.onClick.AddListener(() => //{ // Debug.Log(" 移除已取消 "); //}); } private void InitEvent() { 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 (anchorObj == null) // return; // if (anchorObj.tag == "TriggerBox") // return; // if (OnClickRemoveBtn != null) // { // OnClickRemoveBtn(anchorObj.gameObject); // } //}); //RemoveBtn.gameObject.SetActive(false); AddSize.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localScale += new Vector3(anchorObj.localScale.x / 10.0f, anchorObj.localScale.y / 10.0f, anchorObj.localScale.z / 10.0f); }); SubSize.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localScale -= new Vector3(anchorObj.localScale.x / 10.0f, anchorObj.localScale.y / 10.0f, anchorObj.localScale.z / 10.0f); }); AddRot.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localEulerAngles += new Vector3(0, 10, 0); }); SubRot.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localEulerAngles -= new Vector3(0, 10, 0); }); AddX.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubX.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition += new Vector3(0.1f, 0, 0); }); AddY.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition += new Vector3(0, 0.1f, 0); }); SubY.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition -= new Vector3(0, 0.1f, 0); }); ADDXBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition -= new Vector3(0.1f, 0, 0); }); SubXBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition += new Vector3(0.1f, 0, 0); }); ADDYBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition += new Vector3(0, 0.1f, 0); }); SubYBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition -= new Vector3(0, 0.1f, 0); }); AddZBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition += new Vector3(0, 0, 0.1f); }); SubZBtn.onClick.AddListener(() => { if (anchorObj == null) return; SaveAlter(); anchorObj.localPosition -= new Vector3(0, 0, 0.1f); }); InitiativeBtn.onClick.AddListener(() => { if (anchorObj == null) return; InitanchorObj(); }); RevocationBtn.onClick.AddListener(() => { if (anchorObj == null) return; if (listAlter.Count >= 1) { anchorObj.localPosition = listAlter[listAlter.Count - 1].pos; anchorObj.localEulerAngles = listAlter[listAlter.Count - 1].rot; anchorObj.localScale = listAlter[listAlter.Count - 1].scale; listAlter.RemoveAt(listAlter.Count - 1); } }); SaveBtn.onClick.AddListener(() => { if (anchorObj == null) return; GameManager.Instance.SaveAnchorObjs( anchorObj.name); }); } /// /// 选择锚点 /// /// public void SelectAnchor(Transform anchorObj) { if (this.anchorObj != null) this.anchorObj.GetChild(0).gameObject.SetActive(false); this.anchorObj = anchorObj; this.anchorObj.GetChild(0).gameObject.SetActive(true); listAlter.Clear(); listAlter = new List(); } /// /// 初始化素材 /// 只初始化当前素材 /// private void InitanchorObj() { if (anchorObj == null) return; string name = anchorObj.name; listAlter.Clear(); listAlter = new List(); // GameManager.Instance.InitSpoitObjs(); } private void SaveAlter() { objectData data = new objectData(); data.pos = anchorObj.localPosition; data.rot = anchorObj.localEulerAngles; data.scale = anchorObj.localScale; listAlter.Add(data); } public void HandleEvent(EventData data) { switch (data.ID) { case EventID.EVENT_3: EventData1 data1 = (EventData1)data; if (data1.SelectObj != null) { SelectAnchor(data1.SelectObj.transform); } else { anchorObj = null; listAlter.Clear(); } break; case EventID.EVENT_2: break; default: break; } } private void OnDestroy() { //EventManager.Instance.Remove(this); } }