ObjectReferenceKeyframe
структура в UnityEditor
Описание
Ключевой кадр к ссылке Объект.
Используйте ключевой кадр ссылки на объект для создания массива ссылок на объект. AnimationClip использует массив ссылок на объект для анимации свойств.
Используйте методы AnimationUtility.SetObjectReferenceCurve и AnimationUtility.SetObjectReferenceCurves для назначения массивов ObjectReferenceKeyframe свойств ссылки на объект AnimationClip. Используйте метод AnimationUtility.GetObjectReferenceCurve для получения массива ObjectReferenceKeyframe для свойства ссылки на объект.
Дополнительные ресурсы: AnimationClip AnimationUtility.SetObjectReferenceCurve AnimationUtility.SetObjectReferenceCurves AnimationUtility.GetObjectReferenceCurve.
using UnityEditor; using UnityEngine; static class AnimationClipWithObjectReferenceKeyframesExample { // This example creates an AnimationClip of a sequence of sprites selected // in the project view. The clip is saved as an asset in the project. [MenuItem("Example/Create Flip Book Animation Clip From Sprites")] static void CreateFlipBookAnimationClipFromSprites() { var selectedSprites = Selection.GetFiltered<Sprite>(SelectionMode.Unfiltered); if (selectedSprites == null || selectedSprites.Length == 0) { Debug.LogError("Please select sprites in the project view to create a clip for."); return; } AnimationClip clip = new AnimationClip(); var spriteCurve = new ObjectReferenceKeyframe[selectedSprites.Length]; for (int i = 0; i < selectedSprites.Length; ++i) { var sprite = selectedSprites[i]; spriteCurve[i] = new ObjectReferenceKeyframe { time = i/clip.frameRate, value = sprite }; } var spriteBinding = EditorCurveBinding.PPtrCurve("", typeof(SpriteRenderer), "m_Sprite"); AnimationUtility.SetObjectReferenceCurve(clip, spriteBinding, spriteCurve); AssetDatabase.CreateAsset(clip, AssetDatabase.GenerateUniqueAssetPath($"Assets/FlipBookClip.anim")); } }