private void InitShow() { IPlayerAttributeState iAttributeState = GameState.Instance.GetEntity <IPlayerAttributeState>(); ChangeHPShow(iAttributeState); ChangeMPShow(iAttributeState); }
private void OnEnable() { iPlayerAttributeState = GameState.Instance.GetEntity <IPlayerAttributeState>(); GameState.Instance.Registor <IPlayerAttributeState>(IPlayerAttributeStateChanged); Type t = typeof(IAttributeState); PropertyInfo propertyInfo = t.GetProperty(field_Attribute); if (propertyInfo != null) { FieldExplanAttribute fea = FieldExplanAttribute.GetPropertyExplan(propertyInfo); if (fea != null) { showName = fea.GetExplan(); } else { showName = null; } } else { showName = null; } if (!string.IsNullOrEmpty(showName)) { IPlayerAttributeStateChanged(iPlayerAttributeState, propertyInfo.Name); } }
/// <summary> /// 改变魔法条 /// </summary> /// <param name="iAttributeState"></param> private void ChangeMPShow(IPlayerAttributeState iAttributeState) { float bili = iAttributeState.Mana / iAttributeState.MaxMana; bili = Mathf.Clamp(bili, 0, 1); mpValueImage.fillAmount = bili; mpValueText.text = (int)iAttributeState.Mana + "/" + (int)iAttributeState.MaxMana; }
/// <summary> /// 改变血条 /// </summary> /// <param name="iAttributeState"></param> private void ChangeHPShow(IPlayerAttributeState iAttributeState) { float bili = iAttributeState.HP / iAttributeState.MaxHP; bili = Mathf.Clamp(bili, 0, 1); hpValueImage.fillAmount = bili; hpValueText.text = (int)iAttributeState.HP + "/" + (int)iAttributeState.MaxHP; }
private void PlayerAttributeStateChanged(IPlayerAttributeState iAttribute, string fieldName) { if (string.Equals(fieldName, GameState.GetFieldNameStatic <IPlayerAttributeState, float>(temp => temp.HP))) { if (iAttribute.HP <= 0) { InitTarget(); } } }
public override void SetForcus() { uiAddNum.gameObject.SetActive(true); okRectTrans.gameObject.SetActive(false); iPlayerAttributeState = GameState.Instance.GetEntity <IPlayerAttributeState>(); playerState = DataCenter.Instance.GetEntity <PlayerState>(); keyValueList = new List <KeyValuePair <EnumBaseAttributeType, string> >(); FieldExplanAttribute.SetEnumExplanDic(keyValueList); addPoint = 0; UpdateShow(); }
/// <summary> /// 当玩家属性发生变化时的回调 /// </summary> /// <param name="iAttributeState"></param> /// <param name="fieldName"></param> private void IAttributeState_Callback(IPlayerAttributeState iAttributeState, string fieldName) { if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.HP)) || string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.MaxHP))) { ChangeHPShow(iAttributeState); } else if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.Mana)) || string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.MaxMana))) { ChangeMPShow(iAttributeState); } }
/// <summary> /// 玩家属性发生变化时 /// </summary> /// <param name="iPlayerAttributeState"></param> /// <param name="fieldName"></param> private void IPlayerAttributeStateChanged(IPlayerAttributeState iPlayerAttributeState, string fieldName) { if (string.IsNullOrEmpty(fieldName) || string.IsNullOrEmpty(field_Attribute)) { return; } if (string.Equals(fieldName, field_Attribute)) { Type t = typeof(IAttributeState); PropertyInfo propertyInfo = t.GetProperty(field_Attribute); MethodInfo methodInfo = propertyInfo.GetGetMethod(); if (methodInfo != null) { showText.text = showName + ":" + methodInfo.Invoke(iPlayerAttributeState, null); } } }
/// <summary> /// 监听角色属性更改(主要是速度,还有血量) /// </summary> /// <param name="iPlayerState"></param> /// <param name="fieldName"></param> private void CallBackIAttributeState(IPlayerAttributeState iPlayerAttribute, string fieldName) { if (!playerAnimator) { return; } if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.AttackSpeed))) { if (physicAttackDelayCoroutine == null)//如果正在执行携程则不做该操作,携程处理完成后会自动处理该操作 { PlayerAnimSpeed.speedRate = iPlayerAttribute.AttackSpeed; } } else if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerAttributeState, float>(temp => temp.HP))) { //设置动画状态 playerAnimator.SetBool("Death", iPlayerAttribute.HP <= 0); } }
/// <summary> /// 属性发生变化更新文本 /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> private void IPlayerAttributeStateChanged(IPlayerAttributeState arg1, string arg2) { UpdateText(); }