Categorical Debug


Details

This utility provides the ability to turn logging on and off, by category. When displaying information, the appropriate category is specified, and the message will only be logged, if that category actually has logging enabled. DLL_SPECS Allows the programmer to specify a CategoryIndex (a int index), each time a Debug Log used is taken.
Each category may be enabled or disabled individually. Disabled categories, will NOT display Debug Log messages. Categories are registered with the DebugCategoryRegistrar class, and their enabled state is stored via Unity PlayerPrefs. This utility is internally used to draw various modules of options under a single EyEeengines section, in the Unity Editor Preferences window. Categorical Debug options are drawn in this window.

example:

using UnityEngine;
using System.Collections.Generic;
using EyE.Unity;
{
// [ExecuteInEditMode]
public class ToggleDebugTest : MonoBehaviour
{
//we will use global bools to make toggles show up on the component's inspector, allowing us to control the enabledState of the CategoryDebug.
//Since we only Get the stored enabled states during Start(), this wont work right for multiple instance of this component.
public bool enableTestDebugCategory;
public bool enableAnotherDebugCategory;
int testDebugCategoryID;
int anotherDebugCategoryID;
void Start()
{
//register all categories we would like to use for CatDebug
int catID;
bool failed = false;
// Debug.Log("attempting to register 'TestCategory");
catID = DebugCategoryRegistrar.RegisterCategory("TestCategory");
if (catID != -1)
testDebugCategoryID = catID;
else
failed = true;
// Debug.Log("registering 'TestCategory', assigned id: " + catID.ToString());
catID = DebugCategoryRegistrar.RegisterCategory("AnotherOne");
if (catID != -1) // if the register function returns -1, it failed to find an available ID for the category
anotherDebugCategoryID = catID;
else
failed = true;
// Debug.Log("registering 'AnotherOne', assigned id: " + catID.ToString());
if (failed)//how you choose to handle a lack of available categories is up to you. In this example we will output all their names
{
CatDebug.Log("All debug categories are registered!");
string registeredNames = "Registered Names: ";
for (int i = 0; i < int.MaxValue; i++)
{
if (DebugCategoryRegistrar.GetCategoryName(i) != null)
registeredNames += DebugCategoryRegistrar.GetCategoryName(i) + ", ";
}
CatDebug.Log(registeredNames);
//FYI: Categories can be removed from registration with:
//DebugCategoryRegistrar.UnRegisterCategory(unregCategoryID);
// and
//DebugCategoryRegistrar.DeleteAllSavedCategoryKeysFromPlayerPrefs();
}//failed
// load our local variables with the current enabled state with the preferences that have been loaded from disk
// this will allow them to be visible in the inspector
enableTestDebugCategory = DebugCategoryRegistrar.GetCategoryState(testDebugCategoryID);
Debug.Log("LoadingCategoryLogState for TestCategory: " + enableTestDebugCategory.ToString());
enableAnotherDebugCategory = DebugCategoryRegistrar.GetCategoryState(anotherDebugCategoryID);
Debug.Log("LoadingCategoryLogState for anotherDebugCategory: " + enableAnotherDebugCategory.ToString());
CatDebug.addCategoryNameToLog = true;
}
void Update()
{
// Debug.Log("updating setting log states based on user input from inspector");
// write any changes the user may have made back to the Registrar
DebugCategoryRegistrar.SetCategoryState(testDebugCategoryID, enableTestDebugCategory);
DebugCategoryRegistrar.SetCategoryState(anotherDebugCategoryID, enableAnotherDebugCategory);
CatDebug.Log("General Log message- test.");
CatDebug.Log(testDebugCategoryID, "Test Debug Category test Log message.");
for (int i = 0; i < 10; i++)
CatDebug.Log(anotherDebugCategoryID, "anotherDebugCategory log testing inside a Loop message. ", i);
}
void OnApplicationQuit()
{
DebugCategoryRegistrar.SetCategoryState(testDebugCategoryID, enableTestDebugCategory);
DebugCategoryRegistrar.SetCategoryState(anotherDebugCategoryID, enableAnotherDebugCategory);
}
}
}

Modules

 EyEengines.CatDebug.UnityEditor.dll
 ExtendedPrefs dll for use in the Unity Editor.
 
 EyEengines.CatDebug.dll
 ExtendedPrefs dll for use in built games, and the Unity Editor.
 

Classes

class  CatDebug
 This static class allows the programmer to specify a CategoryIndex, each time a Debug Log used is taken.
Each category may be enabled or disabled individually. Disabled categories, will NOT display Debug Log messages.
 
class  CatDebugOptions
 This class initializes and stores PlayerPrefs, which are persistent between sessions, that define how CatDebug will function.
 
class  CategoricalDebugOptionsGUI
 This class provides a function that can be used to display the Various Debug Categories along with toggle controls to enable and disable each. These options are not automatically drawn, (unless the VendorPrefs library is implemented in the unity project), so you will need to setup your own callback attribute.
 
class  DebugCategoryRegistrar
 This class provides functionality to easily register categories for use by CatDebug.
It also provides functions that allow getting/setting the enabled state or name of a particular category, and automatically stores these values to disk using Unity's PlayerPrefs.
If registered previously, these categories, and their states, are loaded from storage for initialization.
 
class  DebugCategorySettings
 stores the state information regarding each category
 
class  DebugCategorySettingsPlayerPref
 Concrete Variant of the PlayerPrefOption template class used to store DebugCategorySettings objects. It overrides the Load, Save and SetToDefault functions of the base class, to save/load each member of the DebugCategorySettings object Every-time a new CatDebug category is registered, a new instance of this class is created, and if it doesn't already exist, is stored in PlayerPrefOptions. If the category IS found to exist in PlayerPrefOptions, it is assigned the categoryID in the stored in the found DebugCategorySettings.
 
EyE
This namespace contains classes that provide various tools for use in the Unity Editor.
Definition: EmbededXMLTooltip.cs:5
EyE.Unity.Examples
Definition: CatDebugExample.cs:7
EyE.Unity
This namespace holds classes that extended or inherit from various Unity defined classes....
Definition: EmbededXMLTooltip.cs:5