void CreateClip() { DSCommonMethods.RecreateFolders(myPath); AnimationClip myClip = new AnimationClip(); foreach (ToggleObject obj in targets) { if (obj == null) { continue; } string path = AnimationUtility.CalculateTransformPath(obj.Obj.transform, root.transform); if (!gesture) { myClip.SetCurve(path, typeof(GameObject), "m_IsActive", new AnimationCurve { keys = new Keyframe[] { new Keyframe { time = 0, value = obj.active ? 1 : 0 } } }); } else { myClip.SetCurve(path, typeof(GameObject), "m_IsActive", new AnimationCurve { keys = new Keyframe[] { new Keyframe { time = 0, value = obj.active ? 1 : 0 }, new Keyframe { time = 1f / 60f, value = obj.active ? 1 : 0 } } }); } } if (gesture) { AnimationClipSettings settings = AnimationUtility.GetAnimationClipSettings(myClip); settings.loopTime = true; AnimationUtility.SetAnimationClipSettings(myClip, settings); } string clipPath = AssetDatabase.GenerateUniqueAssetPath(myPath + "/" + clipName + ".anim"); AssetDatabase.CreateAsset(myClip, clipPath); if (pingClip) { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(clipPath)); } Debug.Log(clipPath.Substring(clipPath.LastIndexOf('/') + 1, clipPath.Length - clipPath.LastIndexOf('/') - 6) + " Created."); if (autoClose) { Close(); } }
private void OnGUI() { if (!init) { RefreshList(); } scroll = EditorGUILayout.BeginScrollView(scroll); EditorGUI.BeginChangeCheck(); root = (GameObject)EditorGUILayout.ObjectField("Root", root, typeof(GameObject), true); if (EditorGUI.EndChangeCheck()) { CheckIfValid(); } EditorGUILayout.BeginHorizontal(); clipName = EditorGUILayout.TextField("Clip Name", clipName); EditorGUIUtility.labelWidth = 70; EditorGUI.BeginChangeCheck(); autoName = EditorGUILayout.Toggle(new GUIContent("AutoName", "Automatically generate a clip name when using context menu button"), autoName, GUILayout.Width(100)); if (EditorGUI.EndChangeCheck()) { PlayerPrefs.SetInt("QuickToggleAutoName", autoName ? 1 : 0); } EditorGUIUtility.labelWidth = 0; EditorGUILayout.EndHorizontal(); targetList.DoLayoutList(); EditorGUI.BeginChangeCheck(); gesture = EditorGUILayout.Toggle(new GUIContent("Is Gesture", "Generates curves in 2 frames rather than 1 and sets loop time to true."), gesture); if (EditorGUI.EndChangeCheck()) { PlayerPrefs.SetInt("QuickToggleIsGesture", gesture ? 1 : 0); } EditorGUI.BeginChangeCheck(); pingClip = EditorGUILayout.Toggle(new GUIContent("Ping Clip", "Automatically highlights the newly generated clip in Assets"), pingClip); if (EditorGUI.EndChangeCheck()) { PlayerPrefs.SetInt("QuickTogglePingClip", pingClip ? 1 : 0); } EditorGUI.BeginChangeCheck(); autoClose = EditorGUILayout.Toggle(new GUIContent("Close Window", "Close window upon clip creation."), pingClip); if (EditorGUI.EndChangeCheck()) { PlayerPrefs.SetInt("QuickToggleAutoClose", autoClose ? 1 : 0); } EditorGUI.BeginDisabledGroup(!clipValid || string.IsNullOrWhiteSpace(clipName)); GUI.SetNextControlName("CreateClip"); if (GUILayout.Button("Create Clip")) { CreateClip(); } EditorGUI.EndDisabledGroup(); DSCommonMethods.AssetFolderPath(ref myPath, "Clips Path", "QuickTogglePath"); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); DSCommonMethods.Credit(); EditorGUILayout.EndScrollView(); if (!init) { GUI.FocusControl("CreateClip"); init = true; } if (GUI.GetNameOfFocusedControl() == "CreateClip" && Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)) { CreateClip(); } }