Version: 2020.2

AssetPostprocessor.OnPostprocessGameObjectWithAnimatedUserProperties(GameObject, EditorCurveBinding[])

切换到手册

参数

gameObject 具有动画自定义属性的游戏对象。
bindings 绑定到自定义属性的动画曲线。

描述

当自定义属性的动画曲线已完成导入时调用此函数。

对于具有动画自定义属性的每个游戏对象都会调用它。每个动画属性都有一个由 EditorCurveBinding 表示的动画曲线。这使您可以动态地将组件添加到游戏对象,并将 EditorCurveBindings 重新定位到任何可动画化的属性。

using UnityEngine;
using UnityEditor;

class MyAllPostprocessor : AssetPostprocessor { void OnPostprocessGameObjectWithAnimatedUserProperties(GameObject go, EditorCurveBinding[] bindings) { // add a particle emitter to every game object that has a custom property called "particleAmount" // then map the animation to the emission rate for (int i = 0; i < bindings.Length; i++) { if (bindings[i].propertyName == "particlesAmount") { ParticleSystem emitter = go.AddComponent<ParticleSystem>(); var emission = emitter.emission; emission.rateOverTimeMultiplier = 0;

bindings[i].propertyName = "EmissionModule.rateOverTime.scalar"; bindings[i].path = AnimationUtility.CalculateTransformPath(go.transform, go.transform.root); bindings[i].type = typeof(ParticleSystem); } } } }