Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'save as', 'load from' and 'clear' functionalities #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Editor/CompilationAnalysis.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
Expand Down Expand Up @@ -229,7 +230,36 @@ public static void WriteAll(IterativeCompilationData data) {
var json = JsonUtility.ToJson(data, true);
EditorPrefs.SetString(EditorPrefStore, json);
}

public static void SaveToFile()
{
var json = EditorPrefs.GetString(EditorPrefStore);
var path = EditorUtility.SaveFilePanel(
"Save data as JSON",
"",
"CompilationData.json",
"json");
if (path.Length != 0)
{
File.WriteAllText(path, json);
}
}
public static void LoadFromFile()
{
var path = EditorUtility.OpenFilePanel(
"Load data from JSON file",
"",
"json");
if (path.Length == 0) return;
try
{
tempData = JsonUtility.FromJson<IterativeCompilationData>(File.ReadAllText(path));
WriteAll(tempData);
}
catch (Exception ex)
{
Debug.LogError($"Error loading data {ex}");
}
}
public void OnBeforeSerialize()
{
compilationStarted = CompilationStarted;
Expand All @@ -252,6 +282,12 @@ public static void Clear()
tempData = new IterativeCompilationData();
}

public static void ResetData()
{
tempData = new IterativeCompilationData();
WriteAll(tempData);
}

public static void Add()
{
tempData.iterations.Add(new CompilationData());
Expand Down
11 changes: 11 additions & 0 deletions Editor/CompilationTimelineWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ private void OnGUI()
compactDrawing = GUILayout.Toggle(compactDrawing, "Compact", EditorStyles.toolbarButton);
AllowLogging = GUILayout.Toggle(AllowLogging, new GUIContent("Logging", "Log additional compilation data to the console on compilation"), EditorStyles.toolbarButton);
ShowAssemblyReloads = GUILayout.Toggle(ShowAssemblyReloads, new GUIContent("Show Reloads", "Show or hide assembly reloads in the timeline."), EditorStyles.toolbarButton);
if (GUILayout.Button(new GUIContent(UnityEditor.EditorGUIUtility.FindTexture("SaveAs"), "Save current data to a JSON file"), EditorStyles.toolbarButton)) CompilationData.SaveToFile();
if (GUILayout.Button(new GUIContent(UnityEditor.EditorGUIUtility.FindTexture("Profiler.Open"), "Load data from a JSON file"), EditorStyles.toolbarButton))
{
CompilationData.LoadFromFile();
Clear();
}
if (GUILayout.Button(new GUIContent("Clear", "Clear the captured data"), EditorStyles.toolbarButton))
{
CompilationData.ResetData();
Clear();
}
colorMode = (ColorMode) EditorGUILayout.EnumPopup(colorMode, GUILayout.ExpandWidth(false));

var totalSpan = TimeSpan.Zero;
Expand Down