<commit_before>﻿using System.Collections.Generic;
using ATP.SimplePathAnimator.ReorderableList;
using UnityEditor;
using UnityEngine;

namespace ATP.SimplePathAnimator.Events {

    [CustomEditor(typeof (PathEvents))]
    public class PathEventsEditor : Editor {
        #region FIELDS


        #endregion

        #region PROPERTIES

        private SerializedObject EventsDataSerObj { get; set; }

        private PathEvents Script { get; set; }

        private PathEventsSettings PathEventsSettings;

        #endregion

        #region SERIALIZED PROPERTIES

        private SerializedProperty pathAnimator;

        private SerializedProperty drawMethodNames;

        private SerializedProperty nodeEvents;

        private SerializedProperty skin;
        private SerializedProperty settings;
        #endregion

        #region UNITY MESSAGES
        public override void OnInspectorGUI() {
            InitializeNodeEvents();

            serializedObject.Update();

            DrawEventsDataAssetField();

            EditorGUILayout.BeginHorizontal();

            DrawCreateEventsDataAssetButton();
            DrawResetEventsDataInspectorButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(pathAnimator);
            DrawSettingsAssetField();
            EditorGUILayout.PropertyField(skin);

            EditorGUILayout.Space();

            serializedObject.ApplyModifiedProperties();

            DrawEventList();

        }

        private void InitializeNodeEvents() {
            if (Event.current.type != EventType.Layout) return;

            if (Script.EventsData != null && EventsDataSerObj == null) {
                // Initialize SerializedObject EventsDataSerObj.
                EventsDataSerObj = new SerializedObject(Script.EventsData);
                // Iniatilize SerializedProperty nodeEvents.
                nodeEvents = EventsDataSerObj.FindProperty("nodeEvents");
            }
        }

        private void DrawEventList() {
            if (nodeEvents == null) return;

            EventsDataSerObj.Update();

            ReorderableListGUI.Title("Events");
            ReorderableListGUI.ListField(nodeEvents);

            EventsDataSerObj.ApplyModifiedProperties();
        }

        private void OnEnable() {
            Script = (PathEvents) target;
            PathEventsSettings = Script.Settings;

            if (EventsDataSerObj != null) {
                nodeEvents = EventsDataSerObj.FindProperty("nodeEvents");
            }

            pathAnimator = serializedObject.FindProperty("pathAnimator");
            drawMethodNames = serializedObject.FindProperty("drawMethodNames");
            skin = serializedObject.FindProperty("skin");
            settings = serializedObject.FindProperty("settings");
        }

        private void OnSceneGUI() {<commit_msg>Fix null ref. exc. if path data is not assigned<commit_after>﻿using System.Collections.Generic;
using ATP.SimplePathAnimator.ReorderableList;
using UnityEditor;
using UnityEngine;

namespace ATP.SimplePathAnimator.Events {

    [CustomEditor(typeof (PathEvents))]
    public class PathEventsEditor : Editor {
        #region FIELDS


        #endregion

        #region PROPERTIES

        private SerializedObject EventsDataSerObj { get; set; }

        private PathEvents Script { get; set; }

        private PathEventsSettings PathEventsSettings;

        #endregion

        #region SERIALIZED PROPERTIES

        private SerializedProperty pathAnimator;

        private SerializedProperty drawMethodNames;

        private SerializedProperty nodeEvents;

        private SerializedProperty skin;
        private SerializedProperty settings;
        #endregion

        #region UNITY MESSAGES
        public override void OnInspectorGUI() {
            InitializeNodeEvents();

            serializedObject.Update();

            DrawEventsDataAssetField();

            EditorGUILayout.BeginHorizontal();

            DrawCreateEventsDataAssetButton();
            DrawResetEventsDataInspectorButton();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(pathAnimator);
            DrawSettingsAssetField();
            EditorGUILayout.PropertyField(skin);

            EditorGUILayout.Space();

            serializedObject.ApplyModifiedProperties();

            DrawEventList();

        }

        private void InitializeNodeEvents() {
            if (Event.current.type != EventType.Layout) return;

            if (Script.EventsData != null && EventsDataSerObj == null) {
                // Initialize SerializedObject EventsDataSerObj.
                EventsDataSerObj = new SerializedObject(Script.EventsData);
                // Iniatilize SerializedProperty nodeEvents.
                nodeEvents = EventsDataSerObj.FindProperty("nodeEvents");
            }
        }

        private void DrawEventList() {
            if (nodeEvents == null) return;

            EventsDataSerObj.Update();

            ReorderableListGUI.Title("Events");
            ReorderableListGUI.ListField(nodeEvents);

            EventsDataSerObj.ApplyModifiedProperties();
        }

        private void OnEnable() {
            Script = (PathEvents) target;
            PathEventsSettings = Script.Settings;

            if (EventsDataSerObj != null) {
                nodeEvents = EventsDataSerObj.FindProperty("nodeEvents");
            }

            pathAnimator = serializedObject.FindProperty("pathAnimator");
            drawMethodNames = serializedObject.FindProperty("drawMethodNames");
            skin = serializedObject.FindProperty("skin");
            settings = serializedObject.FindProperty("settings");
        }

        private void OnSceneGUI() {
            // Return if path data is not assigned to the PathAnimator component.
            if (Script.PathAnimator.PathData == null) return;
{'fraction_non_alphanumeric': 0.0758183032732131, 'fraction_numerical': 0.0, 'mean_word_length': 2.2906593406593405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5698860', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1353, 'n_words': 290}