WeightUtility.cs 880 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine.Playables;
  2. namespace UnityEngine.Timeline
  3. {
  4. static class WeightUtility
  5. {
  6. // Given a mixer, normalizes the mixer if required
  7. // returns the output weight that should be applied to the mixer as input
  8. public static float NormalizeMixer(Playable mixer)
  9. {
  10. if (!mixer.IsValid())
  11. return 0;
  12. int count = mixer.GetInputCount();
  13. float weight = 0.0f;
  14. for (int c = 0; c < count; c++)
  15. {
  16. weight += mixer.GetInputWeight(c);
  17. }
  18. if (weight > Mathf.Epsilon && weight < 1)
  19. {
  20. for (int c = 0; c < count; c++)
  21. {
  22. mixer.SetInputWeight(c, mixer.GetInputWeight(c) / weight);
  23. }
  24. }
  25. return Mathf.Clamp01(weight);
  26. }
  27. }
  28. }