Version: Unity 6 Preview (6000.0)
LanguageEnglish
  • C#

AnimationMode

class in UnityEditor

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

AnimationMode is used by the AnimationWindow to store properties modified by the AnimationClip playback.

When exiting AnimationMode all properties are reverted to their default state. Animated properties are also highlighted by the inspector. Use StartAnimationMode to enter Animation mode. In Animation mode the editor is tinted to show that it is animating. Properties can be animated via SampleAnimationClip.

The following script example shows how a GameObject can be animated. AnimationMode has functions which support this. The demo can be launched from the "Examples/AnimationMode demo" menu. Once this demo starts it requires a GameObject to be selected in the Scene window. (This example requires the game to not be running in the Game view.) After a GameObject has been selected the example window will change. Choose a created animation clip for the chosen GameObject. Once the animation clip has been loaded the animation can be applied to the GameObject. Clicking the Animate button adds a slider to the window. Using the slider will apply the animation to the selected GameObject. The Lock button prevents the animation to be applied to a different GameObject.

using UnityEngine;
using UnityEditor;

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

[MenuItem("Examples/AnimationMode demo", false, 2000)] public static void DoWindow() { var window = GetWindowWithRect<ExampleClass>(new Rect(0, 0, 300, 80)); window.Show(); }

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

// Main editor window public void OnGUI() { // Wait for user to select a GameObject if (go == null) { EditorGUILayout.HelpBox("Please select a GameObject", MessageType.Info); return; }

// Animate and Lock buttons. Check if Animate has changed GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); GUILayout.Toggle(AnimationMode.InAnimationMode(), "Animate"); if (EditorGUI.EndChangeCheck()) ToggleAnimationMode();

GUILayout.FlexibleSpace(); lockSelection = GUILayout.Toggle(lockSelection, "Lock"); GUILayout.EndHorizontal();

// Slider to use when Animate has been ticked EditorGUILayout.BeginVertical(); animationClip = EditorGUILayout.ObjectField(animationClip, typeof(AnimationClip), false) as AnimationClip; if (animationClip != null) { float startTime = 0.0f; float stopTime = animationClip.length; time = EditorGUILayout.Slider(time, startTime, stopTime); } else if (AnimationMode.InAnimationMode()) AnimationMode.StopAnimationMode(); EditorGUILayout.EndVertical(); }

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

if (animationClip == null) return;

// Animate the GameObject if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode()) { AnimationMode.BeginSampling(); AnimationMode.SampleAnimationClip(go, animationClip, time); AnimationMode.EndSampling();

SceneView.RepaintAll(); } }

void ToggleAnimationMode() { if (AnimationMode.InAnimationMode()) AnimationMode.StopAnimationMode(); else AnimationMode.StartAnimationMode(); } }

Static Properties

animatedPropertyColorThe color used to show that a property is currently being animated.
candidatePropertyColorThe color used to show that an animated property has been modified.
recordedPropertyColorThe color used to show that an animated property automatically records changes in the animation clip.

Static Methods

AddEditorCurveBindingMarks a property defined by an EditorCurveBinding as currently being animated.
AddPropertyModificationMarks a property as currently being animated.
BeginSamplingInitialise the start of the animation clip sampling.
EndSamplingFinish the sampling of the animation clip.
InAnimationModeChecks whether the Editor is in Animation mode.
IsPropertyAnimatedChecks whether the specified property is in Animation mode and is being animated.
SampleAnimationClipSamples the AnimationClip for the GameObject and also records modified properties when in Animation mode.
SamplePlayableGraphSamples the specified output index of a PlayableGraph and also records modified properties when in Animation mode.
StartAnimationModeStarts the Animation mode.
StopAnimationModeStops the Animation mode and reverts any properties that were animated while in Animation mode.