Version: 2023.2
LanguageEnglish
  • C#

GenericBindingUtility

class in UnityEngine.Animations

/

Implemented in:UnityEngine.AnimationModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Animation utility functions for reading and writing values from Unity components.

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

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.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961