using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Channel = Ubisoft.HtLogger.Channel; public class DebugTestSceneController : MonoBehaviour { private readonly HashSet CHANNELS_SET = new HashSet() { GameLogger.CHANNEL_ORANGE }; private enum EChannelsInability { EnableAllChannels, DisableAllChannels, EnableAllChannelsExceptOrange, DisableAllChannelsExceptOrange } public Dropdown m_channelsDropwdown; public Dropdown m_channelsInabilityDropwdown; private Channel m_currentChannel; void Start() { if (m_channelsDropwdown != null) { m_channelsDropwdown.ClearOptions(); List options = new List(); Dropdown.OptionData option; List gameChannels = GameLogger.Channels; int count = gameChannels.Count; for (int i = 0; i < count; ++i) { option = new Dropdown.OptionData { text = gameChannels[i].Name }; options.Add(option); } m_channelsDropwdown.AddOptions(options); SetCurrentChannelByIndex(0); } if (m_channelsInabilityDropwdown != null) { m_channelsInabilityDropwdown.ClearOptions(); List options = new List(); Dropdown.OptionData option; string[] values = Enum.GetNames(typeof(EChannelsInability)); int count = values.Length; for (int i = 0; i < count; ++i) { option = new Dropdown.OptionData { text = values[i] }; options.Add(option); } m_channelsInabilityDropwdown.AddOptions(options); } } public void OnChangeChannel(int index) { if (m_channelsDropwdown != null) { SetCurrentChannelByIndex(index); } } public void OnChangeChannelsInability(int index) { EChannelsInability channelsInability = (EChannelsInability)index; switch (channelsInability) { case EChannelsInability.EnableAllChannels: global::Debug.EnableAllChannels(); break; case EChannelsInability.DisableAllChannels: Debug.DisableAllChannels(); break; case EChannelsInability.EnableAllChannelsExceptOrange: Debug.EnableAllChannelsExcept(CHANNELS_SET); break; case EChannelsInability.DisableAllChannelsExceptOrange: Debug.DisableAllChannelsExcept(CHANNELS_SET); break; } } public void LogTrace() { string message = "LogTrace"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogTrace(message); Debug.LogTrace($"{message} with context", m_channelsDropwdown); Debug.LogTraceFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogTraceFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogTrace(channel, messageInDirectChannel); Debug.ChannelLogTrace(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogTraceFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogTraceFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogTrace(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogTrace(Debug.Logger.GeneralChannel, messageInChannel); } public void LogDebug() { string message = "LogDebug"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogDebug(message); Debug.LogDebug($"{message} with context", m_channelsDropwdown); Debug.LogDebugFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogDebugFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogDebug(channel, messageInDirectChannel); Debug.ChannelLogDebug(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogDebugFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogDebugFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogDebug(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogDebug(Debug.Logger.GeneralChannel, messageInChannel); } public void LogInformation() { string message = "LogInformation"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogInformation(message); Debug.LogInformation($"{message} with context", m_channelsDropwdown); Debug.LogInformationFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogInformationFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogInformation(channel, messageInDirectChannel); Debug.ChannelLogInformation(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogInformationFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogInformationFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogInformation(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogInformation(Debug.Logger.GeneralChannel, messageInChannel); } public void LogWarning() { string message = "LogWarning"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogWarning(message); Debug.LogWarning($"{message} with context", m_channelsDropwdown); Debug.LogWarningFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogWarningFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogWarning(channel, messageInDirectChannel); Debug.ChannelLogWarning(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogWarningFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogWarningFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogWarning(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogWarning(Debug.Logger.GeneralChannel, messageInChannel); } public void LogError() { string message = "LogError"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogError(message); Debug.LogError($"{message} with context", m_channelsDropwdown); Debug.LogErrorFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogErrorFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogError(channel, messageInDirectChannel); Debug.ChannelLogError(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogErrorFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogErrorFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogError(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogError(Debug.Logger.GeneralChannel, messageInChannel); } public void LogCritical() { string message = "LogCritical"; string messageInDirectChannel = $"{message} in a channel passed in directly (no color supported)"; string channel = "ChannelAsString"; int param1 = 4; string param2 = "boo"; // Use Logger directly Debug.LogCritical(message); Debug.LogCritical($"{message} with context", m_channelsDropwdown); Debug.LogCriticalFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogCriticalFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogCritical(channel, messageInDirectChannel); Debug.ChannelLogCritical(channel, messageInDirectChannel + " with context", m_channelsDropwdown); Debug.ChannelLogCriticalFormat(channel, messageInDirectChannel + " with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogCriticalFormat(channel, m_channelsDropwdown, messageInDirectChannel + " with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelLogCritical(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelLogCritical(Debug.Logger.GeneralChannel, messageInChannel); } public void Assert() { string message = "Assert"; string messageInDirectChannel = $"{message} in a channel passed in directly "; int param1 = 4; string param2 = "boo"; // Use Logger directly // It won't be logged because condition is true Debug.Assert(true, $"{message} true"); Debug.Assert(false, $"{message} false"); // It won't be logged because condition is true Debug.Assert(true, $"{message} true with context", m_channelsDropwdown); Debug.Assert(false, $"{message} false with context", m_channelsDropwdown); // It won't be logged because condition is true Debug.AssertFormat(true, $"{message} true with format (Param1: {0}, Param2: {1})", param1, param2); Debug.AssertFormat(false, $"{message} false with format (Param1: {0}, Param2: {1})", param1, param2); Debug.LogAssertion("LogAssertion"); Debug.LogAssertion("LogAssertion with context", m_channelsDropwdown); string channel = "ChannelAsString"; // It won't be logged because condition is true Debug.ChannelAssert(channel, true, $"{messageInDirectChannel} true"); Debug.ChannelAssert(channel, false, $"{messageInDirectChannel} false"); // It won't be logged because condition is true Debug.ChannelAssertFormat(channel, true, $"{messageInDirectChannel} true with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelAssertFormat(channel, false, $"{messageInDirectChannel} false with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogAssertion(channel, messageInDirectChannel); Debug.ChannelLogAssertion(channel, m_channelsDropwdown, $"{messageInDirectChannel} with context"); Debug.ChannelLogAssertion(channel, $"{messageInDirectChannel} with format (Param1: {0}, Param2: {1})", param1, param2); Debug.ChannelLogAssertion(channel, m_channelsDropwdown, $"{messageInDirectChannel} with context and format (Param1: {0}, Param2: {1})", param1, param2); // Use a channel string messageInChannel = $"{message} in selected channel"; ChannelAssert(m_currentChannel, messageInChannel); // Use default channel messageInChannel = $"{message} in General channel"; ChannelAssert(Debug.Logger.GeneralChannel, messageInChannel); } private int[] temp; public void TriggerException() { Debug.LogTrace(temp[10]); } private void ChannelLogTrace(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogTrace(message); channel.LogTrace($"{message} with context", m_channelsDropwdown); channel.LogTraceFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogTraceFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelLogDebug(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogDebug(message); channel.LogDebug($"{message} with context", m_channelsDropwdown); channel.LogDebugFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogDebugFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelLogInformation(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogInformation(message); channel.LogInformation($"{message} with context", m_channelsDropwdown); channel.LogInformationFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogInformationFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelLogWarning(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogWarning(message); channel.LogWarning($"{message} with context", m_channelsDropwdown); channel.LogWarningFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogWarningFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelLogError(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogError(message); channel.LogError($"{message} with context", m_channelsDropwdown); channel.LogErrorFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogErrorFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelLogCritical(Channel channel, string message) { int param1 = 4; string param2 = "boo"; channel.LogCritical(message); channel.LogCritical($"{message} with context", m_channelsDropwdown); channel.LogCriticalFormat(message + " with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogCriticalFormat(m_channelsDropwdown, message + " with context and format (Param1: {0}, Param2: {1})", param1, param2); } private void ChannelAssert(Channel channel, string message) { int param1 = 4; string param2 = "boo"; // It won't be logged because condition is true channel.Assert(true, $"{message} true"); channel.Assert(false, $"{message} false"); // It won't be logged because condition is true channel.Assert(true, $"{message} true with context", m_channelsDropwdown); channel.Assert(false, $"{message} false with context", m_channelsDropwdown); // It won't be logged because condition is true channel.AssertFormat(true, $"{message} true with format (Param1: {0}, Param2: {1})", param1, param2); channel.AssertFormat(false, $"{message} false with format (Param1: {0}, Param2: {1})", param1, param2); channel.LogAssertion("LogAssertion"); channel.LogAssertion("LogAssertion with context", m_channelsDropwdown); } private void SetCurrentChannelByIndex(int index) { List channels = GameLogger.Channels; if (index > -1 && index < channels.Count) { m_currentChannel = channels[index]; } else { m_currentChannel = null; } } }