Version: 2023.1
언어: 한국어

GenericBindingUtility

class in UnityEngine.Animations

매뉴얼로 전환

설명

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) &amp;&amp; !editorCurveBinding.isPPtrCurve &amp;&amp; !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); } }

정적 함수

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