Nick J. Connors d721201b0e Forked
Renamed to new horizons, updated to current versions of OWML and Outer Wilds, added BlackHoleBuilder, LavaBuilder, RingBuilder. Added support to modify existing planets with configs.
2021-12-08 00:09:11 -05:00

75 lines
2.0 KiB
C#

using OWML.Common;
using System;
using System.ComponentModel;
using UnityEngine;
namespace NewHorizons.Utility
{
public class Logger
{
public static void LogProperties(UnityEngine.Object obj)
{
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj))
{
string name = descriptor?.Name;
object value;
try
{
value = descriptor.GetValue(obj);
}
catch(Exception)
{
value = null;
}
Log($"{obj.name} {name}={value}");
}
}
public static void LogPath(GameObject go)
{
if (go == null) Log("Can't print path: GameObject is null");
else Log($"{GetPath(go.transform)}");
}
private static string GetPath(Transform current)
{
if (current.parent == null) return "/" + current.name;
return GetPath(current.parent) + "/" + current.name;
}
public static void Log(string text, LogType type)
{
Main.helper.Console.WriteLine(Enum.GetName(typeof(LogType), type) + " : " + text, LogTypeToMessageType(type));
}
public static void Log(string text)
{
Log(text, LogType.Log);
}
public static void LogError(string text)
{
Log(text, LogType.Error);
}
public enum LogType
{
Log,
Error,
Warning,
Todo
}
private static MessageType LogTypeToMessageType(LogType t)
{
switch(t)
{
case LogType.Error:
return MessageType.Error;
case LogType.Warning:
return MessageType.Warning;
default:
return MessageType.Info;
}
}
}
}