public void setEasingCurve() { string name = getSelectedEaseName(category, selectedIndex); if (name == "Custom") { if (curve.length <= 0) { curve = getCurve(Ease.Linear); this.Repaint(); } return; } Ease ease = (Ease)AMTimeline.GetEaseIndex(getSelectedEaseIndex(category, selectedIndex)); curve = getCurve(ease); selectedCurve = getCurve(ease); this.Repaint(); }
void Update() { percent += 0.003f * speedValues[selectedSpeedIndex]; if (percent > 1f + waitPercent) { percent = waitPercent * -1f; } float x_pos_start = 50f; float x_pos_end = position.width - 50f - 80f - 200f; if (percent <= 1f) { if (isCustomEase) { x_pos = AMUtil.EaseCustom(x_pos_start, x_pos_end - x_pos_start, percent < 0f ? 0f : percent, curve); } else { var ease = AMUtil.GetEasingFunction((Ease)AMTimeline.GetEaseIndex(getSelectedEaseIndex(category, selectedIndex))); x_pos = x_pos_start + (x_pos_end - x_pos_start) * ease(percent < 0f ? 0f : percent, 1.0f, 0.0f, 0.0f); } } this.Repaint(); }
void OnGUI() { #if UNITY_5 titleContent = new GUIContent("Ease: " + (oData.time_numbering ? AMTimeline.frameToTime(key.frame, (float)aData.currentTake.frameRate) + " s" : key.frame.ToString())); #else title = "Ease: " + (oData.time_numbering ? AMTimeline.frameToTime(key.frame, (float)aData.currentTake.frameRate) + " s" : key.frame.ToString()); #endif AMTimeline.loadSkin(ref skin, ref cachedSkinName, position); bool updateEasingCurve = false; GUIStyle styleBox = new GUIStyle(GUI.skin.button); styleBox.normal = GUI.skin.button.active; styleBox.hover = styleBox.normal; styleBox.border = GUI.skin.button.border; GUILayout.BeginArea(new Rect(5f, 5f, position.width - 10f, position.height - 10f)); GUILayout.BeginHorizontal(); if (GUILayout.Button("", styleBox, GUILayout.Width(500f), GUILayout.Height(100f))) { selectedSpeedIndex = (selectedSpeedIndex + 1) % speedValues.Length; percent = waitPercent * -1f; } GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); int prevCategory = category; bool updatedSelectedIndex = false; if (setCategory(GUILayout.SelectionGrid(category, categories, (position.width >= 715f ? 12 : 6), GUILayout.Width(position.width - 16f)))) { selectedIndex = getSelectedEaseIndex(prevCategory, selectedIndex); selectedIndex = getCategoryIndexForEase(selectedIndex); if (selectedIndex < 1) { selectedIndex = 1; percent = waitPercent * -1f; updatedSelectedIndex = true; } } GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.BeginVertical(GUILayout.Height(233f)); if (updatedSelectedIndex || setSelectedIndex(GUILayout.SelectionGrid(selectedIndex, easeTypesFiltered[category].ToArray(), 3))) { percent = waitPercent * -1f; updateEasingCurve = true; if (getSelectedEaseName(category, selectedIndex) == "Custom") { isCustomEase = true; if (key.customEase.Count > 0) { curve = key.getCustomEaseCurve(); } else { setEasingCurve(); } } else { isCustomEase = false; } } GUILayout.EndVertical(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Apply")) { int nease = AMTimeline.GetEaseIndex(getSelectedEaseIndex(category, selectedIndex)); bool shouldUpdateCache = false; if (isCustomEase) { key.setCustomEase(curve); shouldUpdateCache = true; } if (key.easeType != nease) { shouldUpdateCache = true; } if (shouldUpdateCache) { AnimatorDataEdit.RecordUndoTrackAndKeys(track, false, "Change Ease"); key.setEaseType(nease); // update cache when modifying varaibles track.updateCache(aData.target); // preview new position aData.currentTake.previewFrame(aData.target, aData.currentTake.selectedFrame); } this.Close(); } if (GUILayout.Button("Cancel")) { this.Close(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); // orb texture GUI.DrawTexture(new Rect(x_pos, 15f, 80f, 80f), tex_orb); // speed label GUIStyle styleLabelRight = new GUIStyle(GUI.skin.label); styleLabelRight.alignment = TextAnchor.MiddleRight; styleLabelRight.normal.textColor = Color.white; EditorGUI.DropShadowLabel(new Rect(475f, 5f, 25f, 25f), speedNames[selectedSpeedIndex], styleLabelRight); // draw border GUI.color = GUI.skin.window.normal.textColor; GUI.DrawTexture(new Rect(0f, 0f, 7f, 110f), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(position.width - 209f, 0f, 208f, 110f), EditorGUIUtility.whiteTexture); GUI.color = Color.white; // curve field if (updateEasingCurve) { setEasingCurve(); } else if (!isCustomEase && didChangeCurve()) { isCustomEase = true; selectedIndex = getCategoryIndexForEaseName("Custom"); if (selectedIndex < 0) { category = 0; selectedIndex = getCategoryIndexForEaseName("Custom"); } } curve = EditorGUI.CurveField(new Rect(500f, 5f, 208f, 100f), curve); }