Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GenericBindingUtility

Animation utility functions for reading and writing values from Unity components.
Read time 2 minutesLast updated 4 days ago

Definition

public static class GenericBindingUtility

Examples

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); }}

Static Methods

Method

Description

BindPropertiesRetrieves the list of BoundProperty defined by the list of GenericBinding.
CreateGenericBindingRetrieves the GenericBinding that represents a specific property associated with a GameObject or one of its components.
GetAnimatableBindingsRetrieves the animatable bindings for a specific GameObject.
GetCurveBindingsRetrieves the curve bindings from an animation clip.
GetValuesRetrieves the float or integer value for each [[BoundProperty].
SetValuesSets the float or integer value for each [[BoundProperty].
UnbindPropertiesUnbinds and frees all resources used by a list of BoundProperty.