public static void LogError(string theError, string theCategory, MonoBehaviour theObject) { #if KGFDebug KGFDebug.LogError(theError, theCategory, theObject); #else Debug.LogError(string.Format("{0} - {1}", theCategory, theError)); #endif }
public static void LogWarning(string theMessage, string theCategory, MonoBehaviour theCaller) { #if KGFDebug KGFDebug.LogError(theMessage, "KGFEventSystem", null); #else Debug.LogWarning(theMessage); #endif }
// Use this for initialization void Start() { KGFDebug.LogDebug("Start() method of enemy: BossLevelOne was called", "Load.methods"); KGFDebug.LogInfo("Currently 25 enemies in the Scene", "Enemy.Count"); KGFDebug.LogWarning("Gravitation inconsistency: Make sure gravitation is -9.81.", "Physics.forces"); KGFDebug.LogError("Cannot open file: d:\\tmp\\mytestdata. Make sure such a file exist and check read write permissions of the directory.", "IO.filereads", this); KGFDebug.LogFatal("The referenced module is missing. Make sure to keep the module running if its in use.", "Module.Status"); Debug.LogError("This error demonstrates KGFDebugs ability to capture unity3d Debug.Log messages."); }
protected override void KGFAwake() { base.KGFAwake(); if (itsDataDebugFile.itsFilePath == string.Empty) { itsDataDebugFile.itsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "KGFLog.txt"); } // create a new file using (var file = new StreamWriter(itsDataDebugFile.itsFilePath, false, Encoding.ASCII)) { file.WriteLine("".PadLeft("FileLogger started: ".Length + DateTime.Now.ToString().Length, '=')); } KGFDebug.AddLogger(this); }
/// <summary> /// This method is called from Unity3D Engine when the script instance is being loaded. /// </summary> /// <remarks> /// Awake is called before the game starts. Any state settings and variable initialization can be placed here. /// In this class Awake checks if there is already an instance of KGFDebug. If there is already an instance running, the calling /// gameObject will be deleted. /// </remarks> /// <example> /// How to ensure that there is only one instance. /// <code> /// private static KGFDebug itsInstance = null; /// /// protected void Awake() /// { /// //check if a KGFDebug instance is already running /// if (itsInstance == null) /// itsInstance = this; /// else /// Destroy(gameObject); ///} /// </code> /// </example> protected override void KGFAwake() { base.KGFAwake(); //check if a KGFDebug instance is already running if (itsInstance == null) { itsInstance = this; } else { if (itsInstance != this) { UnityEngine.Debug.Log("there is more than one KFGDebug instance in this scene. please ensure there is always exactly one instance in this scene"); Destroy(gameObject); } } }
private static void CheckInstance() { // check if the cheat module is already activated if (itsInstance == null) { UnityEngine.Object theObject = UnityEngine.Object.FindObjectOfType(typeof(KGFDebug)); if (theObject != null) { itsInstance = theObject as KGFDebug; } else { if (!itsAlreadyChecked) { UnityEngine.Debug.LogError("Kolmich Debug Module is not running. Make sure that there is an instance of the KGFDebug prefab in the current scene. Adding loggers in Awake() can cause problems, prefer to add loggers in Start()."); itsAlreadyChecked = true; } } } }
public void Awake() { KGFDebug.AddLogger(this); }