trimend( );表示如果字符尾部有括号内的字符,则去掉尾部
挂载在游戏物体上的单例需要进行泛型约束
public class singleton<T>:monobehaviour
where T:monobehaviour
代表不是继承自monobehaviour的类无法使用这个单例
优化代码如下,实测有效
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);
}
}