Example #1
0
    public static bool SaveDebugSetting(Dictionary <CsDComponent, CsDLevel> setting, CsDLogTarget logTarget)
    {
        string path = GameManager.Inst.AppDataPath + "/GameData/";

        if (!MakeSureFileExists(path, "Debugs.txt"))
        {
            return(false);
        }

        //clear the file

        System.IO.File.WriteAllText(path + "Debugs.txt", "LogTarget=" + logTarget + "\r\n");

        foreach (KeyValuePair <CsDComponent, CsDLevel> line in setting)
        {
            string text = line.Key.ToString() + "=" + line.Value.ToString() + "\r\n";
            try
            {
                System.IO.File.AppendAllText(path + "Debugs.txt", text);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(e.Message);
                return(false);
            }
        }


        return(true);
    }
Example #2
0
    void OnGUI()
    {
        GUILayout.Label("Debug Level Settings", EditorStyles.boldLabel);

        CsDComponent [] components = (CsDComponent[])Enum.GetValues(typeof(CsDComponent));

        foreach (CsDComponent component in components)
        {
            DebugLevel[component] = (CsDLevel)EditorGUILayout.EnumPopup(component.ToString(), DebugLevel[component]);
        }

        GUILayout.Label("Debug Log Target", EditorStyles.boldLabel);

        LogTarget = (CsDLogTarget)EditorGUILayout.EnumPopup("Log Target", LogTarget);


        if (GUILayout.Button("Save", GUILayout.Width(50)))
        {
            if (CsDebug.SaveDebugSetting(DebugLevel, LogTarget))
            {
                Debug.Log("Debug level setting saved successfully!");
            }
            else
            {
                Debug.LogError("Failed to save debug level setting!");
            }
        }
    }
Example #3
0
    void OnGUI()
    {
        GUILayout.Label("Debug Level Settings", EditorStyles.boldLabel);

        CsDComponent [] components = (CsDComponent[])Enum.GetValues(typeof(CsDComponent));

        foreach(CsDComponent component in components)
        {
            DebugLevel[component] = (CsDLevel) EditorGUILayout.EnumPopup(component.ToString(), DebugLevel[component]);
        }

        GUILayout.Label("Debug Log Target", EditorStyles.boldLabel);

        LogTarget = (CsDLogTarget) EditorGUILayout.EnumPopup("Log Target", LogTarget);

        if(GUILayout.Button("Save", GUILayout.Width(50)))
        {
            if(CsDebug.SaveDebugSetting(DebugLevel, LogTarget))
            {
                Debug.Log("Debug level setting saved successfully!");
            }
            else
            {
                Debug.LogError("Failed to save debug level setting!");
            }
        }
    }
Example #4
0
    public static bool SaveDebugSetting(Dictionary<CsDComponent, CsDLevel> setting, CsDLogTarget logTarget)
    {
        string path = Application.dataPath + "/GameData/";

        if(!MakeSureFileExists(path, "Debugs.txt"))
        {
            return false;
        }

        //clear the file

        System.IO.File.WriteAllText(path + "Debugs.txt", "LogTarget=" + logTarget + "\r\n");

        foreach(KeyValuePair<CsDComponent,CsDLevel> line in setting)
        {
            string text = line.Key.ToString() + "=" + line.Value.ToString() + "\r\n";
            try
            {
                System.IO.File.AppendAllText(path + "Debugs.txt", text);
            }
            catch(Exception e)
            {
                UnityEngine.Debug.LogError(e.Message);
                return false;
            }
        }

        return true;
    }
Example #5
0
    public static Dictionary <CsDComponent, CsDLevel> LoadDebugSetting(out CsDLogTarget logTarget)
    {
        string [] rawFile;

        try
        {
            rawFile = File.ReadAllLines(Application.dataPath + "/GameData/" + "Debugs.txt");
        }
        catch (Exception e)
        {
            logTarget = CsDLogTarget.File;
            UnityEngine.Debug.LogError(e.Message);
            return(null);
        }


        Dictionary <string, object>         data       = CsDebug.ParseLines(rawFile);
        Dictionary <CsDComponent, CsDLevel> debugLevel = new Dictionary <CsDComponent, CsDLevel>();

        //build the dictionary with default values
        CsDComponent [] components = (CsDComponent[])Enum.GetValues(typeof(CsDComponent));
        foreach (CsDComponent component in components)
        {
            debugLevel.Add(component, CsDLevel.Default);
        }

        logTarget = (CsDLogTarget)System.Enum.Parse(typeof(CsDLogTarget), data["LogTarget"].ToString());
        data.Remove("LogTarget");

        foreach (KeyValuePair <string, object> line in data)
        {
            CsDComponent component = (CsDComponent)System.Enum.Parse(typeof(CsDComponent), line.Key);
            CsDLevel     level     = (CsDLevel)System.Enum.Parse(typeof(CsDLevel), line.Value.ToString());


            debugLevel[component] = level;
        }

        return(debugLevel);
    }
Example #6
0
    public static Dictionary<CsDComponent, CsDLevel> LoadDebugSetting(out CsDLogTarget logTarget)
    {
        string [] rawFile;

        try
        {
            rawFile = File.ReadAllLines(Application.dataPath + "/GameData/" + "Debugs.txt");
        }
        catch(Exception e)
        {
            logTarget = CsDLogTarget.File;
            UnityEngine.Debug.LogError(e.Message);
            return null;
        }

        Dictionary<string, object> data = CsDebug.ParseLines(rawFile);
        Dictionary<CsDComponent, CsDLevel> debugLevel = new Dictionary<CsDComponent, CsDLevel>();

        //build the dictionary with default values
        CsDComponent [] components = (CsDComponent[])Enum.GetValues(typeof(CsDComponent));
        foreach(CsDComponent component in components)
        {
            debugLevel.Add(component, CsDLevel.Default);
        }

        logTarget = (CsDLogTarget)System.Enum.Parse(typeof(CsDLogTarget), data["LogTarget"].ToString());
        data.Remove("LogTarget");

        foreach(KeyValuePair<string, object> line in data)
        {
            CsDComponent component = (CsDComponent)System.Enum.Parse(typeof(CsDComponent), line.Key);
            CsDLevel level = (CsDLevel)System.Enum.Parse(typeof(CsDLevel), line.Value.ToString());

            debugLevel[component] = level;

        }

        return debugLevel;
    }