public static void NewDamageIndicator(DamageIndicatorInfo info) { if (DamageIndicatorEvent != null) { DamageIndicatorEvent(info); } }
public override void Init() { m_GroupUI = GetComponent <CanvasGroup>(); m_GroupUI.alpha = 0; m_IndicatorDisplayDuration = 0; m_Info = new DamageIndicatorInfo(Vector3.zero); m_AttackerID = -1; }
/// <summary> /// Create (request the object pooling manager for object reuse) a new indicator UI. /// </summary> /// <param name="info">The information about this new indicator.</param> private void CreateIndicator(DamageIndicatorInfo info) { // Reqest object reuse DamageIndicator indicator = (DamageIndicator)(ObjectPoolManager.Instance.ReuseObject( m_PerfabInstanceID, info, this).m_Instance); // Add the active indicator into the list m_IndicatorList.Add(indicator); }
/// <summary> /// Update a exist indicator. /// </summary> /// <param name="info">The indicator info</param> /// <param name="index">The index of inicator in the list.</param> private void UpdateIndicator(DamageIndicatorInfo info, int index) { DamageIndicator indicator = m_IndicatorList[index]; if (indicator == null) { Debug.LogWarning("Can't update indicator because this does't exit in list"); return; } if (info.IndicatorSpriteColor == Color.black) { info.IndicatorSpriteColor = Color.red; } // Update the exist indicator. indicator.UpdateIndicator(info, this); }
/// <summary> /// When create a new indicator of update a indicator, use this method. /// </summary> /// <param name="info">All the information that the indicator should know about.</param> /// <param name="manager">The indicator's manager.</param> /// <param name="update">If the indicator just been created, no need to update.</param> public void UpdateIndicator(DamageIndicatorInfo info, DamageIndicatorManager manager) { // Apply settings. m_Info = info; m_Manager = manager; // Apply the attacker. m_AttackerID = info.AttackerID; m_IndicatorDisplayDuration = m_Info.IndicatorDisplayDuration; m_GroupUI.alpha = 1; // Stop fading out. StopAllCoroutines(); // Restart the indicator fade out process. StartCoroutine(Fadeout()); }
/// <summary> /// When a "new" indicator has been called /// </summary> public override void OnObjectReuse(params object[] options) { // Apply settings. m_Info = (DamageIndicatorInfo)options[0]; m_Manager = (DamageIndicatorManager)options[1]; // Reset the attacker ID. m_AttackerID = m_Info.AttackerID; m_IndicatorDisplayDuration = m_Info.IndicatorDisplayDuration; // Reset transparency. m_GroupUI.alpha = 1; // Start the indicator. StartCoroutine(Fadeout()); }
/// <summary> /// When a damage has been done, a new event called /// </summary> /// <param name="info">Info about the new indicator</param> private void OnNewIndicator(DamageIndicatorInfo info) { // Determine if need create a new indicator or just update one existing. // Check if there is a indicator in the list which has a same attacker. if (m_IndicatorList.Exists(x => x.GetInfo.AttackerID == info.AttackerID)) { // Get the indicator's index form list. int index = GetIndicatorIndexFormList(info.AttackerID); if (index != -1) { // If just update, delay the indicator's fadeout timer by the half of the display duration. info.IndicatorDisplayDuration = m_IndicatorDisplayDuration / 2; // Update the indicator. UpdateIndicator(info, index); } else { Debug.LogError("Couldn't find the indicator in the list, it should create one."); } } // If there is no such indicator that has a same attacker ID, then create one. else { // Set the indicator display duration. info.IndicatorDisplayDuration = m_IndicatorDisplayDuration; // In most of the cases the indicator sprite's color should not be BLACK // If its BLACK that means its not been set any colors yet if (info.IndicatorSpriteColor == Color.black) { // Set it as RED. info.IndicatorSpriteColor = Color.red; } CreateIndicator(info); ControlIndicators(); } }