GenericBindingUtility
класс в UnityEngine.Animations
Выполнено в:UnityEngine.AnimationModule
Описание
Функции Animation для чтения и записи значений из компонентов Unity.
using System.Collections.Generic; using UnityEngine; using UnityEngine.Animations; using UnityEditor; using Unity.Collections; using System.Linq;
public class AnimationClipPlayer : MonoBehaviour { public AnimationClip animationClip; public float time;
List<AnimationCurve> curves;
NativeArray<BoundProperty> floatProperties; NativeArray<BoundProperty> intProperties; NativeArray<float> floatValues; NativeArray<int> intValues;
void Start() { var editorCurveBindings = AnimationUtility.GetCurveBindings(animationClip); editorCurveBindings = editorCurveBindings.Where(editorCurveBinding => editorCurveBinding.type != typeof(Transform) && !editorCurveBinding.isPPtrCurve && !editorCurveBinding.isDiscreteCurve ).ToArray();
curves = new List<AnimationCurve>(editorCurveBindings.Length); for (var i = 0; i < editorCurveBindings.Length; i++) { curves.Add(AnimationUtility.GetEditorCurve(animationClip, editorCurveBindings[i])); }
var genericBindings = new NativeArray<GenericBinding>(AnimationUtility.EditorCurveBindingsToGenericBindings(editorCurveBindings), Allocator.Temp); GenericBindingUtility.BindProperties(gameObject, genericBindings, out floatProperties, out intProperties, Allocator.Persistent);
floatValues = new NativeArray<float>(floatProperties.Length, Allocator.Persistent); intValues = new NativeArray<int>(intProperties.Length, Allocator.Persistent); }
private void OnDestroy() { floatProperties.Dispose(); floatValues.Dispose(); intProperties.Dispose(); intValues.Dispose(); }
// Update is called once per frame void Update() { for (int i = 0; i < curves.Count; i++) { floatValues[i] = curves[i].Evaluate(time); }
GenericBindingUtility.SetValues(floatProperties, floatValues); } }
Статические методы
| Метод | Описание |
|---|---|
| BindProperties | Получает список BoundProperty, определенный списком GenericBinding. |
| CreateGenericBinding | Получает GenericBinding, который представляет определенное свойство, связанное с GameObject или одним из его компонентов. |
| GetAnimatableBindings | Получает анимированные привязки для конкретного GameObject. |
| GetCurveBindings | Получает привязки кривых из клипа анимации. |
| GetValues | Получает значение с плавающей запятой или целое число для каждого [[BoundProperty]. |
| SetValues | Задает значение с плавающей запятой или целое число для каждого [[BoundProperty]. |
| UnbindProperties | Развязывает и высвобождает все ресурсы, используемые списком BoundProperty. |