Exemplo n.º 1
0
        public static LogSettingsSO FindLogSettings()
        {
            if (cache != null)
            {
                return(cache);
            }

            cache = Object.FindObjectOfType <LogSettingsSO>();
            if (cache != null)
            {
                return(cache);
            }

            string[] assetGuids = AssetDatabase.FindAssets("t:" + nameof(LogSettingsSO));
            if (assetGuids.Length == 0)
            {
                return(null);
            }

            string firstGuid = assetGuids[0];

            string path = AssetDatabase.GUIDToAssetPath(firstGuid);

            cache = AssetDatabase.LoadAssetAtPath <LogSettingsSO>(path);

            if (assetGuids.Length > 2)
            {
                Debug.LogWarning("Found more than one LogSettings, Delete extra settings. Using first asset found: " + path);
            }
            Debug.Assert(cache != null, "Failed to load asset at: " + path);

            return(cache);
        }
Exemplo n.º 2
0
        public static void LoadLogSettingsIntoDictionary()
        {
            LogSettingsSO settings = FindLogSettings();

            if (settings != null)
            {
                settings.LoadIntoLogFactory();
            }
        }
Exemplo n.º 3
0
        // called when component is added to GameObject
        private void Reset()
        {
            if (_settings != null)
            {
                return;
            }

            var existingSettings = EditorLogSettingsLoader.FindLogSettings();

            if (existingSettings != null)
            {
                Undo.RecordObject(this, "adding existing settings");
                _settings = existingSettings;
            }
        }
Exemplo n.º 4
0
        public static void SaveFromLogFactory(this LogSettingsSO settings)
        {
            Dictionary <string, ILogger> dictionary = LogFactory.loggers;

            if (settings == null)
            {
                Debug.LogWarning("Could not SaveFromDictionary because LogSettings were null");
                return;
            }

            settings.LogLevels.Clear();

            foreach (KeyValuePair <string, ILogger> kvp in dictionary)
            {
                settings.LogLevels.Add(new LogSettingsSO.LoggerSettings(kvp.Key, kvp.Value.filterLogType));
            }

#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(settings);
#endif
        }
Exemplo n.º 5
0
        public static void LoadIntoLogFactory(this LogSettingsSO settings)
        {
            if (settings == null)
            {
                Debug.LogWarning("Could not LoadIntoDictionary because LogSettings were null");
                return;
            }

            for (int i = 0; i < settings.LogLevels.Count; i++)
            {
                LogSettingsSO.LoggerSettings logLevel = settings.LogLevels[i];
                string key = logLevel.FullName;
                if (key == null)
                {
                    settings.LogLevels.RemoveAt(i);
                    i--;
                    Debug.LogWarning("Found null key in log settings, removing item");
                    continue;
                }

                ILogger logger = LogFactory.GetLogger(key);
                logger.filterLogType = logLevel.logLevel;
            }
        }