/* * @author Valentin Simonov / http://va.lent.in/ */ #if TOUCHSCRIPT_DEBUG using System.Collections.Generic; using TouchScript.Debugging.Filters; using UnityEngine; using TouchScript.Debugging.Loggers; using TouchScript.Pointers; namespace TouchScript.Debugging { /// /// A set of debugging tools for TouchScript. /// public class TouchScriptDebugger : ScriptableObject { /// /// The singleton instance of the debugger. /// public static TouchScriptDebugger Instance { get { if (instance == null) { var objs = Resources.FindObjectsOfTypeAll(); if (objs.Length > 0) instance = objs[0]; else { instance = CreateInstance(); instance.hideFlags = HideFlags.HideAndDontSave; } } return instance; } } /// /// Current logger to record pointer events. /// public IPointerLogger PointerLogger { get { return pointerLogger; } set { if (value == null) return; if (pointerLogger == value) return; pointerLogger.Dispose(); pointerLogger = value; } } private static TouchScriptDebugger instance; private IPointerLogger pointerLogger; public void ClearPointerLogger() { if (Application.isEditor) pointerLogger = new DummyLogger(); else pointerLogger = new FileWriterLogger(); } private void OnEnable() { if (pointerLogger == null) ClearPointerLogger(); } private void OnDisable() { if (pointerLogger != null) pointerLogger.Dispose(); } private class DummyLogger : IPointerLogger { public int PointerCount { get { return 0; } } public void Log(Pointer pointer, PointerEvent evt) {} public List GetFilteredPointerData(IPointerDataFilter filter = null) { return new List(); } public List GetFilteredLogsForPointer(int id, IPointerLogFilter filter = null) { return new List(); } public void Dispose() {} } } } #endif