[Add] FishNet

This commit is contained in:
2026-03-30 20:11:57 +07:00
parent ee793a3361
commit c22c08753a
1797 changed files with 197950 additions and 1 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 980bce33e6d8c5247bedb2ddc2310b77
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
#if UNITY_EDITOR
using GameKit.Dependencies.Utilities;
using UnityEditor;
namespace FishNet.Managing.Logging.Editing
{
[CustomEditor(typeof(LevelLoggingConfiguration), true)]
[CanEditMultipleObjects]
public class LevelLoggingConfigurationEditor : Editor
{
private SerializedProperty _isEnabled;
private SerializedProperty _addLocalTick;
private SerializedProperty _addTimestamps;
private SerializedProperty _enableTimestampsInEditor;
private SerializedProperty _developmentLogging;
private SerializedProperty _guiLogging;
private SerializedProperty _headlessLogging;
protected virtual void OnEnable()
{
_isEnabled = serializedObject.FindProperty(nameof(_isEnabled).MemberToPascalCase());
_addLocalTick = serializedObject.FindProperty(nameof(_addLocalTick));
_addTimestamps = serializedObject.FindProperty(nameof(_addTimestamps));
_enableTimestampsInEditor = serializedObject.FindProperty(nameof(_enableTimestampsInEditor));
_developmentLogging = serializedObject.FindProperty(nameof(_developmentLogging));
_guiLogging = serializedObject.FindProperty(nameof(_guiLogging));
_headlessLogging = serializedObject.FindProperty(nameof(_headlessLogging));
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(_isEnabled);
if (_isEnabled.boolValue == false)
return;
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_addLocalTick);
EditorGUILayout.PropertyField(_addTimestamps);
if (_addTimestamps.boolValue == true)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_enableTimestampsInEditor);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(_developmentLogging);
EditorGUILayout.PropertyField(_guiLogging);
EditorGUILayout.PropertyField(_headlessLogging);
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();
}
}
}
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b815d3a75a4bcc54b907a07e83c7b7cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
assetPath: Assets/FishNet/Runtime/Managing/Logging/Editor/LevelLoggingConfigurationEditor.cs
uploadId: 866910
@@ -0,0 +1,194 @@
#if UNITY_EDITOR || DEVELOPMENT_BUILD
#define DEVELOPMENT
#endif
using FishNet.Documenting;
using System;
using System.Runtime.CompilerServices;
using System.Text;
using FishNet.Managing.Timing;
using UnityEngine;
namespace FishNet.Managing.Logging
{
/// <summary>
/// Configuration ScriptableObject specifying which data to log. Used in conjuction with NetworkManager.
/// </summary>
[CreateAssetMenu(fileName = "New LevelLoggingConfiguration", menuName = "FishNet/Logging/Level Logging Configuration")]
public class LevelLoggingConfiguration : LoggingConfiguration
{
#region Serialized.
/// <summary>
/// True to add localtick to logs.
/// </summary>
[Tooltip("True to add localtick to logs.")]
[SerializeField]
private bool _addLocalTick;
/// <summary>
/// True to add timestamps to logs.
/// </summary>
[Tooltip("True to add timestamps to logs.")]
[SerializeField]
private bool _addTimestamps = true;
/// <summary>
/// True to add timestamps when in editor. False to only include timestamps in builds.
/// </summary>
[Tooltip("True to add timestamps when in editor. False to only include timestamps in builds.")]
[SerializeField]
private bool _enableTimestampsInEditor;
/// <summary>
/// Type of logging to use for development builds and editor.
/// </summary>
[Tooltip("Type of logging to use for development builds and editor.")]
[SerializeField]
private LoggingType _developmentLogging = LoggingType.Common;
/// <summary>
/// Type of logging to use for GUI builds.
/// </summary>
[Tooltip("Type of logging to use for GUI builds.")]
[SerializeField]
private LoggingType _guiLogging = LoggingType.Warning;
/// <summary>
/// Type of logging to use for headless builds.
/// </summary>
[Tooltip("Type of logging to use for headless builds.")]
[SerializeField]
private LoggingType _headlessLogging = LoggingType.Error;
#endregion
#region Private.
/// <summary>
/// True when initialized.
/// </summary>
private bool _initialized;
/// <summary>
/// Highest type which can be logged.
/// </summary>
private LoggingType _highestLoggingType = LoggingType.Off;
/// <summary>
/// Sequential stringbuilder for performance.
/// </summary>
private static StringBuilder _stringBuilder = new();
#endregion
[APIExclude]
public void LoggingConstructor(bool loggingEnabled, LoggingType development, LoggingType gui, LoggingType headless)
{
IsEnabled = loggingEnabled;
_developmentLogging = development;
_guiLogging = gui;
_headlessLogging = headless;
}
/// <summary>
/// Initializes script for use.
/// </summary>
/// <param name = "manager"></param>
public override void InitializeOnce()
{
byte currentHighest = (byte)LoggingType.Off;
#if UNITY_SERVER
currentHighest = Math.Max(currentHighest, (byte)_headlessLogging);
#elif DEVELOPMENT
currentHighest = Math.Max(currentHighest, (byte)_developmentLogging);
#else
currentHighest = Math.Max(currentHighest, (byte)_guiLogging);
#endif
_highestLoggingType = (LoggingType)currentHighest;
_initialized = true;
}
/// <summary>
/// True if can log for loggingType.
/// </summary>
/// <param name = "loggingType">Type of logging being filtered.</param>
/// <returns></returns>
public override bool CanLog(LoggingType loggingType)
{
if (!IsEnabled)
return false;
if (!_initialized)
{
#if DEVELOPMENT
if (Application.isPlaying)
NetworkManagerExtensions.LogError("CanLog called before being initialized.");
else
return true;
#endif
return false;
}
return (byte)loggingType <= (byte)_highestLoggingType;
}
/// <summary>
/// Logs a common value if can log.
/// </summary>
public override void Log(string value)
{
if (CanLog(LoggingType.Common))
Debug.Log(AddSettingsToLog(value));
}
/// <summary>
/// Logs a warning value if can log.
/// </summary>
public override void LogWarning(string value)
{
if (CanLog(LoggingType.Warning))
Debug.LogWarning(AddSettingsToLog(value));
}
/// <summary>
/// Logs an error value if can log.
/// </summary>
public override void LogError(string value)
{
if (CanLog(LoggingType.Error))
Debug.LogError(AddSettingsToLog(value));
}
/// <summary>
/// Clones this logging configuration.
/// </summary>
/// <returns></returns>
public override LoggingConfiguration Clone()
{
LevelLoggingConfiguration copy = CreateInstance<LevelLoggingConfiguration>();
copy.LoggingConstructor(IsEnabled, _developmentLogging, _guiLogging, _headlessLogging);
copy._addTimestamps = _addTimestamps;
copy._addLocalTick = _addLocalTick;
copy._enableTimestampsInEditor = _enableTimestampsInEditor;
return copy;
}
/// <summary>
/// Adds onto logging message if settings are enabled to.
/// </summary>
private string AddSettingsToLog(string value)
{
_stringBuilder.Clear();
if (_addTimestamps && (!Application.isEditor || _enableTimestampsInEditor))
_stringBuilder.Append($"[{DateTime.Now:yyyy.MM.dd HH:mm:ss}] ");
if (_addLocalTick)
{
TimeManager tm = InstanceFinder.TimeManager;
uint tick = tm == null ? TimeManager.UNSET_TICK : tm.LocalTick;
_stringBuilder.Append($"LocalTick [{tick}] ");
}
// If anything was added onto string builder then add value, and set value to string builder.
if (_stringBuilder.Length > 0)
{
_stringBuilder.Append(value);
value = _stringBuilder.ToString();
}
return value;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 925fc096350b81f4f82f4fe4ac0c4dda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
assetPath: Assets/FishNet/Runtime/Managing/Logging/LevelLoggingConfiguration.cs
uploadId: 866910
@@ -0,0 +1,61 @@
using FishNet.Documenting;
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace FishNet.Managing.Logging
{
/// <summary>
/// Base for logging configurations.
/// </summary>
public abstract class LoggingConfiguration : ScriptableObject
{
#region Serialized.
/// <summary>
/// True to use logging features. False to disable all logging.
/// </summary>
[Tooltip("True to use logging features. False to disable all logging.")]
public bool IsEnabled = true;
[Obsolete("Use IsEnabled.")] // Remove V5
public bool LoggingEnabled
{
get => IsEnabled;
set => IsEnabled = value;
}
#endregion
/// <summary>
/// Initializes script for use.
/// </summary>
/// <param name = "manager"></param>
public virtual void InitializeOnce() { }
/// <summary>
/// True if can log for loggingType.
/// </summary>
/// <param name = "loggingType">Type of logging being filtered.</param>
/// <returns></returns>
public abstract bool CanLog(LoggingType loggingType);
/// <summary>
/// Logs a common value if can log.
/// </summary>
public abstract void Log(string value);
/// <summary>
/// Logs a warning value if can log.
/// </summary>
public abstract void LogWarning(string value);
/// <summary>
/// Logs an error value if can log.
/// </summary>
public abstract void LogError(string value);
/// <summary>
/// Clones this logging configuration.
/// </summary>
/// <returns></returns>
public abstract LoggingConfiguration Clone();
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 438d7e99b7655114891d4fa6e9f68c7d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
assetPath: Assets/FishNet/Runtime/Managing/Logging/LoggingConfiguration.cs
uploadId: 866910
@@ -0,0 +1,25 @@
namespace FishNet.Managing.Logging
{
/// <summary>
/// Type of logging being filtered.
/// </summary>
public enum LoggingType : byte
{
/// <summary>
/// Disable logging.
/// </summary>
Off = 0,
/// <summary>
/// Only log errors.
/// </summary>
Error = 1,
/// <summary>
/// Log warnings and errors.
/// </summary>
Warning = 2,
/// <summary>
/// Log all common activities, warnings, and errors.
/// </summary>
Common = 3
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8bf0a7ab3f60fe44984fcfd16d8fe7b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
assetPath: Assets/FishNet/Runtime/Managing/Logging/LoggingType.cs
uploadId: 866910