Skip to content

Commit

Permalink
✨ 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jun 3, 2024
1 parent ec7ad5d commit ec0f67c
Show file tree
Hide file tree
Showing 19 changed files with 4,049 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ _pkginfo.txt
[Bb]uild[Ll]og.*
_ReSharper*/

*.*.*-[Pp]review/
*.*.*/
.git/
.vs/
.idea/
Expand Down
173 changes: 173 additions & 0 deletions Editor.GUI.CLI/External/AIO.Unity.Print/UnityConsoleEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#region

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using UnityEditor;

#endregion

namespace AIO.UEditor
{
[DebuggerNonUserCode, IgnoreConsoleJump, Description("Unity Console Editor : 日志输出开关")]
internal static class UnityConsoleEditor
{
/// <summary>
/// 输出日志
/// </summary>
private const string MENU_DEVELOPER_MODE = "AIO/Debug/Developer Mode";

/// <summary>
/// 错误日志
/// </summary>
private const string MENU_EDITOR_SWITCH_LOG = "AIO/Debug/Console Log";

/// <summary>
/// 开发者模式
/// </summary>
private const string MENU_EDITOR_SWITCH_ERROR = "AIO/Debug/Console Error";

private static MethodInfo EnabledError;
private static MethodInfo DisableError;

private static MethodInfo EnabledLog;
private static MethodInfo DisableLog;
private static bool IS_EDITOR_SWITCH_LOG => EditorPrefs.GetInt(MENU_EDITOR_SWITCH_LOG, 1) == 1;
private static bool IS_EDITOR_SWITCH_ERROR => EditorPrefs.GetInt(MENU_EDITOR_SWITCH_ERROR, -1) == 1;
private static bool IS_DEVELOPER_MODE => EditorPrefs.GetInt(MENU_DEVELOPER_MODE, -1) == 1;

[LnkTools(
Tooltip = "支持读取 Console.WriteLine 日志",
IconResource = "Editor/Icon/Color/-message")]
private static bool EditorSwitchLog()
{
EditorSwitchLOG();
return IS_EDITOR_SWITCH_LOG;
}

[MenuItem(MENU_EDITOR_SWITCH_LOG)]
private static void EditorSwitchLOG()
{
EditorPrefs.SetInt(MENU_EDITOR_SWITCH_LOG, !IS_EDITOR_SWITCH_LOG ? 1 : -1);
Initialize();
var refreshSettingsMethodInfo = typeof(AssetDatabase).GetMethod("RefreshSettings",
BindingFlags.Static | BindingFlags.Public);
if (refreshSettingsMethodInfo == null) AssetDatabase.Refresh();
else refreshSettingsMethodInfo.Invoke(null, null);
}

[MenuItem(MENU_EDITOR_SWITCH_ERROR)]
private static void EditorSwitchERROR()
{
EditorPrefs.SetInt(MENU_EDITOR_SWITCH_ERROR, !IS_EDITOR_SWITCH_ERROR ? 1 : -1);
Initialize();
var refreshSettingsMethodInfo = typeof(AssetDatabase).GetMethod("RefreshSettings",
BindingFlags.Static | BindingFlags.Public);
if (refreshSettingsMethodInfo == null) AssetDatabase.Refresh();
else refreshSettingsMethodInfo.Invoke(null, null);
}

private static void MenuRefresh()
{
if (Menu.GetChecked(MENU_EDITOR_SWITCH_ERROR))
Menu.SetChecked(MENU_EDITOR_SWITCH_ERROR, IS_EDITOR_SWITCH_ERROR);

if (Menu.GetChecked(MENU_EDITOR_SWITCH_LOG))
Menu.SetChecked(MENU_EDITOR_SWITCH_LOG, IS_EDITOR_SWITCH_LOG);

if (Menu.GetChecked(MENU_DEVELOPER_MODE))
Menu.SetChecked(MENU_DEVELOPER_MODE, IS_DEVELOPER_MODE);
}

[IgnoreConsoleJump]
private static void ErrorEnabled()
{
if (EnabledError is null)
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.GetName().Name.StartsWith("AIO.Print.Unity")) continue;
var type = assembly.GetType("UnityEngine.UnityConsole");
if (type is null) continue;
EnabledError = type.GetMethod(nameof(EnabledError),
BindingFlags.Static | BindingFlags.NonPublic);
if (EnabledError != null) break;
}

EnabledError?.Invoke(null, null);
}

[IgnoreConsoleJump]
private static void ErrorDisabled()
{
if (DisableError is null)
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.GetName().Name.StartsWith("AIO.Print.Unity")) continue;
var type = assembly.GetType("UnityEngine.UnityConsole");
if (type is null) continue;
DisableError = type.GetMethod(nameof(DisableError),
BindingFlags.Static | BindingFlags.NonPublic);
if (DisableError != null) break;
}

DisableError?.Invoke(null, null);
}


[IgnoreConsoleJump]
private static void LogEnabled()
{
if (EnabledLog is null)
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.GetName().Name.StartsWith("AIO.Print.Unity")) continue;
var type = assembly.GetType("UnityEngine.UnityConsole");
if (type is null) continue;
EnabledLog = type.GetMethod(nameof(EnabledLog),
BindingFlags.Static | BindingFlags.NonPublic);
if (EnabledLog != null) break;
}

