Skip to content

Commit

Permalink
Implemented OpenEditorLog
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertoalexsantos committed Apr 5, 2018
1 parent 6061d50 commit d123ab1
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;


namespace BluConsole.Core.UnityLoggerApi
{

public static class BluInternalEditorUtility
{

public static void OpenEditorConsole()
{
var method = GetMethod("OpenEditorConsole");
method.Invoke(null, null);
}

public static void OpenPlayerConsole()
{
var method = GetMethod("OpenPlayerConsole");
method.Invoke(null, null);
}

private static MethodInfo GetMethod(string key)
{
return ReflectionCache.GetMethod(key, UnityClassType.InternalEditorUtility);
}

}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ namespace BluConsole.Core.UnityLoggerApi

public enum UnityClassType
{
ConsoleWindow = 0,
LogEntries = 1,
LogEntry = 2,
ConsoleWindow = 0,
LogEntries = 1,
LogEntry = 2,
InternalEditorUtility = 3,
}

public static class ReflectionCache
{

private static Dictionary<UnityClassType, string> _cacheStrUnityClassType = new Dictionary<UnityClassType, string>()
{
{ UnityClassType.ConsoleWindow, "0" },
{ UnityClassType.LogEntries, "1" },
{ UnityClassType.LogEntry, "2" },
{ UnityClassType.ConsoleWindow, "0" },
{ UnityClassType.LogEntries, "1" },
{ UnityClassType.LogEntry, "2" },
{ UnityClassType.InternalEditorUtility, "3" },
};

private static Dictionary<Type, string> _cacheStrType = new Dictionary<Type, string>()
Expand All @@ -36,15 +38,15 @@ public static MethodInfo GetMethod(string key, UnityClassType type)
{
var cacheKey = GetKey<MethodInfo>(key, type);
if (!Has(cacheKey))
_cache[cacheKey] = GetType(type).GetMethod(key, GetFlags(type));
_cache[cacheKey] = GetType(type).GetMethod(key, Flags);
return (MethodInfo)_cache[cacheKey];
}

public static PropertyInfo GetProperty(string key, UnityClassType type)
{
var cacheKey = GetKey<PropertyInfo>(key, type);
if (!Has(cacheKey))
_cache[cacheKey] = GetType(type).GetProperty(key, GetFlags(type));
_cache[cacheKey] = GetType(type).GetProperty(key, Flags);
return (PropertyInfo)_cache[cacheKey];
}

Expand Down Expand Up @@ -85,6 +87,8 @@ private static Type GetTypeFromAssembly(UnityClassType type)
return Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
case UnityClassType.LogEntry:
return Type.GetType("UnityEditor.LogEntry,UnityEditor.dll");
case UnityClassType.InternalEditorUtility:
return Type.GetType("UnityEditorInternal.InternalEditorUtility,UnityEditor.dll");
default:
return default(Type);
}
Expand All @@ -97,24 +101,23 @@ private static Type GetTypeFromAssembly(UnityClassType type)
return Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
case UnityClassType.LogEntry:
return Type.GetType("UnityEditorInternal.LogEntry,UnityEditor.dll");
case UnityClassType.InternalEditorUtility:
return Type.GetType("UnityEditorInternal.InternalEditorUtility,UnityEditor.dll");
default:
return default(Type);
}
#endif
}

