Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-03 11:02:29 +02:00
commit 27d6b94b7c
8167 changed files with 1116569 additions and 0 deletions

View File

@ -0,0 +1,211 @@
using System.Collections.Generic;
using System.Reflection;
using Convai.Scripts.Utils;
using UnityEditor;
using UnityEngine;
using Logger = Convai.Scripts.Utils.Logger;
namespace Convai.Scripts.Editor
{
/// <summary>
/// Manages the settings for the Logger, including loading, creating, and modifying LoggerSettings.
/// </summary>
public class LoggerSettingsManager
{
// Path to the LoggerSettings asset
private const string SETTINGS_PATH = "Assets/Convai/Resources/LoggerSettings.asset";
/// <summary>
/// Mapping between the row names and the field names in the LoggerSettings class.
/// </summary>
private static readonly Dictionary<string, string> CategoryMapping = new()
{
{ "Character", "characterResponse" },
{ "LipSync", "lipSync" },
{ "Actions", "actions" }
};
/// <summary>
/// The LoggerSettings instance.
/// </summary>
private LoggerSettings _loggerSettings;
/// <summary>
/// Property accessor for _loggerSettings. If _loggerSettings is null, it attempts to load it from the asset path.
/// If the asset does not exist, it creates a new LoggerSettings instance.
/// </summary>
public LoggerSettings loggerSettings
{
get
{
if (_loggerSettings == null)
{
_loggerSettings = AssetDatabase.LoadAssetAtPath<LoggerSettings>(SETTINGS_PATH);
if (_loggerSettings == null)
{
CreateLoggerSettings();
Logger.Warn("LoggerSettings ScriptableObject not found. Creating one...",
Logger.LogCategory.Character);
}
}
return _loggerSettings;
}
}
/// <summary>
/// Creates a new LoggerSettings instance with default values and saves it as an asset
/// </summary>
private void CreateLoggerSettings()
{
_loggerSettings = ScriptableObject.CreateInstance<LoggerSettings>();
// Set default values for Character
_loggerSettings.characterResponseDebug = true;
_loggerSettings.characterResponseInfo = true;
_loggerSettings.characterResponseWarning = true;
_loggerSettings.characterResponseError = true;
_loggerSettings.characterResponseException = true;
// Set default values for LipSync
_loggerSettings.lipSyncDebug = true;
_loggerSettings.lipSyncInfo = true;
_loggerSettings.lipSyncWarning = true;
_loggerSettings.lipSyncError = true;
_loggerSettings.lipSyncException = true;
// Set default values for Actions
_loggerSettings.actionsDebug = true;
_loggerSettings.actionsInfo = true;
_loggerSettings.actionsWarning = true;
_loggerSettings.actionsError = true;
_loggerSettings.actionsException = true;
// Check if the Convai folder exists and create if not
if (!AssetDatabase.IsValidFolder("Assets/Convai/Resources"))
AssetDatabase.CreateFolder("Assets/Convai", "Resources");
// Check if the Settings folder exists and create if not
if (!AssetDatabase.IsValidFolder("Assets/Convai/Resources/Settings"))
AssetDatabase.CreateFolder("Assets/Convai/Resources", "Settings");
AssetDatabase.CreateAsset(_loggerSettings, SETTINGS_PATH);
AssetDatabase.SaveAssets();
}
/// <summary>
/// Checks if all flags for a given row are set.
/// </summary>
/// <param name="rowName">The name of the row to check.</param>
/// <returns>True if all flags for the given row are set, false otherwise.</returns>
public bool GetAllFlagsForRow(string rowName)
{
bool allSelected = true;
foreach (string logType in new[] { "Debug", "Error", "Exception", "Info", "Warning" })
{
string baseFieldName = CategoryMapping.TryGetValue(rowName, out string value) ? value : string.Empty;
if (string.IsNullOrEmpty(baseFieldName))
{
Debug.LogError($"No mapping found for row {rowName}");
return false;
}
string fieldName = $"{baseFieldName}{logType}";
FieldInfo field = _loggerSettings.GetType().GetField(fieldName);
if (field != null)
{
bool currentValue = (bool)field.GetValue(_loggerSettings);
allSelected &= currentValue;
}
else
{
Debug.LogError($"Field {fieldName} does not exist in LoggerSettings");
return false;
}
}
return allSelected;
}
/// <summary>
/// Renders a checkbox for a given log type and handles changes to its value.
/// </summary>
/// <param name="rowName">The name of the row to render the checkbox for.</param>
/// <param name="logType">The type of log to handle.</param>
public void RenderAndHandleCheckbox(string rowName, string logType)
{
// Using the mapping to get the base name for the fields
string baseFieldName = CategoryMapping.TryGetValue(rowName, out string value) ? value : string.Empty;
if (string.IsNullOrEmpty(baseFieldName))
{
Debug.LogError($"No mapping found for row {rowName}");
return;
}
string fieldName = $"{baseFieldName}{logType}";
FieldInfo field = _loggerSettings.GetType().GetField(fieldName);
if (field != null)
{
bool currentValue = (bool)field.GetValue(_loggerSettings);
bool newValue = EditorGUILayout.Toggle(currentValue, GUILayout.Width(100));
if (currentValue != newValue) field.SetValue(_loggerSettings, newValue);
}
else
{
Debug.LogError($"Field {fieldName} does not exist in LoggerSettings");
}
}
/// <summary>
/// Sets all flags for a given row to the provided value.
/// </summary>
/// <param name="rowName">The name of the row to set the flags for.</param>
/// <param name="value">The value to set all flags to.</param>
public void SetAllFlagsForRow(string rowName, bool value)
{
foreach (string logType in new[] { "Debug", "Error", "Exception", "Info", "Warning" })
{
string baseFieldName = CategoryMapping.TryGetValue(rowName, out string value1) ? value1 : string.Empty;
if (string.IsNullOrEmpty(baseFieldName))
{
Debug.LogError($"No mapping found for row {rowName}");
return;
}
string fieldName = $"{baseFieldName}{logType}";
FieldInfo field = _loggerSettings.GetType().GetField(fieldName);
if (field != null)
field.SetValue(_loggerSettings, value);
else
Debug.LogError($"Field {fieldName} does not exist in LoggerSettings");
}
}
/// <summary>
/// Sets all flags to the provided value.
/// </summary>
/// <param name="value"> The value to set all flags to.</param>
public void SetAllFlags(bool value)
{
string[] categories = { "characterResponse", "lipSync", "actions" };
string[] logTypes = { "Debug", "Info", "Error", "Exception", "Warning" };
foreach (string category in categories)
foreach (string logType in logTypes)
{
string fieldName = $"{category}{logType}";
FieldInfo field = _loggerSettings.GetType().GetField(fieldName);
if (field != null && field.FieldType == typeof(bool))
field.SetValue(_loggerSettings, value);
else
Debug.LogWarning($"Field {fieldName} not found or not boolean.");
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b6aa5925780d46299eacd79ab8115332
timeCreated: 1701853621

View File

@ -0,0 +1,87 @@
using UnityEditor;
using UnityEngine;
namespace Convai.Scripts.Editor
{
public class LoggerSettingsWindow : EditorWindow
{
private readonly LoggerSettingsManager _loggerSettingsManager = new();
private void OnEnable()
{
_ = _loggerSettingsManager.loggerSettings;
}
private void OnGUI()
{
// Setting window size
minSize = new Vector2(850, 250);
maxSize = minSize;
if (_loggerSettingsManager.loggerSettings == null) return;
EditorGUILayout.Space(20);
// Create a custom GUIStyle based on EditorStyles.wordWrappedLabel
GUIStyle customLabelStyle = new(EditorStyles.wordWrappedLabel)
{
fontSize = 15,
normal = { textColor = Color.grey }
};
// Display a label with a custom style
GUILayout.Label(
"These loggerSettings only affect log loggerSettings related to the Convai plugin. Changes made here will not affect other parts of your project.",
customLabelStyle);
EditorGUILayout.Space(20);
// Headers for the table
string[] headers =
{ "Select All", "Category", "Debug", "Info", "Error", "Exception", "Warning" };
// Names of the rows in the table
string[] rowNames = { "Character", "LipSync", "Actions" };
// Style for the headers
GUIStyle headerStyle = new(GUI.skin.label)
{
fontStyle = FontStyle.Bold,
alignment = TextAnchor.MiddleLeft
};
// Draw the headers
EditorGUILayout.BeginHorizontal();
foreach (string header in headers) GUILayout.Label(header, headerStyle, GUILayout.Width(95));
EditorGUILayout.EndHorizontal();
// Slightly increased spacing between rows
EditorGUILayout.Space(5);
// Draw the rows
foreach (string row in rowNames)
{
EditorGUILayout.BeginHorizontal();
// 'Select All' checkbox for each row
bool allSelectedForRow = _loggerSettingsManager.GetAllFlagsForRow(row);
bool newAllSelectedForRow = EditorGUILayout.Toggle(allSelectedForRow, GUILayout.Width(100));
if (newAllSelectedForRow != allSelectedForRow)
_loggerSettingsManager.SetAllFlagsForRow(row, newAllSelectedForRow);
GUILayout.Label(row, GUILayout.Width(100));
// Individual checkboxes for each log type
foreach (string logType in new[] { "Debug", "Info", "Error", "Exception", "Warning" })
_loggerSettingsManager.RenderAndHandleCheckbox(row, logType);
EditorGUILayout.EndHorizontal();
}
// Increased spacing before global actions
EditorGUILayout.Space(20);
// Global actions
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Select All", GUILayout.Width(150), GUILayout.Height(30))) // Slightly bigger button
_loggerSettingsManager.SetAllFlags(true);
if (GUILayout.Button("Clear All", GUILayout.Width(150), GUILayout.Height(30))) // Slightly bigger button
_loggerSettingsManager.SetAllFlags(false);
EditorGUILayout.EndHorizontal();
// Additional space at the end for cleaner look
EditorGUILayout.Space(20);
// If the GUI has changed, mark _settings as dirty so it gets saved
if (GUI.changed) EditorUtility.SetDirty(_loggerSettingsManager.loggerSettings);
}
[MenuItem("Convai/Logger Settings")]
public static void ShowWindow()
{
GetWindow<LoggerSettingsWindow>("Logger Settings");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1cfc7ccc4a8a584459a48d2851faa587
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: