/// <summary> /// Refreshes the contents of the curve and property display by loading animation curves from the provided /// animation clip. /// </summary> /// <param name="clip">Clip containing the animation to load.</param> private void LoadAnimClip(AnimationClip clip) { EditorPersistentData persistentData = EditorApplication.PersistentData; if (persistentData.dirtyAnimClips.TryGetValue(clip.UUID, out clipInfo)) { // If an animation clip is imported, we don't care about it's cached curve values as they could have changed // since last modification, so we re-load the clip. But we persist the events as those can only be set // within the editor. if (clipInfo.isImported) { EditorAnimClipInfo newClipInfo = EditorAnimClipInfo.Create(clip); newClipInfo.events = clipInfo.events; } } else clipInfo = EditorAnimClipInfo.Create(clip); persistentData.dirtyAnimClips[clip.UUID] = clipInfo; AnimFieldInfo[] fieldInfos = new AnimFieldInfo[clipInfo.curves.Count]; int idx = 0; foreach (var curve in clipInfo.curves) fieldInfos[idx++] = new AnimFieldInfo(curve.Key, curve.Value); guiFieldDisplay.SetFields(fieldInfos); guiCurveEditor.Events = clipInfo.events; guiCurveEditor.DisableCurveEdit = clipInfo.isImported; SetCurrentFrame(0); FPS = clipInfo.sampleRate; }
/// <summary> /// Checks if the currently selected object has changed, and rebuilds the GUI and loads the animation clip if needed. /// </summary> /// <param name="force">If true the GUI rebuild and animation clip load will be forced regardless if the active /// scene object changed.</param> private void UpdateSelectedSO(bool force) { SceneObject so = Selection.SceneObject; if (selectedSO != so || force) { if (selectedSO != null && so == null) { EditorInput.OnPointerPressed -= OnPointerPressed; EditorInput.OnPointerMoved -= OnPointerMoved; EditorInput.OnPointerReleased -= OnPointerReleased; EditorInput.OnButtonUp -= OnButtonUp; } else if (selectedSO == null && so != null) { EditorInput.OnPointerPressed += OnPointerPressed; EditorInput.OnPointerMoved += OnPointerMoved; EditorInput.OnPointerReleased += OnPointerReleased; EditorInput.OnButtonUp += OnButtonUp; } SwitchState(State.Empty); selectedSO = so; zoomAmount = 0.0f; selectedFields.Clear(); clipInfo = null; UndoRedo.Clear(); RebuildGUI(); // Load existing clip if one exists if (selectedSO != null) { Animation animation = selectedSO.GetComponent<Animation>(); if (animation != null) { AnimationClip clip = animation.DefaultClip; if (clip != null) LoadAnimClip(clip); } } if(clipInfo == null) clipInfo = new EditorAnimClipInfo(); SwitchState(State.Normal); currentClipState = CreateClipState(); if (selectedSO != null) { // Select first curve by default foreach (var KVP in clipInfo.curves) { SelectField(KVP.Key, false); break; } UpdateDisplayedCurves(true); } } }