//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Saturday, January 06, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class NewGuideWin : Window { public SquareHollowImage holdImage; public RectTransform container; public RectTransform rtSelectFrame; public FakeButton2 btnFake; public RectTransform rtContent; public Text txtContent; public RectTransform rtArrow; private Transform m_PreParent; private Transform m_HighLight; private UnityEngine.Events.UnityAction onClose; private byte m_Direction; private bool m_PressClose; #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { btnFake.RemoveAllListeners(); btnFake.AddListener(OnClick); NewGuideModel _model = ModelCenter.Instance.GetModel(); m_HighLight = WindowCenter.Instance.uiRoot.transform.Find(_model.componentPath); holdImage.cell = _model.size; rtSelectFrame.sizeDelta = _model.size + new Vector2(15, 15); if (string.IsNullOrEmpty(_model.content)) { rtContent.gameObject.SetActive(false); } else { rtContent.gameObject.SetActive(true); } txtContent.text = _model.content; m_PressClose = _model.pressedClose; rtArrow.localScale = Vector3.one * _model.arrowScale; container.gameObject.SetActive(_model.showMask); if (_model.onClose != null) { onClose = _model.onClose; } m_Direction = _model.direction; } protected override void OnAfterOpen() { } protected override void OnPreClose() { if (onClose != null) { onClose(); onClose = null; } } protected override void OnAfterClose() { btnFake.RemoveAllListeners(); } #endregion protected override void LateUpdate() { base.LateUpdate(); if (m_PressClose) { if (Input.GetMouseButtonDown(0)) { var sp = Input.mousePosition; if (RectTransformUtility.RectangleContainsScreenPoint(rtSelectFrame.transform as RectTransform, sp, CameraManager.uiCamera)) { OnClick(); return; } } } if (m_HighLight == null) { return; } if (m_HighLight.position != rtSelectFrame.transform.position) { rtSelectFrame.transform.position = m_HighLight.position; holdImage.center = holdImage.transform.InverseTransformPoint(m_HighLight.position); Vector2 _arrowPosition = Vector3.zero; Vector2 _contentPosition = Vector3.zero; Vector3 _rotation = Vector3.zero; if (m_Direction == 0)// 上 { _arrowPosition = rtSelectFrame.anchoredPosition + new Vector2(0, rtSelectFrame.sizeDelta.y * .5f + 20f); _contentPosition = _arrowPosition + new Vector2(0, rtArrow.sizeDelta.y * .5f + rtContent.sizeDelta.y * .5f + 5); _rotation = new Vector3(0, 0, 90); } else if (m_Direction == 1)// 下 { _arrowPosition = rtSelectFrame.anchoredPosition + new Vector2(0, -rtSelectFrame.sizeDelta.y * .5f - 20f); _contentPosition = _arrowPosition + new Vector2(0, -rtArrow.sizeDelta.y * .5f - rtContent.sizeDelta.y * .5f - 5); _rotation = new Vector3(0, 0, 270); } else if (m_Direction == 2)// 左 { _arrowPosition = rtSelectFrame.anchoredPosition + new Vector2(-rtSelectFrame.sizeDelta.x * .5f - 20f, 0); _contentPosition = _arrowPosition + new Vector2(-rtArrow.sizeDelta.x * .5f - rtContent.sizeDelta.x * .5f - 5, 0); _rotation = new Vector3(0, 0, 180); } else if (m_Direction == 3)// 右 { _arrowPosition = rtSelectFrame.anchoredPosition + new Vector2(rtSelectFrame.sizeDelta.x * .5f + 20f, 0); _contentPosition = _arrowPosition + new Vector2(rtArrow.sizeDelta.x * .5f + rtContent.sizeDelta.x * .5f + 5, 0); _rotation = Vector3.zero; } rtArrow.anchoredPosition = _arrowPosition; rtArrow.eulerAngles = _rotation; rtContent.anchoredPosition = _contentPosition; } } private void OnClick() { NewGuideModel _model = ModelCenter.Instance.GetModel(); if (_model.clickClosed) { WindowCenter.Instance.Close(); } } } }