/// <summary> /// 根据指定的类型和id设置图标 /// </summary> public void InitShow() { switch (keyLatticeType) { case EnumKeyContactType.Skill: if (ThisSkillStructData == null) { break; } if (id > (int)EnumSkillType.MagicCombinedStart) //组合技能 { SetTargetImage(SkillCombineStaticTools.GetCombineSkillSprite(ThisSkillStructData, id)); } else //单一的技能 { SkillBaseStruct skillBaseStruct = ThisSkillStructData.SearchSkillDatas(temp => temp.skillType == (EnumSkillType)id).FirstOrDefault(); if (skillBaseStruct != null) { SetTargetImage(skillBaseStruct.skillSprite); } else { SetTargetImage(null); } } break; case EnumKeyContactType.Prap: if (ThisPlayerState == null) { break; } PlayGoods playGoods = ThisPlayerState.PlayerAllGoods.Where(temp => temp.ID == id).FirstOrDefault(); SetTargetImage(playGoods.GetGoodsSprite); break; default: SetTargetImage(null); break; } }
private void Show() { if (skillStructData == null || playerState == null || keyImage == null) { return; } KeyContactStruct keyContactStruct = default(KeyContactStruct); //这里存在优化空间 if (r1Press) { keyContactStruct = keyContactData.GetKeyContactStruct(InputType | (int)EnumInputType.RB, null, iPlayerState.KeyContactDataZone).FirstOrDefault(); } else if (r2Press) { keyContactStruct = keyContactData.GetKeyContactStruct(InputType | (int)EnumInputType.RT, null, iPlayerState.KeyContactDataZone).FirstOrDefault(); } else if (l1Press) { keyContactStruct = keyContactData.GetKeyContactStruct(InputType | (int)EnumInputType.LB, null, iPlayerState.KeyContactDataZone).FirstOrDefault(); } else if (l2Press) { keyContactStruct = keyContactData.GetKeyContactStruct(InputType | (int)EnumInputType.LT, null, iPlayerState.KeyContactDataZone).FirstOrDefault(); } else { keyContactStruct = keyContactData.GetKeyContactStruct(InputType, null, iPlayerState.KeyContactDataZone).FirstOrDefault(); } switch (keyContactStruct.keyContactType) { case EnumKeyContactType.None: keyImage.sprite = null; innerImage.fillAmount = 0; break; case EnumKeyContactType.Skill: int skillKey = keyContactStruct.id; if (skillKey > (int)EnumSkillType.MagicCombinedStart) { keyImage.sprite = SkillCombineStaticTools.GetCombineSkillSprite(skillStructData, skillKey); } else { keyImage.sprite = skillStructData.SearchSkillDatas(temp => (int)temp.skillType == skillKey).Select(temp => temp.skillSprite).FirstOrDefault(); } //这里还需要判断是不是没有冷却的技能,比如魔法释放 普通攻击等 if (skillKey != (int)EnumSkillType.MagicRelease && skillKey != (int)EnumSkillType.PhysicAttack) { innerImage.fillAmount = Mathf.Clamp(iSkillState.PublicCoolingTime / 1, 0, 1); } else { innerImage.fillAmount = 0; } break; case EnumKeyContactType.Prap: PlayGoods playGoods = playerState.PlayerAllGoods.Where(temp => (int)temp.GoodsInfo.EnumGoodsType == keyContactStruct.id).FirstOrDefault(); if (playGoods != null) { keyImage.sprite = playGoods.GetGoodsSprite; } else { keyImage.sprite = null; } innerImage.fillAmount = 0; break; case EnumKeyContactType.Action: keyImage.sprite = keyContactStruct.Sprite; innerImage.fillAmount = 0; break; } keyImage.enabled = keyImage.sprite != null; r1Press = false; r2Press = false; l1Press = false; l2Press = false; }
/// <summary> /// 更新显示 /// </summary> private void ChangeSpriteLattice() { SkillBaseStruct[] skillBaseStructs = iSkillState.CombineSkills; Action <Transform, Sprite> SetImageSprite = (trans, sprite) =>//设置技能的图片显示 { if (trans) { Image image = trans.GetComponent <Image>(); if (image) { image.sprite = sprite; image.enabled = sprite != null; } } }; Action <Transform, float> SetImageInnerState = (trans, coolingTime) =>//设置技能的冷却显示 { if (trans) { Image image = trans.GetComponent <Image>(); if (image) { image.fillAmount = Mathf.Clamp(coolingTime, 0, 1); } } }; if (skillBaseStructs != null) { int skillID = SkillCombineStaticTools.GetCombineSkillKey(skillBaseStructs); float skillCoolingTime = iSkillState.GetSkillRuntimeCoolingTime(skillID); //本技能的冷却时间 float maxTime = skillCoolingTime > iSkillState.PublicCoolingTime ? (skillCoolingTime / iSkillState.GetSkillMaxCoolingTime(skillID)) : iSkillState.PublicCoolingTime; //选取最大的时间作为显示时间 if (skillBaseStructs.Length > 0 && skillBaseStructs[0] != null) { Sprite sprite = SkillCombineStaticTools.GetCombineSkillSprite(skillStructData, (int)skillBaseStructs[0].skillType); SetImageSprite(firstImage, sprite); SetImageInnerState(firstInnerImage, maxTime); } else//清理第一个框 { SetImageSprite(firstImage, null); SetImageInnerState(firstInnerImage, 0); } if (skillBaseStructs.Length > 1 && skillBaseStructs[1] != null) { Sprite sprite = SkillCombineStaticTools.GetCombineSkillSprite(skillStructData, (int)skillBaseStructs[1].skillType); SetImageSprite(secondImage, sprite); SetImageInnerState(secondInnerImage, maxTime); } else//清理第二个框 { SetImageSprite(secondImage, null); SetImageInnerState(secondInnerImage, 0); } if (skillBaseStructs.Length > 2 && skillBaseStructs[2] != null) { Sprite sprite = SkillCombineStaticTools.GetCombineSkillSprite(skillStructData, (int)skillBaseStructs[2].skillType); SetImageSprite(thirdImage, sprite); SetImageInnerState(thirdInnerImage, maxTime); } else//清理第三个框 { SetImageSprite(thirdImage, null); SetImageInnerState(thirdInnerImage, 0); } if (skillBaseStructs.Length > 3 && skillBaseStructs[3] != null) { Sprite sprite = SkillCombineStaticTools.GetCombineSkillSprite(skillStructData, (int)skillBaseStructs[3].skillType); SetImageSprite(fourthImage, sprite); SetImageInnerState(fourthInnerImage, maxTime); } else//清理第四个框 { SetImageSprite(fourthImage, null); SetImageInnerState(fourthInnerImage, 0); } } else { SetImageSprite(firstImage, null); SetImageSprite(secondImage, null); SetImageSprite(thirdImage, null); SetImageSprite(fourthImage, null); SetImageInnerState(firstInnerImage, 0); SetImageInnerState(secondInnerImage, 0); SetImageInnerState(thirdInnerImage, 0); SetImageInnerState(fourthInnerImage, 0); } }