public void Init(U3D_Render.EntityView ev, int cam, BloodStyleType bt, BloodCanvasNode node) { ResetData(); m_Entity = ev; if (!U3D_Render.EntityView.isNullOrEmpty(ev)) { m_ID = m_Entity.ID; } m_BloodType = bt; m_CanvasNode = node; m_StyleInfo = UBloodManager.Instance.m_BloodStyleList.Find((x) => { return(x.bloodType == m_BloodType); }); if (null == m_StyleInfo || null == m_BloodImg) { return; } bInit = true; m_BloodInfoVisible = UBloodManager.Instance.NumInfoVisible; if (null != m_BloodNumTex) { m_BloodNumTex.text = ""; m_BloodNumTex.gameObject.SetActive(m_BloodInfoVisible); } if (m_BillBoard) { m_BillBoard.gameObject.SetActive(m_FinalVisible); } if (m_BloodType == BloodStyleType.Boss) { this.gameObject.SetActive(m_bVisible); } if (m_Sequence == null) { m_Sequence = DOTween.Sequence(); } SetCampType(cam); if (m_Entity != null) { CreatBillBoard(); ChangeCanvasNode(); } }
private UBlood GetBlood(BloodStyleType type, ref BloodCanvasNode canvNode) { UBlood ub = null; if (!bPreWarmBlood) { if (!AllocBloodPos(type, ref canvNode)) { return(null); } ub = InstanceUBlood(type, canvNode); return(ub); } if (!m_CacheBloodMap.ContainsKey(type)) { if (!AllocBloodPos(type, ref canvNode)) { return(null); } ub = InstanceUBlood(type, canvNode); return(ub); } else { if (!m_CacheBloodMap.ContainsKey(type)) { if (!AllocBloodPos(type, ref canvNode)) { return(null); } ub = InstanceUBlood(type, canvNode); return(ub); } Queue <UBlood> m_CacheList = m_CacheBloodMap[type]; if (m_CacheList.Count > 0) { ub = m_CacheList.Dequeue(); canvNode = ub.CanvasNode; ub.RefreshTexture(); } else { if (!AllocBloodPos(type, ref canvNode)) { return(null); } ub = InstanceUBlood(type, canvNode); } } return(ub); }
/// <summary> /// 设置血条位置 /// </summary> /// <param name="go"></param> /// <param name="bcn"></param> /// <returns></returns> private bool RectPosition(GameObject go, BloodCanvasNode bcn) { if (go == null || bcn.start == null) { return(false); } RectTransform rt = go.transform.GetComponent <RectTransform>(); if (rt == null || renderCanvas == null) { return(false); } rt.SetParent(renderCanvas, false); rt.localPosition = new Vector3(bcn.start.x, bcn.start.y, 0); return(true); }
//预热血条 public void PreWarmBlood() { if (bPreWarmBlood) { return; } bPreWarmBlood = true; for (int i = 0; i < (int)BloodStyleType.Boss; i++) { BloodStyleType eType = (BloodStyleType)i; if (!m_CacheBloodMap.ContainsKey(eType)) { m_CacheBloodMap.Add(eType, new Queue <UBlood>()); } Queue <UBlood> BloodList = m_CacheBloodMap[eType]; BloodList.Clear(); for (int n = 0; n < CacheCountArry[i]; n++) { BloodCanvasNode canvNode = new BloodCanvasNode(); if (!AllocBloodPos(eType, ref canvNode)) { continue; } UBlood ub = InstanceUBlood(eType, canvNode); if (null != ub) { ub.Init(null, 0, eType, canvNode); ub.ChangeParent(CacheBloodRoot.transform); ub.SetEnable(false); BloodList.Enqueue(ub); } } } if (EntityFactory.MainHero != null) { bossBloodTarget = EntityFactory.MainHero.transform; } }
/// <summary> /// 创建大血条 /// </summary> private void CreateBossBlood() { if (null == BossBlood) { BossBlood = InstanceUBossBlood(); if (null == BossBlood) { Trace.LogError("UGUI -- BossBlood创建失败!"); } else { BloodCanvasNode bcn = new BloodCanvasNode(); BossBlood.Init(null, 0, BloodStyleType.Boss, bcn); BossBlood.SetMaxValue(100); BossBlood.SetCurValue(100); UpdateBossBloodAndTowerSoldier(null, false); BossBlood.SetPositionDirectly_ScreenPoint(OrginalBossBloodPos); } } }
/// <summary> /// 实例化普通血条 /// </summary> /// <param name="entityType">实体类型</param> /// <param name="isHero">是否主角</param> /// <param name="bcn">血条节点数据</param> /// <returns></returns> private UBlood InstanceUBlood(BloodStyleType type, BloodCanvasNode bcn) { //大血条返回null,这个方法只创常规血条 if (type == BloodStyleType.Boss) { return(null); } BloodStyleInfo bloodInfo = m_BloodStyleList.Find((x) => { return(x.bloodType == type); }); if (null != bloodInfo && null != bloodInfo.bloodRes) { GameObject go = bloodInfo.bloodRes.InstanceMainRes(); if (RectPosition(go, bcn)) { UBlood blood = go.GetComponent <UBlood>(); blood.resNode = bloodInfo.bloodRes; return(blood); } } return(null); }
private Vector2[] m_curIndexArry = new Vector2[3]; //暂时只显示三种类型,Player、Buliding、Monster,大血条不用建格子 /// <summary> /// 分配血条格子,同一类型放一起,左下为起点, 如:最下面3行放人物的,再依次往上4行放建筑的,最上面放怪物 /// </summary> /// <param name="type"></param> /// <param name="bcn"></param> /// <returns></returns> private bool AllocBloodPos(BloodStyleType type, ref BloodCanvasNode bcn) { int nTypeIndex = (int)type; BloodStyleInfo bloodInfo = m_BloodStyleList.Find((x) => { return(x.bloodType == type); }); if (null != bloodInfo) { Vector2 bloodSize = bloodInfo.bloodSize; bcn.isValid = false; //先查缓存格子列有没有 if (m_unUseCanvasNodeMap.ContainsKey(type) && m_unUseCanvasNodeMap[type].Count > 0) { BloodCanvasNode bc = m_unUseCanvasNodeMap[type].Dequeue(); bcn.RowIndex = bc.RowIndex; bcn.ColIndex = bc.ColIndex; bcn.start = bc.start; bcn.end = bc.end; bcn.vSize = bc.vSize; bcn.scale = bc.scale; bcn.isValid = true; } else { if (m_curIndexArry[nTypeIndex].x > MaxCellRowCountList[nTypeIndex]) { bcn.isValid = false; return(false); } bcn = new BloodCanvasNode(); bcn.start.x = bloodInfo.bloodSize.x * m_curIndexArry[nTypeIndex].y; float offset = 0; if (nTypeIndex > 0) { for (int i = 0; i < nTypeIndex; i++) { BloodStyleInfo info = m_BloodStyleList.Find((x) => { return(x.bloodType == (BloodStyleType)i); }); if (info != null) { offset += MaxCellRowCountList[i] * info.bloodSize.y; } } } bcn.start.y = offset + bloodInfo.bloodSize.y * m_curIndexArry[nTypeIndex].x; bcn.end.x = bcn.start.x + bloodSize.x; bcn.end.y = bcn.start.y + bloodSize.y; bcn.vSize = bloodSize; bcn.scale = bloodInfo.bloodScale; bcn.RowIndex = (int)m_curIndexArry[nTypeIndex].x; bcn.ColIndex = (int)m_curIndexArry[nTypeIndex].y; //分配下一次的格子索引 m_curIndexArry[nTypeIndex].y++; if (m_curIndexArry[nTypeIndex].y == (int)(bloodRenderTextureWidth / bloodInfo.bloodSize.x)) { m_curIndexArry[nTypeIndex].x++; m_curIndexArry[nTypeIndex].y = 0; } bcn.isValid = true; } return(true); } bcn.isValid = false; return(false); }
/// <summary> /// 血条创建 /// </summary> /// <param name="objev">实体View</param> /// <param name="entityID">实体ID</param> /// <param name="host">实体Object</param> /// <param name="camType">阵营</param> /// <returns></returns> public UBlood CreatBlood(EntityView objev, int campType) { if (!bInit) { Trace.LogError("UBloodManager必须初始化!"); return(null); } if (null == objev || !objev.IsValid || null == objev.Property) { Trace.LogWarning("Blood--EntityView无效!"); return(null); } CreateBossBlood(); int entityID = objev.ID; if (m_BloodMap.ContainsKey(entityID)) { Trace.LogWarning(entityID + "已经有血条,返回已有的实例"); UBlood ub = m_BloodMap[entityID]; return(ub); } //按照策划要求,目前不创建己方小兵血条,其他己方物体不变 //if (objev.Flag == (int)MONSTER_SUB_TYPE.MONSTER_SUB_TYPE_SOLDIER && campType == (int)GFxCampTpye.CT_Friend && objev.Property.GetNumProp(ENTITY_PROPERTY.PROPERTY_MASTER_UID) <= 0) //{ // return null; //} int hideFlag = (int)ENTITY_MASKFLAG.MASKFLAG_PROPCHANGE_HIDE_SAME_CAMP; if (campType == (int)GFxCampTpye.CT_Friend && (objev.Property.GetNumProp(ENTITY_PROPERTY.PROPERTY_MASK) & hideFlag) == hideFlag) { return(null); } BloodStyleType bloodType = BloodStyleType.Player; if (objev.Type == ENTITY_TYPE.TYPE_PLAYER_ROLE) { bloodType = BloodStyleType.Player; } else if (objev.Type == ENTITY_TYPE.TYPE_MONSTER && objev.createinfo.nBloodStyle < (int)BloodStyleType.Boss) { bloodType = (BloodStyleType)objev.createinfo.nBloodStyle; } BloodCanvasNode bcn = new BloodCanvasNode(); UBlood blood = GetBlood(bloodType, ref bcn); if (null == blood) { return(null); } blood.Init(objev, campType, bloodType, bcn); m_BloodMap.Add(entityID, blood); ChangeMask(objev, true); SetProperty(objev, blood); return(blood); }