| //-------------------------------------------------------- | 
| //    [Author]:           玩个游戏 | 
| //    [  Date ]:           Monday, August 14, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
|   | 
|     [RequireComponent(typeof(RectTransform))] | 
|     public class PopupMessageContainer:MonoBehaviour { | 
|   | 
|         [SerializeField] | 
|         PopupMessage[] popupMessages; | 
|   | 
|         [SerializeField] | 
|         Vector2 m_CellSize; | 
|   | 
|   | 
|         [SerializeField] | 
|         float interval = 1f; | 
|   | 
|         float nextPopupTime = 0f; | 
|         Queue<string> contents = new Queue<string>(); | 
|         Queue<PopupMessage> displayPopupMessages = new Queue<PopupMessage>(); | 
|   | 
|         Vector2 bottomPosition; | 
|         Vector2 topPosition; | 
|   | 
|   | 
|         public void Popup(string _content) { | 
|   | 
|   | 
|         } | 
|   | 
|         private void LateUpdate() { | 
|             if(Time.time > nextPopupTime) { | 
|                 if(contents.Count > 0) { | 
|                     nextPopupTime += interval; | 
|                     var content = contents.Dequeue(); | 
|   | 
|                     PopupMessage behaviour = null; | 
|                     for(var i = 0;i < popupMessages.Length;i++) { | 
|                         if(!popupMessages[i].isActive) { | 
|                             behaviour = popupMessages[i]; | 
|                             break; | 
|                         } | 
|                     } | 
|   | 
|                     if(behaviour == null) { | 
|                         behaviour = displayPopupMessages.Dequeue(); | 
|                     } | 
|   | 
|                     behaviour.transform.localPosition = bottomPosition; | 
|                     displayPopupMessages.Enqueue(behaviour); | 
|                 } | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         private void OnValidate() { | 
|   | 
|             var rectTransform = this.transform as RectTransform; | 
|   | 
|             var width = rectTransform.rect.width; | 
|             var height = rectTransform.rect.height; | 
|   | 
|             bottomPosition = new Vector2(0,-height * 0.5f + m_CellSize.y * 0.5f); | 
|             topPosition = new Vector2(0,height * 0.5f - m_CellSize.y * 0.5f); | 
|   | 
|         } | 
|   | 
|   | 
|   | 
|     } |