<commit_before>﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace ATP.SimplePathAnimator.PathAnimatorComponent {

    [CustomEditor(typeof (PathAnimator))]
    public sealed class PathAnimatorEditor : Editor {
        
        #region PROPERTIES
        private GizmoIcons GizmoIcons { get; set; }

        private SceneHandles SceneHandles { get; set; }

        private SerializedObject SettingsSerObj { get; set; }
        //public SerializedObject PathExporterSerObj { get; private set; }

        /// <summary>
        ///     Reference to target script.
        /// </summary>
        private PathAnimator Script { get; set; }

        private Shortcuts Shortcuts { get; set; }

        private PathAnimatorSettings Settings { get; set; }

        private PathExporter PathExporter { get; set; }

        #endregion 

        #region SERIALIZED PROPERTIES

        private SerializedProperty advancedSettingsFoldout;
        private SerializedProperty animatedGO;
        private SerializedProperty enableControlsInPlayMode;
        private SerializedProperty forwardPointOffset;
        private SerializedProperty gizmoCurveColor;
        private SerializedProperty maxAnimationSpeed;
        private SerializedProperty pathData;
        //private SerializedProperty positionLerpSpeed;
        private SerializedProperty rotationCurveColor;
        private SerializedProperty rotationSlerpSpeed;
        private SerializedProperty skin;
        private SerializedProperty targetGO;
        private SerializedProperty settings;
        private SerializedProperty shortJumpValue;
        private SerializedProperty longJumpValue;
        #endregion SERIALIZED PROPERTIES

        #region UNITY MESSAGES

        public override void OnInspectorGUI() {
            HandleUndo();

            // TODO Rename to DrawPathDataAssetField().
            DrawPathDataAssetField();

            EditorGUILayout.BeginHorizontal();

            DrawCreatePathAssetButton();
            DrawResetPathInspectorButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            DrawAnimatedGOField();
            DrawTargetGOField();

            EditorGUILayout.Space();

            DrawAnimationTimeValue();

            DrawRotationModeDropdown();
            DrawHandleModeDropdown();
            DrawTangentModeDropdown();
            DrawWrapModeDropdown();

            EditorGUILayout.Space();

            DrawPositionSpeedSlider();
            
            EditorGUIUtility.labelWidth = 208;

            DrawRotationSpeedField();

            EditorGUIUtility.labelWidth = 0;

            DrawForwardPointOffsetSlider();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            DrawResetEaseButton();
            DrawResetRotationPathButton();
            DrawResetTiltingButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            DrawAutoPlayControl();
            DrawEnableControlsInPlayModeToggle();
            DrawUpdateAllToggle();

            EditorGUILayout.Space();

            DrawPlayerControls();

            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = 0;

            //DrawShortcutsHelpBox();
            EditorGUILayout.Space();

            PathExporter.DrawExportControls();

            DrawAdvancedSettingsFoldout();
            DrawAdvancedSettingsControls();

            // Validate inspector settings.
            // Not all inspector controls can be validated with OnValidate().
            if (GUI.changed) ValidateInspectorSettings();

            // Repaint scene after each inspector update.
            SceneView.RepaintAll();
        }

        private void OnEnable() {
            // Get target script reference.
            Script = (PathAnimator) target;

            if (Script.Settings != null) {
                // Initialize Settings property.
                Settings = Script.Settings;
            }

            InstantiateCompositeClasses();
            InitializeSerializedProperties();

            SceneTool.RememberCurrentTool();
            FocusOnSceneView();
            GizmoIcons.CopyIconsToGizmosFolder();
        }
        private void OnDisable() {
            SceneTool.RestoreTool();
        }

        private void OnSceneGUI() {
            CheckForSkinAsset();

            // Return if path asset does not exist.
            if (Script.PathData == null) return;

            if (Settings == null) return;

            // Disable interaction with background scene elements.
            HandleUtility.AddDefaultControl(
                GUIUtility.GetControlID(
                    FocusType.Passive));

            Shortcuts.HandleShortcuts();

            //Script.UpdateWrapMode();

            HandleDrawingEaseHandles();
            HandleDrawingTiltingHandles();
            HandleDrawingEaseLabel();
            HandleDrawingTiltLabel();
            HandleDrawingUpdateAllModeLabel();
            HandleDrawingPositionHandles();
            HandleDrawingRotationHandle();
            HandleDrawingAddButtons();
            HandleDrawingRemoveButtons();
        }
        #endregion UNITY MESSAGES

        #region INSPECTOR
        private void DrawShortcutsHelpBox() {
            EditorGUILayout.HelpBox(
                "Check Settings Asset for shortcuts.",
                MessageType.Info);
        }

        private void DrawSettingsAssetField() {
            serializedObject.Update();

            EditorGUILayout.PropertyField(
                settings,
                new GUIContent(
                    "Settings Asset",
                    ""));

            serializedObject.ApplyModifiedProperties();
        }

        private void HandleDrawingUpdateAllModeLabel() {
            if (!Settings.UpdateAllMode) return;

            //SceneHandles.DrawNodeLabels(
            //    Script,
            //    "A",
            //    upall
            //    Script.Skin.GetStyle("UpdateAllLabel"));

            SceneHandles.DrawUpdateAllLabels(
                Script,
                Script.Skin.GetStyle("UpdateAllLabel"));
        }


        private void DrawAdvancedSettingsFoldout() {
            serializedObject.Update();

            advancedSettingsFoldout.boolValue = EditorGUILayout.Foldout(
                advancedSettingsFoldout.boolValue,
                new GUIContent(
                    "Advanced Settings",
                    ""));

            serializedObject.ApplyModifiedProperties();
        }

        private void DrawResetRotationPathButton() {
            if (GUILayout.Button(
                            new GUIContent(
                                "Reset Rotation",
                                ""))) {

                if (Script.PathData == null) return;

                Undo.RecordObject(Script.PathData, "Reset rotatio path.");

                // Reset curves to its default state.
                // todo Create direct property for PathData.
                Script.PathData.ResetRotationPath();

                SceneView.RepaintAll();
            }
        }

        private void DrawAdvancedSettingsControls() {
            if (advancedSettingsFoldout.boolValue) {
                DrawGizmoCurveColorPicker();
                DrawRotationCurveColorPicker();

                EditorGUILayout.Space();

                DrawShortJumpValueField();
                DrawLongJumpValueField();

                EditorGUILayout.Space();

                DrawSettingsAssetField();
                DrawSkinSelectionControl();
            }
        }

        private void DrawLongJumpValueField() {
            SettingsSerObj.Update();

            EditorGUILayout.PropertyField(longJumpValue);

            SettingsSerObj.ApplyModifiedProperties();
        }

        private void DrawShortJumpValueField() {
            SettingsSerObj.Update();

            EditorGUILayout.PropertyField(shortJumpValue);

            SettingsSerObj.ApplyModifiedProperties();
        }

        private void DrawAnimatedGOField() {
            serializedObject.Update();
            
            EditorGUILayout.PropertyField(
                animatedGO,
                new GUIContent(
                    "Animated Object",
                    "Object to animate."));

            serializedObject.ApplyModifiedProperties();
        }

        private void DrawAnimationTimeValue() {
            Undo.RecordObject(target, "Update AnimationTime");

            float newTimeRatio = 0;

            switch (Settings.WrapMode) {
                case AnimatorWrapMode.Clamp:
                    newTimeRatio = DrawAnimationTimeSlider();
                    break;
                case AnimatorWrapMode.Loop:
                    newTimeRatio = DrawAnimationTimeFloatField();
                    break;
                case AnimatorWrapMode.PingPong:
                    newTimeRatio = DrawAnimationTimeFloatField();
                    break;
            }
<commit_msg>Draw animation time always as a slider<commit_after>﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace ATP.SimplePathAnimator.PathAnimatorComponent {

    [CustomEditor(typeof (PathAnimator))]
    public sealed class PathAnimatorEditor : Editor {
        
        #region PROPERTIES
        private GizmoIcons GizmoIcons { get; set; }

        private SceneHandles SceneHandles { get; set; }

        private SerializedObject SettingsSerObj { get; set; }
        //public SerializedObject PathExporterSerObj { get; private set; }

        /// <summary>
        ///     Reference to target script.
        /// </summary>
        private PathAnimator Script { get; set; }

        private Shortcuts Shortcuts { get; set; }

        private PathAnimatorSettings Settings { get; set; }

        private PathExporter PathExporter { get; set; }

        #endregion 

        #region SERIALIZED PROPERTIES

        private SerializedProperty advancedSettingsFoldout;
        private SerializedProperty animatedGO;
        private SerializedProperty enableControlsInPlayMode;
        private SerializedProperty forwardPointOffset;
        private SerializedProperty gizmoCurveColor;
        private SerializedProperty maxAnimationSpeed;
        private SerializedProperty pathData;
        //private SerializedProperty positionLerpSpeed;
        private SerializedProperty rotationCurveColor;
        private SerializedProperty rotationSlerpSpeed;
        private SerializedProperty skin;
        private SerializedProperty targetGO;
        private SerializedProperty settings;
        private SerializedProperty shortJumpValue;
        private SerializedProperty longJumpValue;
        #endregion SERIALIZED PROPERTIES

        #region UNITY MESSAGES

        public override void OnInspectorGUI() {
            HandleUndo();

            // TODO Rename to DrawPathDataAssetField().
            DrawPathDataAssetField();

            EditorGUILayout.BeginHorizontal();

            DrawCreatePathAssetButton();
            DrawResetPathInspectorButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            DrawAnimatedGOField();
            DrawTargetGOField();

            EditorGUILayout.Space();

            DrawAnimationTimeValue();

            DrawRotationModeDropdown();
            DrawHandleModeDropdown();
            DrawTangentModeDropdown();
            DrawWrapModeDropdown();

            EditorGUILayout.Space();

            DrawPositionSpeedSlider();
            
            EditorGUIUtility.labelWidth = 208;

            DrawRotationSpeedField();

            EditorGUIUtility.labelWidth = 0;

            DrawForwardPointOffsetSlider();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            DrawResetEaseButton();
            DrawResetRotationPathButton();
            DrawResetTiltingButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            DrawAutoPlayControl();
            DrawEnableControlsInPlayModeToggle();
            DrawUpdateAllToggle();

            EditorGUILayout.Space();

            DrawPlayerControls();

            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = 0;

            //DrawShortcutsHelpBox();
            EditorGUILayout.Space();

            PathExporter.DrawExportControls();

            DrawAdvancedSettingsFoldout();
            DrawAdvancedSettingsControls();

            // Validate inspector settings.
            // Not all inspector controls can be validated with OnValidate().
            if (GUI.changed) ValidateInspectorSettings();

            // Repaint scene after each inspector update.
            SceneView.RepaintAll();
        }

        private void OnEnable() {
            // Get target script reference.
            Script = (PathAnimator) target;

            if (Script.Settings != null) {
                // Initialize Settings property.
                Settings = Script.Settings;
            }

            InstantiateCompositeClasses();
            InitializeSerializedProperties();

            SceneTool.RememberCurrentTool();
            FocusOnSceneView();
            GizmoIcons.CopyIconsToGizmosFolder();
        }
        private void OnDisable() {
            SceneTool.RestoreTool();
        }

        private void OnSceneGUI() {
            CheckForSkinAsset();

            // Return if path asset does not exist.
            if (Script.PathData == null) return;

            if (Settings == null) return;

            // Disable interaction with background scene elements.
            HandleUtility.AddDefaultControl(
                GUIUtility.GetControlID(
                    FocusType.Passive));

            Shortcuts.HandleShortcuts();

            //Script.UpdateWrapMode();

            HandleDrawingEaseHandles();
            HandleDrawingTiltingHandles();
            HandleDrawingEaseLabel();
            HandleDrawingTiltLabel();
            HandleDrawingUpdateAllModeLabel();
            HandleDrawingPositionHandles();
            HandleDrawingRotationHandle();
            HandleDrawingAddButtons();
            HandleDrawingRemoveButtons();
        }
        #endregion UNITY MESSAGES

        #region INSPECTOR
        private void DrawShortcutsHelpBox() {
            EditorGUILayout.HelpBox(
                "Check Settings Asset for shortcuts.",
                MessageType.Info);
        }

        private void DrawSettingsAssetField() {
            serializedObject.Update();

            EditorGUILayout.PropertyField(
                settings,
                new GUIContent(
                    "Settings Asset",
                    ""));

            serializedObject.ApplyModifiedProperties();
        }

        private void HandleDrawingUpdateAllModeLabel() {
            if (!Settings.UpdateAllMode) return;

            //SceneHandles.DrawNodeLabels(
            //    Script,
            //    "A",
            //    upall
            //    Script.Skin.GetStyle("UpdateAllLabel"));

            SceneHandles.DrawUpdateAllLabels(
                Script,
                Script.Skin.GetStyle("UpdateAllLabel"));
        }


        private void DrawAdvancedSettingsFoldout() {
            serializedObject.Update();

            advancedSettingsFoldout.boolValue = EditorGUILayout.Foldout(
                advancedSettingsFoldout.boolValue,
                new GUIContent(
                    "Advanced Settings",
                    ""));

            serializedObject.ApplyModifiedProperties();
        }

        private void DrawResetRotationPathButton() {
            if (GUILayout.Button(
                            new GUIContent(
                                "Reset Rotation",
                                ""))) {

                if (Script.PathData == null) return;

                Undo.RecordObject(Script.PathData, "Reset rotatio path.");

                // Reset curves to its default state.
                // todo Create direct property for PathData.
                Script.PathData.ResetRotationPath();

                SceneView.RepaintAll();
            }
        }

        private void DrawAdvancedSettingsControls() {
            if (advancedSettingsFoldout.boolValue) {
                DrawGizmoCurveColorPicker();
                DrawRotationCurveColorPicker();

                EditorGUILayout.Space();

                DrawShortJumpValueField();
                DrawLongJumpValueField();

                EditorGUILayout.Space();

                DrawSettingsAssetField();
                DrawSkinSelectionControl();
            }
        }

        private void DrawLongJumpValueField() {
            SettingsSerObj.Update();

            EditorGUILayout.PropertyField(longJumpValue);

            SettingsSerObj.ApplyModifiedProperties();
        }

        private void DrawShortJumpValueField() {
            SettingsSerObj.Update();

            EditorGUILayout.PropertyField(shortJumpValue);

            SettingsSerObj.ApplyModifiedProperties();
        }

        private void DrawAnimatedGOField() {
            serializedObject.Update();
            
            EditorGUILayout.PropertyField(
                animatedGO,
                new GUIContent(
                    "Animated Object",
                    "Object to animate."));

            serializedObject.ApplyModifiedProperties();
        }

        private void DrawAnimationTimeValue() {
            Undo.RecordObject(target, "Update AnimationTime");

            float newTimeRatio = 0;

            newTimeRatio = DrawAnimationTimeSlider();

{'fraction_non_alphanumeric': 0.07351787515409616, 'fraction_numerical': 0.0006724195898240502, 'mean_word_length': 1.7499229583975346, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395018', 'n_tokens_mistral': 4212, 'n_tokens_neox': 3946, 'n_words': 815}