71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
|
using Games.LogicObj;
|
|||
|
using GCGame.Table;
|
|||
|
using Module.Log;
|
|||
|
using UnityEngine;
|
|||
|
/// <summary>
|
|||
|
/// 模型材质属性随生命值修改
|
|||
|
/// Effect.txt 表格扩展参数说明
|
|||
|
/// Param1 :EffectParam.txt中id值 身体材质属性相关配置
|
|||
|
/// Param2 :EffectParam.txt中id值 右武器材质属性相关配置
|
|||
|
/// Param3 :EffectParam.txt中id值 左武器材质属性相关配置
|
|||
|
/// Param4 :EffectParam.txt中id值 动画曲线id
|
|||
|
///
|
|||
|
/// EffectParams 参考ChangeMatPro
|
|||
|
/// </summary>
|
|||
|
public class Impact_MatProByHealth : ImpactEffectBase
|
|||
|
{
|
|||
|
private ChangeMatPro _materialPropertyMod;
|
|||
|
private AnimationCurve _animationCurve;
|
|||
|
private Obj_Character _character;
|
|||
|
private float? _lastRatio;
|
|||
|
public override EffectLogic.EffectType ImpactEffectType
|
|||
|
{
|
|||
|
get { return EffectLogic.EffectType.TYPE_MATPROBYHEALTH; }
|
|||
|
}
|
|||
|
// Hack重用ChangeMatPro类型。直接添加SetRatio的接口,不走Update流程来控制当前实际效果
|
|||
|
public override void StartEffect()
|
|||
|
{
|
|||
|
base.StartEffect();
|
|||
|
if (objCharacter != null && Data != null)
|
|||
|
{
|
|||
|
var character = objCharacter as Obj_Character;
|
|||
|
if (character == null)
|
|||
|
LogModule.ErrorLog(string.Format("试图为非角色Obj {0}添加{1}类型的Impact!", objCharacter.name, ImpactEffectType));
|
|||
|
else
|
|||
|
{
|
|||
|
_character = character;
|
|||
|
var paramid = Data.GetParamValuebyIndex(bodyPart);
|
|||
|
var param = TableManager.GetEffectParamByID(paramid, 0);
|
|||
|
if (param != null && _materialPropertyMod == null)
|
|||
|
{
|
|||
|
var animationId = Data.GetParamValuebyIndex(3);
|
|||
|
_animationCurve = CommonUtility.GetAnimationCurveById(animationId);
|
|||
|
_materialPropertyMod = new ChangeMatPro(objCharacter, BodyToModelPart(bodyPart), param);
|
|||
|
_materialPropertyMod.Start(param, float.PositiveInfinity);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void StopEffect()
|
|||
|
{
|
|||
|
base.StopEffect();
|
|||
|
if (_materialPropertyMod != null)
|
|||
|
_materialPropertyMod.StopEffect();
|
|||
|
}
|
|||
|
|
|||
|
protected override void UpdateInherited()
|
|||
|
{
|
|||
|
if (_character != null && _character.BaseAttr != null && _materialPropertyMod != null)
|
|||
|
{
|
|||
|
var ratio = (float)_character.BaseAttr.HP / _character.BaseAttr.MaxHP;
|
|||
|
ratio = Mathf.Clamp01(ratio);
|
|||
|
ratio = _animationCurve.Evaluate(ratio);
|
|||
|
if (ratio != _lastRatio)
|
|||
|
{
|
|||
|
_lastRatio = ratio;
|
|||
|
_materialPropertyMod.SetRatio(ratio);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|