private static BindingFlags GetFlags(UnityClassType type)
private static BindingFlags Flags
{
switch (type)
get
{
case UnityClassType.ConsoleWindow:
return BindingFlags.Static | BindingFlags.NonPublic;
case UnityClassType.LogEntries:
return BindingFlags.Static | BindingFlags.Public;
case UnityClassType.LogEntry:
return BindingFlags.Default;
default:
return BindingFlags.Default;
return BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Static |
BindingFlags.Instance |
BindingFlags.Default;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
namespace BluConsole.Core.UnityLoggerApi
using UnityEngine;


namespace BluConsole.Core.UnityLoggerApi
{

public static class UnityLoggerServer
{

public static bool ShouldShowPlayerConsole
{
get
{
return Application.platform == RuntimePlatform.OSXEditor;
}
}

public static void OpenEditorConsole()
{
BluInternalEditorUtility.OpenEditorConsole();
}

public static void OpenPlayerConsole()
{
if (!ShouldShowPlayerConsole)
return;

BluInternalEditorUtility.OpenPlayerConsole();
}

public static void Clear()
{
LogEntries.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BluConsole.Editor

public class BluConsoleEditorWindow : EditorWindow, IHasCustomMenu
{

#region Variables

public static BluConsoleEditorWindow Instance;
Expand All @@ -38,11 +38,11 @@ public class BluConsoleEditorWindow : EditorWindow, IHasCustomMenu
private BluDetailWindow _detailWindow;
private BluToolbarWindow _toolbarWindow;

#endregion Variables
#endregion Variables



#region Windows

[MenuItem("Window/BluConsole")]
public static void ShowWindow()
{
Expand All @@ -56,10 +56,10 @@ public static void ShowWindow()

window._topPanelHeight = window.position.height / 2.0f;
}

#endregion Windows


#region OnEvents

private void OnEnable()
Expand Down Expand Up @@ -88,7 +88,7 @@ private void OnDestroy()
}

private void OnGUI()
{
{
InitVariables();
CalculateResizer();

Expand All @@ -107,8 +107,8 @@ private void OnGUI()
}

public void OnBeforeCompile()
{
SetDirtyLogs();
{
SetDirtyLogs();
}

public void OnAfterCompile()
Expand All @@ -127,28 +127,31 @@ public void OnStopPlay()
{
SetDirtyLogs();
}

#endregion OnEvents


#region IHasCustomMenu

public void AddItemsToMenu(GenericMenu menu)
{
if (UnityLoggerServer.ShouldShowPlayerConsole)
menu.AddItem(new GUIContent("Open Player Log"), false, UnityLoggerServer.OpenPlayerConsole);
menu.AddItem(new GUIContent("Open Editor Log"), false, UnityLoggerServer.OpenEditorConsole);
menu.AddItem(new GUIContent("Add Filter"), false, OnAddFilterTabClicked);
}

private void OnAddFilterTabClicked()
{
if (_settings == null)
return;

Selection.activeObject = _settings;
}

#endregion IHasCustomMenu


#region Draw

private float DrawToolbarWindow(int id)
Expand All @@ -165,7 +168,7 @@ private float DrawToolbarWindow(int id)
GUI.Window(id, new Rect(0, 0, position.width, height), _toolbarWindow.OnGUI, GUIContent.none, GUIStyle.none);

return height;
}
}

private float DrawListWindow(int id)
{
Expand Down Expand Up @@ -204,7 +207,7 @@ private float DrawResizer()
{
if (Event.current.type != EventType.Repaint)
return _configuration.ResizerHeight;

var rect = new Rect(0, _drawYPos, position.width, _configuration.ResizerHeight);
EditorGUI.DrawRect(rect, _configuration.ResizerColor);

Expand All @@ -213,7 +216,7 @@ private float DrawResizer()

#endregion Draw


#region Gets

private int[] GetCachedIntArr(int size)
Expand Down Expand Up @@ -255,7 +258,7 @@ private bool IsClicked(Rect rect)
{
return Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition);
}

private bool ShouldLog(BluLog log, int row)
{
var messageLower = log.MessageLower;
Expand Down Expand Up @@ -285,10 +288,10 @@ private bool ShouldLog(BluLog log, int row)
}

#endregion Gets


#region Sets

private void SetDirtyComparer()
{
_cacheLogComparer.Clear();
Expand All @@ -302,10 +305,10 @@ private void SetDirtyLogs()
_cacheLogArr = new BluLog[50];
SetDirtyComparer();
}

#endregion Sets


#region Actions

private void CheckDirties()
Expand Down Expand Up @@ -335,8 +338,8 @@ private void CalculateResizer()
_cursorChangeRect.Set(_cursorChangeRect.x, resizerY, _cursorChangeRect.width, _cursorChangeRect.height);
}

_topPanelHeight = Mathf.Clamp(_topPanelHeight,
_configuration.MinHeightOfTopAndBotton,
_topPanelHeight = Mathf.Clamp(_topPanelHeight,
_configuration.MinHeightOfTopAndBotton,
position.height - _configuration.MinHeightOfTopAndBotton);
}

Expand Down Expand Up @@ -369,15 +372,15 @@ private void PreProcessLogs()
int cacheLogComparerCount = _cacheLogComparer.Count;
for (int i = 0; i < _qtLogs; i++)
{
// Ugly code to avoid function call
// Ugly code to avoid function call
int realCount = _cacheLog.Count;
BluLog log = null;
if (i < _cacheLogCount && i < realCount)
log = _cacheLog[i];
else
log = GetSimpleLog(i);

// Ugly code to avoid function call
// Ugly code to avoid function call
bool has = false;
if (i < cacheLogComparerCount)
has = _cacheLogComparer[i];
Expand Down

0 comments on commit d123ab1

Please sign in to comment.