优化代码如下,实测有效
public void ChangeBlenderShapeValue(string blenderShapeValue,float value)
{
if (!blenderShapeDatabase.ContainsKey(blenderShapeValue))
{
Debug.LogError("输入有误");
return;
}
BlenderShape blenderShape = blenderShapeDatabase[blenderShapeValue];
if (blenderShape.PositiveIndex < 0 && blenderShape.NegativeIndex < 0)
{
Debug.LogError("字典读取有误");
return;
}
if (blenderShape.PositiveIndex<0||blenderShape.NegativeIndex<0)
{
value = Mathf.Clamp(value, 0, 100);
Target.SetBlendShapeWeight(Mathf.Max(blenderShape.PositiveIndex, blenderShape.NegativeIndex),value);
}
else
{
value = Mathf.Clamp(value, -100, 100);
if (value>=0)
{
Target.SetBlendShapeWeight(blenderShape.PositiveIndex,value);
}
else
{
Target.SetBlendShapeWeight(blenderShape.NegativeIndex, -value);
}
}