//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 06, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; namespace vnxbqy.UI { public class WorldMapWin : Window { [SerializeField] Button m_LocalMap; [SerializeField] Button m_Close; [SerializeField] BoundedDrag m_BoudedDrag; [SerializeField] AreaBehaviourTable[] m_AreaBehaviours; [SerializeField] ScaleTween m_ScaleTween; [SerializeField] Transform m_ContainerPlayerHead; [SerializeField] AvatarCell m_AvatarCell; [SerializeField] ScreenMoveTo m_UnLockBehaviour; [SerializeField] Transform m_EffectMask; [SerializeField] Transform m_ContainerNewUnLock; [SerializeField] Image m_BackGround; MapModel model { get { return ModelCenter.Instance.GetModel(); } } protected override void BindController() { } protected override void AddListeners() { m_LocalMap.AddListener(OpenLocalMap); m_Close.AddListener(CloseClick); } protected override void OnPreOpen() { m_EffectMask.SetActive(false); m_UnLockBehaviour.SetActive(false); m_ContainerNewUnLock.SetActive(false); } protected override void OnAfterOpen() { WindowCenter.Instance.Close(); WindowCenter.Instance.Close(); } protected override void OnPreClose() { model.wannaLookLocalMap = 0; } protected override void OnAfterClose() { if (!WindowJumpMgr.Instance.IsJumpState) { WindowCenter.Instance.Open(); } } protected override void OnActived() { base.OnActived(); var backGroundSize = m_BackGround.rectTransform.rect; var viewAreaSize = m_BoudedDrag.rectTransform.rect; var xLimit = (backGroundSize.width - viewAreaSize.width) * 0.5f; var moveArea = m_BoudedDrag.moveArea; m_BoudedDrag.moveArea = new BoundedDrag.MoveArea() { Left = -xLimit, Right = xLimit, Bottom = moveArea.Bottom, Top = moveArea.Top }; Init(); } public override void CloseClick() { base.CloseClick(); } void Init() { var worldMapAreaKeys = model.GetWorldMapAreas(); var mapAreas = new List(); for (int i = 0; i < worldMapAreaKeys.Count; i++) { var key = worldMapAreaKeys[i]; WorldMapArea area; if (model.TryGetWorldMapArea(key, out area)) { mapAreas.Add(area); } } m_AvatarCell.InitUI(AvatarHelper.GetMyAvatarModel()); WorldMapAreaBehaviour playerAtBehaviour = null; var currentMapId = PlayerDatas.Instance.baseData.MapID; m_ContainerPlayerHead.SetActive(false); for (int i = 0; i < m_AreaBehaviours.Length; i++) { var behaviourTable = m_AreaBehaviours[i]; WorldMapArea area; if (FindData(int.Parse(behaviourTable.id), mapAreas, out area)) { behaviourTable.areaBehaviour.SetActive(true); behaviourTable.areaBehaviour.container.SetActive(true); behaviourTable.areaBehaviour.Init(area); if (behaviourTable.id == currentMapId.ToString()) { m_ContainerPlayerHead.SetActive(true); playerAtBehaviour = behaviourTable.areaBehaviour; m_ContainerPlayerHead.SetParentEx(behaviourTable.areaBehaviour.playerHead, Vector3.zero, Vector3.zero, Vector3.one); } } else { behaviourTable.areaBehaviour.SetActive(false); behaviourTable.areaBehaviour.container.SetActive(false); } } if (model.newUnlockedMap != 0) { StopCoroutine("Co_MapUnLockShow"); StartCoroutine("Co_MapUnLockShow", model.newUnlockedMap); model.newUnlockedMap = 0; } else { EffectMgr.Instance.PlayUIEffect(1143, 3500, this.transform, false); if (playerAtBehaviour != null) { var localPosition = -playerAtBehaviour.container.transform.localPosition.SetZ(0); localPosition = new Vector3(Mathf.Clamp(localPosition.x, m_BoudedDrag.moveArea.Left, m_BoudedDrag.moveArea.Right), Mathf.Clamp(localPosition.y, m_BoudedDrag.moveArea.Bottom, m_BoudedDrag.moveArea.Top)); m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = localPosition; } else { m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = Vector3.zero; } m_BoudedDrag.actionable = false; m_ScaleTween.SetStartState(); m_ScaleTween.Play(() => { m_BoudedDrag.currentScale = m_BoudedDrag.destScale = m_BoudedDrag.defaultScale; m_BoudedDrag.actionable = true; }); } } bool FindData(int _id, List _areas, out WorldMapArea _area) { for (int i = 0; i < _areas.Count; i++) { var area = _areas[i]; if (area.id == _id) { _area = area; return true; } } _area = default(WorldMapArea); return false; } IEnumerator Co_MapUnLockShow(int _mapId) { windowInfo.raycastTarget = false; var mapId = _mapId; WorldMapAreaBehaviour areaBehaviour = null; for (int i = 0; i < m_AreaBehaviours.Length; i++) { var behaviourTable = m_AreaBehaviours[i]; if (behaviourTable.id == mapId.ToString()) { areaBehaviour = behaviourTable.areaBehaviour; } } if (areaBehaviour == null) { yield break; } m_EffectMask.SetActive(true); EffectMgr.Instance.PlayUIEffect(1143, 3500, this.transform, false); areaBehaviour.SetMaterial("Lerp"); var localPosition = -areaBehaviour.transform.localPosition.SetZ(0); localPosition = new Vector3(Mathf.Clamp(localPosition.x, m_BoudedDrag.moveArea.Left, m_BoudedDrag.moveArea.Right), Mathf.Clamp(localPosition.y, m_BoudedDrag.moveArea.Bottom, m_BoudedDrag.moveArea.Top)); m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = localPosition; yield return WaitingForSecondConst.WaitMS2000; var config = MapResourcesConfig.Get(MapUtility.GetMapResourceId(mapId, 0)); if (config != null && !config.Effect.IsNullOrEmpty()) { var unLockEffectId = config.Effect[0]; var effect = EffectMgr.Instance.PlayUIEffect(unLockEffectId, 3500, this.transform, false); var timer = 0f; while (timer < 5f) { timer += Time.deltaTime; yield return null; } if (effect.gameObject != null) { EffectMgr.Instance.RecyleUIEffect(unLockEffectId, effect.gameObject); } } EffectMgr.Instance.PlayUIEffect(3053, 3500, areaBehaviour.transform, false); yield return WaitingForSecondConst.WaitMS1000; m_EffectMask.SetActive(false); areaBehaviour.BeginUnLockShow(); m_ContainerNewUnLock.SetActive(true); m_ContainerNewUnLock.SetParentEx(areaBehaviour.newUnLockArrowPoint != null ? areaBehaviour.newUnLockArrowPoint : areaBehaviour.transform, Vector3.zero, Vector3.zero, Vector3.one); windowInfo.raycastTarget = true; } public void TestMapUnLockShow(int _mapId) { StopCoroutine("Co_MapUnLockShow"); StartCoroutine("Co_MapUnLockShow", _mapId); } private void OpenLocalMap() { WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); } [System.Serializable] class AreaBehaviourTable { public string id; public WorldMapAreaBehaviour areaBehaviour; } } }