EnabledLog?.Invoke(null, null);
}

[IgnoreConsoleJump]
private static void LogDisabled()
{
if (DisableLog is null)
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.GetName().Name.StartsWith("AIO.Print.Unity")) continue;
var type = assembly.GetType("UnityEngine.UnityConsole");
if (type is null) continue;
DisableLog = type.GetMethod(nameof(DisableLog),
BindingFlags.Static | BindingFlags.NonPublic);
if (DisableLog != null) break;
}

DisableLog?.Invoke(null, null);
}

[AInit(EInitAttrMode.Both, int.MinValue)]
private static void Initialize()
{
if (IS_EDITOR_SWITCH_ERROR) ErrorEnabled();
else ErrorDisabled();
if (IS_EDITOR_SWITCH_LOG) LogEnabled();
else LogDisabled();
MenuRefresh();
}

/// <summary>
/// 打开开发者模式
/// </summary>
[MenuItem(MENU_DEVELOPER_MODE, false, 0)]
private static void OpenDeveloperMode()
{
EditorPrefs.SetBool("DeveloperMode", !IS_DEVELOPER_MODE);
EditorPrefs.SetInt(MENU_DEVELOPER_MODE, !IS_DEVELOPER_MODE ? 1 : -1);
MenuRefresh();
}
}
}

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
@@ -0,0 +1,119 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace AIO.RainbowCore.RList.Editor
{
[CustomPropertyDrawer(typeof(ReorderableAttribute))]
internal class ReorderableDrawer : PropertyDrawer
{
private struct SurrogateCallback
{
private string property;

internal SurrogateCallback(string property)
{
this.property = property;
}

internal void SetReference(SerializedProperty element, Object objectReference, ReorderableList list)
{
SerializedProperty serializedProperty = ((!string.IsNullOrEmpty(property)) ? element.FindPropertyRelative(property) : null);
if (serializedProperty != null && serializedProperty.propertyType == SerializedPropertyType.ObjectReference)
{
serializedProperty.objectReferenceValue = objectReference;
}
}
}

public const string ARRAY_PROPERTY_NAME = "array";

private static Dictionary<int, ReorderableList> lists = new Dictionary<int, ReorderableList>();

public override bool CanCacheInspectorGUI(SerializedProperty property)
{
return false;
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return GetList(property, attribute as ReorderableAttribute, "array")?.GetHeight() ?? EditorGUIUtility.singleLineHeight;
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
ReorderableList list = GetList(property, attribute as ReorderableAttribute, "array");
if (list != null)
{
list.DoList(EditorGUI.IndentedRect(position), label);
}
else
{
GUI.Label(position, "Array must extend from ReorderableArray", EditorStyles.label);
}
}

public static int GetListId(SerializedProperty property)
{
if (property == null) return 0;
var hashCode = property.serializedObject.targetObject.GetHashCode();
var hashCode2 = property.propertyPath.GetHashCode();
return ((hashCode << 5) + hashCode) ^ hashCode2;
}

public static ReorderableList GetList(SerializedProperty property, string arrayPropertyName)
{
return GetList(property, null, GetListId(property), arrayPropertyName);
}

public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, string arrayPropertyName)
{
return GetList(property, attrib, GetListId(property), arrayPropertyName);
}

public static ReorderableList GetList(SerializedProperty property, int id, string arrayPropertyName)
{
return GetList(property, null, id, arrayPropertyName);
}

public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, int id, string arrayPropertyName)
{
if (property == null)
{
return null;
}
ReorderableList value = null;
SerializedProperty serializedProperty = property.FindPropertyRelative(arrayPropertyName);
if (serializedProperty != null && serializedProperty.isArray)
{
if (!lists.TryGetValue(id, out value))
{
if (attrib != null)
{
Texture elementIcon = ((!string.IsNullOrEmpty(attrib.elementIconPath)) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null);
ReorderableList.ElementDisplayType elementDisplayType = (attrib.singleLine ? ReorderableList.ElementDisplayType.SingleLine : ReorderableList.ElementDisplayType.Auto);
value = new ReorderableList(serializedProperty, attrib.add, attrib.remove, attrib.draggable, elementDisplayType, attrib.elementNameProperty, attrib.elementNameOverride, elementIcon);
value.paginate = attrib.paginate;
value.pageSize = attrib.pageSize;
value.sortable = attrib.sortable;
if (attrib.surrogateType != null)
{
SurrogateCallback surrogateCallback = new SurrogateCallback(attrib.surrogateProperty);
value.surrogate = new ReorderableList.Surrogate(attrib.surrogateType, surrogateCallback.SetReference);
}
}
else
{
value = new ReorderableList(serializedProperty, canAdd: true, canRemove: true, draggable: true);
}
lists.Add(id, value);
}
else
{
value.List = serializedProperty;
}
}
return value;
}
}
}

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

Loading

0 comments on commit ec0f67c

Please sign in to comment.