Skip to content

Commit

Permalink
Merge branch 'feature/5' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejwolk committed Apr 28, 2015
2 parents 0dd258c + 2723b10 commit 589468d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
33 changes: 26 additions & 7 deletions Editor/LoggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class LoggerEditor : Editor {
}

public override void OnInspectorGUI() {
base.OnInspectorGUI();
// todo create Script property
Logger script = (Logger)target;

Expand All @@ -77,7 +76,9 @@ public class LoggerEditor : Editor {

EditorGUILayout.Space();

// todo remove param.
DrawEnabledMethodsDropdown(script);
// todo remove param.
DrawAppendDropdown(script);

EditorGUILayout.Space();
Expand All @@ -90,20 +91,26 @@ public class LoggerEditor : Editor {
ReorderableListGUI.Title("Method Filter");
ReorderableListGUI.ListField(methodFilter);

DrawStartStopButton(script);
// todo remove param.
HandleDrawingStartStopButton(script);

// Save changes
serializedObject.ApplyModifiedProperties();
}
#endregion
#region INSPECTOR

private void DrawStartStopButton(Logger script) {
private void HandleDrawingStartStopButton(Logger script) {
// todo add button to continue logging after pause
// todo extract what's inside to DrawDrawStartStopButton()
if (loggingEnabled.boolValue == false) {
if (GUILayout.Button("Start Logging")) {
loggingEnabled.boolValue = true;
loggingEnabled.boolValue = GUILayout.Toggle(
loggingEnabled.boolValue,
"Start Logging",
"Button");

// If value was changed..
if (loggingEnabled.boolValue != script.LoggingEnabled) {
// Fire event.
Utilities.InvokeMethodWithReflection(
script,
Expand All @@ -112,7 +119,13 @@ public class LoggerEditor : Editor {
}
}
else if (Application.isPlaying && enableOnPlay.boolValue) {
if (GUILayout.Button("Pause Logging")) {
loggingEnabled.boolValue = GUILayout.Toggle(
loggingEnabled.boolValue,
"Pause Logging",
"Button");

// If value was changed..
if (loggingEnabled.boolValue != script.LoggingEnabled) {
loggingEnabled.boolValue = false;
script.LogCache.Add("[PAUSE]", true);

Expand All @@ -124,7 +137,13 @@ public class LoggerEditor : Editor {
}
}
else {
if (GUILayout.Button("Stop Logging")) {
loggingEnabled.boolValue = GUILayout.Toggle(
loggingEnabled.boolValue,
"Stop Logging",
"Button");

// If value was changed..
if (loggingEnabled.boolValue != script.LoggingEnabled) {
loggingEnabled.boolValue = false;
script.LogCache.WriteAll(script.FilePath, false);

Expand Down
55 changes: 32 additions & 23 deletions Editor/LoggerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,61 @@ public class LoggerWindow : EditorWindow {
window.minSize = new Vector2(100f, 60f);
}

private void OnEnable() {
Logger.StateChanged += Logger_StateChanged;
}

private void OnDisable() {
Logger.StateChanged -= Logger_StateChanged;
}

void Logger_StateChanged(object sender, EventArgs e) {
Repaint();
}

private void OnGUI() {
EditorGUILayout.BeginHorizontal();
if (!LoggerInstance.LoggingEnabled) {
if (GUILayout.Button("Start Logging")) {
LoggerInstance.LoggingEnabled = true;
}
// todo extract to DrawStartStopToggle()
LoggerInstance.LoggingEnabled = GUILayout.Toggle(
LoggerInstance.LoggingEnabled,
"Start Logging",
"Button");

}
else if (Application.isPlaying && LoggerInstance.EnableOnPlay) {
if (GUILayout.Button("Pause Logging")) {
LoggerInstance.LoggingEnabled = false;
else if (Application.isPlaying
&& LoggerInstance.EnableOnPlay
&& LoggerInstance.LoggingEnabled) {

LoggerInstance.LoggingEnabled = GUILayout.Toggle(
LoggerInstance.LoggingEnabled,
"Pause Logging",
"Button");

if (!LoggerInstance.LoggingEnabled) {
LoggerInstance.LogCache.Add("[PAUSE]", true);
}
}
else if (Application.isPlaying
&& LoggerInstance.EnableOnPlay
&& !LoggerInstance.LoggingEnabled) {

if (GUILayout.Button("Continue Logging")) {
LoggerInstance.LoggingEnabled = true;
}
LoggerInstance.LoggingEnabled = GUILayout.Toggle(
LoggerInstance.LoggingEnabled,
"Continue Logging",
"Button");

}
else {
if (GUILayout.Button("Stop Logging")) {
LoggerInstance.LoggingEnabled = false;
LoggerInstance.LoggingEnabled = GUILayout.Toggle(
LoggerInstance.LoggingEnabled,
"Stop Logging",
"Button");

if (!LoggerInstance.LoggingEnabled) {
LoggerInstance.LogCache.WriteAll(
LoggerInstance.FilePath,
false);
}

}

if (GUILayout.Button("->", GUILayout.Width(30))) {
EditorGUIUtility.PingObject(LoggerInstance);
Selection.activeGameObject = LoggerInstance.gameObject;
}

EditorGUILayout.EndHorizontal();

Repaint();
}
}
}
3 changes: 3 additions & 0 deletions Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public enum EnabledMethods {
public sealed class Logger : MonoBehaviour {

#region EVENTS
/// <summary>
/// Event called when logger is started, stopped, paused or reasumed.
/// </summary>
public static event EventHandler StateChanged;
#endregion

Expand Down

0 comments on commit 589468d

Please sign in to comment.