Version: 2018.2
public static bool IsPropertyAnimated (Object target, string propertyPath);

Parameters

targetThe object to determine if it contained the animation.
propertyPathThe name of the animation to search for.

Returns

bool Whether the property search is found or not.

Description

Указанное свойство в настоящее время в режиме анимации и анимируется?

IsPropertyAnimated checks whether a property is being animated. This check requires also the object where the property can be found.

color is searched for in the following script example . It is part of the Renderer object. Note that the example uses a sphere GameObject and an animation file, color.anim. The color animation in color.anim has the color varying from yellow to blue.

// Demo showing how IsPropertyAnimated() can be used to determine if a property
// on an object is being animated. In this example the color in a Renderer is
// animated.

using UnityEngine; using UnityEditor;

public class ExampleClass : EditorWindow { protected GameObject go; protected AnimationClip animationClip; protected float time = 0.0f; protected bool showColor = false;

[MenuItem("Examples/AnimationMode demo")] public static void DoWindow() { var window = GetWindow<ExampleClass>(); window.Show(); }

void OnGUI() { if (go == null) { EditorGUILayout.HelpBox("Select a GO", MessageType.Info); return; }

EditorGUILayout.LabelField("Color slider");

if (animationClip == null) { AnimationMode.StartAnimationMode(); animationClip = AssetDatabase.LoadAssetAtPath<AnimationClip>("Assets/color.anim"); }

if (animationClip != null) { float startTime = 0.0f; float stopTime = animationClip.length; time = EditorGUILayout.Slider(time, startTime, stopTime); }

if (showColor) { EditorGUILayout.LabelField("Red color being animated"); } }

void Update() { if (go == null) return;

if (animationClip == null) return;

if (AnimationMode.InAnimationMode()) { Renderer rend = go.GetComponent<Renderer>();

if (AnimationMode.IsPropertyAnimated(rend, "material._Color.r")) { showColor = true; } else { showColor = false; }

AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, time); AnimationMode.EndSampling();

SceneView.RepaintAll(); } }

// Has a GameObject been selection? public void OnSelectionChange() { go = Selection.activeGameObject; Repaint(); }

public void OnDestroy() { Debug.Log("Shutting down"); AnimationMode.StopAnimationMode(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961