您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

51 行
1.4 KiB

using UnityEngine;
using UnityEngine.Playables;
public class SimpleTranstion<U> where U : struct, IPlayable
{
public SimpleTranstion(U target, params int[] ports)
{
m_target = target;
m_ports = ports;
}
public void Update(int activePort, float blendVelocity, float deltaTime)
{
// Update current state weight
float weight = m_target.GetInputWeight(activePort);
if (weight != 1.0f)
{
weight = Mathf.Clamp(weight + blendVelocity * deltaTime, 0, 1);
m_target.SetInputWeight(activePort, weight);
}
// Adjust weight of other states and ensure total weight is 1
float weighLeft = 1.0f - weight;
float totalWeight = 0;
for (int i = 0; i < m_ports.Length; i++)
{
int port = m_ports[i];
if (port == activePort)
continue;
totalWeight += m_target.GetInputWeight(port);
}
if (totalWeight == 0)
return;
float fraction = weighLeft / totalWeight;
for (int i = 0; i < m_ports.Length; i++)
{
int port = m_ports[i];
if (port == activePort)
continue;
float w = m_target.GetInputWeight(port);
w = w * fraction;
m_target.SetInputWeight(port, w);
}
}
int[] m_ports;
U m_target;
}