406 lines
14 KiB
C#
406 lines
14 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Games.LogicObj;
|
|
using System;
|
|
using GCGame;
|
|
using Games.GlobeDefine;
|
|
using Games.ImpactModle;
|
|
using System.Collections;
|
|
using GCGame.Table;
|
|
|
|
public class BossFramUI : MonoBehaviour
|
|
{
|
|
private static BossFramUI m_Instance = null;
|
|
public static BossFramUI Instance()
|
|
{
|
|
return m_Instance;
|
|
}
|
|
public GameObject m_BossBlood;
|
|
public GameObject m_BossShidle;
|
|
|
|
public Text BossName;
|
|
public Text BossBloodRate;
|
|
public Text BossBloodIndex;
|
|
public Text BossAttackObjName;
|
|
|
|
public RectTransform LineRect;
|
|
public GameObject BloodSliderObj;
|
|
public Slider[] BossBloodSlider;
|
|
public Slider[] BossBloodBuffSlider;
|
|
|
|
public Image ShidleImage;
|
|
public Text ShidleName;
|
|
public Text ShidleBloodRate;
|
|
|
|
private int TotleShowBloodTimes = 0;
|
|
|
|
private int m_TargetServerID = GlobeVar.INVALID_ID;
|
|
public int TargetServerID
|
|
{
|
|
get { return m_TargetServerID; }
|
|
set { m_TargetServerID = value; }
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
m_Instance = this;
|
|
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.ChangeTarget, ChangeTarget);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.TargetHP, ChangeHP);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.CancleTarget, CancelTarget);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.UpdateTargetBuff, UpdateBuffIcon);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.CreateTargetHealth, CreateShield);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.UpdateTargetHealth, UpdateShield);
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.RemoveTargetHealth, RemoveShield);
|
|
|
|
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.FunctionChangeBaseBtnActive, FunctionChangeBase);
|
|
|
|
ShieldOnAwake();
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
HideTargetFrame();
|
|
}
|
|
|
|
private void HideFuctionUI()
|
|
{
|
|
GCGame.Utils.HideMainTopRightUI(false,false);
|
|
}
|
|
|
|
void FunctionChangeBase(object obj)
|
|
{
|
|
bool FunctionChangeBaseShow = (bool)obj;
|
|
if (FunctionChangeBaseShow == false && m_TargetServerID != GlobeVar.INVALID_ID)
|
|
{
|
|
if(gameObject.activeSelf == false)
|
|
ShowTargetFrame();
|
|
}
|
|
else
|
|
{
|
|
HideTargetFrame();
|
|
}
|
|
}
|
|
|
|
int _Index = -1;
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
if (_Index < 0 || _Index > BossBloodSlider.Length)
|
|
return;
|
|
if (_Index == -1)
|
|
return;
|
|
if (BossBloodBuffSlider[_Index].value == BossBloodSlider[_Index].value)
|
|
return;
|
|
if (BossBloodBuffSlider[_Index].value - 0.005f < BossBloodSlider[_Index].value)
|
|
{
|
|
BossBloodBuffSlider[_Index].value = BossBloodSlider[_Index].value;
|
|
return;
|
|
}
|
|
BossBloodBuffSlider[_Index].value -= 0.005f;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.ChangeTarget, ChangeTarget);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.TargetHP, ChangeHP);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.CancleTarget, CancelTarget);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.UpdateTargetBuff, UpdateBuffIcon);
|
|
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.CreateTargetHealth, CreateShield);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.UpdateTargetHealth, UpdateShield);
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.RemoveTargetHealth, RemoveShield);
|
|
|
|
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.FunctionChangeBaseBtnActive, FunctionChangeBase);
|
|
|
|
m_Instance = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换目标
|
|
/// </summary>
|
|
/// <param name="targetObj">目标obj</param>
|
|
public void ChangeTarget(object obj)
|
|
{
|
|
if (Singleton<ObjManager>.Instance.MainPlayer == null)
|
|
return;
|
|
if (Singleton<ObjManager>.Instance.MainPlayer.targetId == null)
|
|
return;
|
|
Obj_Character character = Singleton<ObjManager>.Instance.FindObjCharacterInScene(Singleton<ObjManager>.Instance.MainPlayer.targetId.Value);
|
|
if (character == null)
|
|
return;
|
|
if (m_TargetServerID != GlobeVar.INVALID_ID && character.ServerID == Singleton<ObjManager>.Instance.MainPlayer.ServerID)
|
|
return;
|
|
var roleTab = TableManager.GetRoleBaseAttrByID(character.BaseAttr.RoleBaseID, 0);
|
|
if (roleTab == null || roleTab.IsShowHeadIcon != 1 || roleTab.BossBloodShowTimes <= 0)
|
|
{
|
|
HideTargetFrame();
|
|
m_TargetServerID = GlobeVar.INVALID_ID;
|
|
return;
|
|
}
|
|
|
|
if(m_TargetServerID == GlobeVar.INVALID_ID || m_TargetServerID!= character.ServerID)
|
|
{
|
|
m_TargetServerID = character.ServerID;
|
|
gameObject.SetActive(true);
|
|
HideFuctionUI();
|
|
}
|
|
else if(FunctionButtonLogic.Instance()!=null && FunctionButtonLogic.Instance().IsShowBtn == false)
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
if (gameObject.activeSelf == false)
|
|
{
|
|
m_TargetServerID = GlobeVar.INVALID_ID;
|
|
return;
|
|
}
|
|
UpdateBuffIcon(character.ServerID);
|
|
TotleShowBloodTimes = roleTab.BossBloodShowTimes;
|
|
m_TargetServerID = character.ServerID;
|
|
// 特殊处理护盾情况
|
|
var npc = character as Obj_NPC;
|
|
if (npc != null && npc.shieldData != null && npc.shieldData.health > 0)
|
|
{
|
|
CreateShield(npc);
|
|
UpdateShield(npc);
|
|
}
|
|
else
|
|
{
|
|
m_BossBlood.SetActive(true);
|
|
m_BossShidle.SetActive(false);
|
|
BossName.text = string.Format("Lv.{0} {1}", character.BaseAttr.Level, roleTab.Name);
|
|
ChangeHP(obj);
|
|
}
|
|
|
|
}
|
|
|
|
public void ChangeHP(object obj)
|
|
{
|
|
Obj_Character targetObj = obj as Obj_Character;
|
|
if (targetObj == null || targetObj.IsDie() || targetObj.ServerID != m_TargetServerID || gameObject.activeSelf == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (TotleShowBloodTimes <= 0)
|
|
{
|
|
HideTargetFrame();
|
|
m_TargetServerID = GlobeVar.INVALID_ID;
|
|
return;
|
|
}
|
|
BossBloodRate.text = string.Format("{0}/{1}", targetObj.BaseAttr.HP, targetObj.BaseAttr.MaxHP);
|
|
float preBlood = targetObj.BaseAttr.MaxHP * 1.0f / TotleShowBloodTimes;
|
|
float showIndex = (targetObj.BaseAttr.MaxHP - targetObj.BaseAttr.HP) / preBlood;
|
|
int xIndex = Mathf.CeilToInt(TotleShowBloodTimes - showIndex);
|
|
float rate = TotleShowBloodTimes - showIndex + 1 - xIndex;
|
|
if (rate <= 0)
|
|
rate = 1;
|
|
if (rate < 1 && rate>0)
|
|
{
|
|
LineRect.gameObject.SetActive(true);
|
|
LineRect.sizeDelta = new Vector2(415 * rate, 10);
|
|
}
|
|
else
|
|
{
|
|
LineRect.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (xIndex >= 1)
|
|
BossBloodIndex.text = "X" + xIndex.ToString();
|
|
else
|
|
{
|
|
BossBloodIndex.text = "X" + TotleShowBloodTimes.ToString();
|
|
}
|
|
|
|
int index = xIndex % BossBloodSlider.Length;
|
|
if(_Index == index)
|
|
{
|
|
|
|
BossBloodSlider[_Index].value = rate;
|
|
return;
|
|
}
|
|
_Index = index;
|
|
for (int i = 0; i < BossBloodSlider.Length; i++)
|
|
{
|
|
BossBloodSlider[i].gameObject.SetActive(i == _Index);
|
|
}
|
|
|
|
BossBloodSlider[_Index].value = rate;
|
|
BossBloodSlider[_Index].transform.SetAsLastSibling();
|
|
BossBloodBuffSlider[_Index].value = rate;
|
|
index = index - 1;
|
|
if (index < 0)
|
|
index = BossBloodSlider.Length - 1;
|
|
|
|
if(xIndex > 1)
|
|
{
|
|
BossBloodSlider[index].gameObject.SetActive(true);
|
|
BossBloodSlider[index].value = 1;
|
|
BossBloodSlider[index].transform.SetAsFirstSibling();
|
|
}
|
|
}
|
|
|
|
public void CancelTarget(object obj)
|
|
{
|
|
var targetId = (int) obj;
|
|
if (m_TargetServerID != GlobeVar.INVALID_ID && targetId != -1 && targetId != m_TargetServerID)
|
|
return;
|
|
if (gameObject.activeSelf)
|
|
{
|
|
HideTargetFrame();
|
|
if(GameManager.gameManager.ActiveScene.IsCopyScene() == false)
|
|
{
|
|
var character = ObjManager.Instance.FindObjCharacterInScene(targetId);
|
|
if (character != null && character.IsDie())
|
|
{
|
|
GCGame.Utils.ShowMainTopRightUI();
|
|
}
|
|
}
|
|
}
|
|
|
|
m_TargetServerID = GlobeVar.INVALID_ID;
|
|
_Index = -1;
|
|
}
|
|
|
|
public void ShowAttackObjName(int TargetID)
|
|
{
|
|
if (TargetID != m_TargetServerID)
|
|
{
|
|
Obj_Character obj = Singleton<ObjManager>.Instance.FindObjCharacterInScene(TargetID);
|
|
if (obj != null)
|
|
{
|
|
BossAttackObjName.text = obj.BaseAttr.RoleName;
|
|
return;
|
|
}
|
|
}
|
|
BossAttackObjName.text = "";
|
|
}
|
|
|
|
void ShowTargetFrame()
|
|
{
|
|
if(Singleton<ObjManager>.Instance.MainPlayer!=null && Singleton<ObjManager>.Instance.MainPlayer.targetId!=null)
|
|
{
|
|
Obj_Character obj = Singleton<ObjManager>.Instance.FindObjCharacterInScene(Singleton<ObjManager>.Instance.MainPlayer.targetId.Value);
|
|
if(obj!=null)
|
|
{
|
|
ChangeTarget(null);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void HideTargetFrame()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
//目标BUFFIcon相关
|
|
public Image[] m_BuffShowIcon = new Image[(int)BUFFICON.MAX_BUFFICONUM];
|
|
|
|
public void OnClick_BuffIcon()
|
|
{
|
|
UIManager.ShowUI(UIInfo.ImpactInfoWnd, OnOpenSuccess);
|
|
}
|
|
|
|
public void OnOpenSuccess(bool success, object param)
|
|
{
|
|
Hashtable hash = new Hashtable();
|
|
hash.Add("targetId", m_TargetServerID);
|
|
Games.Events.EventDispatcher.Instance.SendMessage(Games.Events.EventId.OpenImpactInfoWndSuccess, hash);
|
|
}
|
|
|
|
//更新头像的BUFF位
|
|
public void UpdateBuffIcon(object obj)
|
|
{
|
|
if (gameObject.activeSelf == false)
|
|
return;
|
|
int TargetId = (int)obj;
|
|
|
|
if (TargetId != m_TargetServerID)
|
|
return;
|
|
Obj_Character targetObj = Singleton<ObjManager>.Instance.FindObjCharacterInScene(TargetId);
|
|
if (targetObj == null || targetObj.ClientImpactInfos == null)
|
|
return;
|
|
|
|
int nBuffShowIndex = 0;
|
|
for (int i = 0; i < targetObj.ClientImpactInfos.Count; ++i)
|
|
{
|
|
if (nBuffShowIndex >= m_BuffShowIcon.Length)
|
|
break;
|
|
if (nBuffShowIndex<(int)BUFFICON.MAX_BUFFICONUM)
|
|
m_BuffShowIcon[nBuffShowIndex].gameObject.SetActive(false);
|
|
if (targetObj.ClientImpactInfos[i].IsVaild())
|
|
{
|
|
Tab_Impact _tabImpact = TableManager.GetImpactByID(targetObj.ClientImpactInfos[i].ImpactId, 0);
|
|
if (_tabImpact != null)
|
|
{
|
|
if (_tabImpact.BuffIcon != "-1" && _tabImpact.IsNeedNoticeClient == 1)
|
|
{
|
|
if (nBuffShowIndex >= 0 && nBuffShowIndex < (int)BUFFICON.MAX_BUFFICONUM)
|
|
{
|
|
m_BuffShowIcon[nBuffShowIndex].gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(m_BuffShowIcon[nBuffShowIndex], _tabImpact.BuffIcon);
|
|
nBuffShowIndex++;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (int i = nBuffShowIndex; i < (int)BUFFICON.MAX_BUFFICONUM; i++)
|
|
{
|
|
m_BuffShowIcon[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
#region 护盾处理流程
|
|
|
|
public Slider _healthBar;
|
|
|
|
private void ShieldOnAwake()
|
|
{
|
|
m_BossBlood.SetActive(true);
|
|
m_BossShidle.SetActive(false);
|
|
if (ShidleImage!=null)
|
|
ShidleImage.color = Utils.GetColorByString(StrDictionary.GetClientDictionaryString(GlobeVar.shieldColorKey));
|
|
}
|
|
|
|
public void CreateShield(object obj)
|
|
{
|
|
Obj_NPC targetObj = obj as Obj_NPC;
|
|
if (targetObj == null || targetObj.shieldData == null)
|
|
return;
|
|
ShidleName.text = StrDictionary.GetClientDictionaryString(GlobeVar.shieldNameKey);
|
|
m_BossBlood.SetActive(false);
|
|
m_BossShidle.SetActive(true);
|
|
if(gameObject.activeSelf ==false)
|
|
{
|
|
ShowTargetFrame();
|
|
}
|
|
}
|
|
|
|
public void UpdateShield(object obj)
|
|
{
|
|
Obj_NPC targetObj = obj as Obj_NPC;
|
|
if (targetObj == null || targetObj.ServerID != m_TargetServerID || targetObj.shieldData == null)
|
|
return;
|
|
ShidleBloodRate.text = string.Format("{0}/{1}", Utils.ConvertLargeNumToString(targetObj.shieldData.health), Utils.ConvertLargeNumToString(targetObj.shieldData.maxHealth));
|
|
_healthBar.value = (float)targetObj.shieldData.health / targetObj.shieldData.maxHealth;
|
|
}
|
|
|
|
public void RemoveShield(object obj)
|
|
{
|
|
Obj_NPC targetObj = obj as Obj_NPC;
|
|
if (targetObj == null || targetObj.ServerID != m_TargetServerID ||m_TargetServerID == GlobeVar.INVALID_ID)
|
|
return;
|
|
m_BossBlood.SetActive(true);
|
|
m_BossShidle.SetActive(false);
|
|
BossName.text = string.Format("Lv.{0} {1}", targetObj.BaseAttr.Level, targetObj.BaseAttr.RoleName);
|
|
ChangeHP(obj);
|
|
}
|
|
#endregion
|
|
|
|
} |