Skip to content

Commit

Permalink
删除了没用的一些测试数据
Browse files Browse the repository at this point in the history
  • Loading branch information
qq362946 committed Sep 24, 2024
1 parent 01895aa commit 0303deb
Show file tree
Hide file tree
Showing 58 changed files with 796 additions and 1,351 deletions.
1 change: 1 addition & 0 deletions Fantasy.Net/Fantasy.Net/Runtime/Core/Helper/FileHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace Fantasy.Helper
{
Expand Down
4 changes: 3 additions & 1 deletion Fantasy.Net/Fantasy.Net/Runtime/Core/Log/ConsoleLog.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if FANTASY_NET
using Fantasy.Platform.Net;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

Expand Down Expand Up @@ -139,4 +140,5 @@ public void Fatal(string message, params object[] args)
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message, args);
}
}
}
#endif
5 changes: 4 additions & 1 deletion Fantasy.Net/Fantasy.Net/Runtime/Core/Log/ILog.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#if FANTASY_NET
using Fantasy.Platform.Net;

#endif
namespace Fantasy
{
/// <summary>
/// 定义日志记录功能的接口。
/// </summary>
public interface ILog
{
#if FANTASY_NET
/// <summary>
/// 初始化
/// </summary>
/// <param name="processMode"></param>
void Initialize(ProcessMode processMode);
#endif
/// <summary>
/// 记录跟踪级别的日志消息。
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions Fantasy.Net/Fantasy.Net/Runtime/Core/Log/Log.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
#if FANTASY_NET
using Fantasy.Platform.Net;
#endif

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

Expand All @@ -12,8 +14,8 @@ namespace Fantasy
public static class Log
{
private static ILog _logCore;
#if FANTASY_NET
private static bool _isRegister;

/// <summary>
/// 初始化Log系统
/// </summary>
Expand Down Expand Up @@ -43,15 +45,17 @@ public static void Initialize()

_logCore.Initialize(processMode);
}

#endif
/// <summary>
/// 注册一个日志系统
/// </summary>
/// <param name="log"></param>
public static void Register(ILog log)
{
_logCore = log;
#if FANTASY_NET
_isRegister = true;
#endif
}

/// <summary>
Expand Down
182 changes: 182 additions & 0 deletions Fantasy.Net/Fantasy.Net/Runtime/Core/Log/UnityLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#if UNITY_EDITOR
using System;
using System.Reflection;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditorInternal;
#else
using System;
#endif

#if FANTASY_UNITY
namespace Fantasy
{
public class UnityLog : ILog
{
public void Trace(string msg)
{
UnityEngine.Debug.Log(msg);
}

public void Debug(string msg)
{
UnityEngine.Debug.Log(msg);
}

public void Info(string msg)
{
UnityEngine.Debug.Log(msg);
}

public void Warning(string msg)
{
UnityEngine.Debug.LogWarning(msg);
}

public void Error(string msg)
{
UnityEngine.Debug.LogError(msg);
}

public void Error(Exception e)
{
UnityEngine.Debug.LogException(e);
}

public void Trace(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public void Warning(string message, params object[] args)
{
UnityEngine.Debug.LogWarningFormat(message, args);
}

public void Info(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public void Debug(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public void Error(string message, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(message, args);
}
}
}
#endif

#if UNITY_EDITOR
namespace Fantasy
{
/// <summary>
/// 日志重定向相关的实用函数。
/// </summary>
internal static class LogRedirection
{
[OnOpenAsset(0)]
private static bool OnOpenAsset(int instanceID, int line)
{
if (line <= 0)
{
return false;
}

// 获取资源路径
string assetPath = AssetDatabase.GetAssetPath(instanceID);

// 判断资源类型
if (!assetPath.EndsWith(".cs"))
{
return false;
}

bool autoFirstMatch = assetPath.Contains("Log.cs") ||
assetPath.Contains("UnityLog.cs");

var stackTrace = GetStackTrace();
if (!string.IsNullOrEmpty(stackTrace))

{
if (!autoFirstMatch)
{
var fullPath = UnityEngine.Application.dataPath.Substring(0, UnityEngine.Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
fullPath = $"{fullPath}{assetPath}";
// 跳转到目标代码的特定行
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
return true;
}

// 使用正则表达式匹配at的哪个脚本的哪一行
var matches = Regex.Match(stackTrace, @"\(at (.+)\)",
RegexOptions.IgnoreCase);
while (matches.Success)
{
var pathLine = matches.Groups[1].Value;

if (!pathLine.Contains("Log.cs") &&
!pathLine.Contains("UnityLog.cs"))
{
var splitIndex = pathLine.LastIndexOf(":", StringComparison.Ordinal);
// 脚本路径
var path = pathLine.Substring(0, splitIndex);
// 行号
line = Convert.ToInt32(pathLine.Substring(splitIndex + 1));
var fullPath = UnityEngine.Application.dataPath.Substring(0, UnityEngine.Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
fullPath = $"{fullPath}{path}";
// 跳转到目标代码的特定行
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
break;
}

matches = matches.NextMatch();
}

return true;
}

return false;
}

/// <summary>
/// 获取当前日志窗口选中的日志的堆栈信息。
/// </summary>
/// <returns>选中日志的堆栈信息实例。</returns>
private static string GetStackTrace()
{
// 通过反射获取ConsoleWindow类
var consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
// 获取窗口实例
var fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow",
BindingFlags.Static |
BindingFlags.NonPublic);
if (fieldInfo != null)
{
var consoleInstance = fieldInfo.GetValue(null);
if (consoleInstance != null)
if (EditorWindow.focusedWindow == (EditorWindow)consoleInstance)
{
// 获取m_ActiveText成员
fieldInfo = consoleWindowType.GetField("m_ActiveText",
BindingFlags.Instance |
BindingFlags.NonPublic);
// 获取m_ActiveText的值
if (fieldInfo != null)
{
var activeText = fieldInfo.GetValue(consoleInstance).ToString();
return activeText;
}
}
}

return null;
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private async FTask RepeatedSend()
Ping = (int)(responseTime - requestTime) / 2;
TimeHelper.TimeDiff = pingResponse.Now + Ping - responseTime;
}
catch (Exception e)
catch (Exception)
{
Dispose();
}
Expand Down

This file was deleted.

Loading

0 comments on commit 0303deb

Please sign in to comment.