Beispiel #1
0
 private string GetSystemPrefix(IDebuggable system)
 {
     if (system == null || !_gameSystems.ContainsKey(system))
     {
         return("");
     }
     return(GetSystemPrefix(_gameSystems[system].parent) + "/" + system.GetType().Name);
 }
Beispiel #2
0
        /*public void Analyze()
         * {
         *  var semantic = new SemanticAnalyzer(astTree);
         *  semantic.analyze();
         *
         *  var aTree = semantic.annotatedTree;
         *  printDebug("Semantic tree:\n" + aTree + "\n");
         *
         *  //var semantic = new SemanticAnalyzer(tree);
         *  //semantic.generateTables();
         *  //semantic.analyze();
         *  //printDebug("Semantic tree:\n" + tree + "\n");
         * }*/

        /*public void Generate()
         * {
         *  var codeGen = new CodeGenerator(aTree, semantic.moduleTable, semantic.dataTable);
         *  codeGen.generate();
         *
         *  var asmCode = codeGen.assembly.ToString();
         *  printDebug("Generated assembly:\n" + asmCode);
         * }*/

        private static void PrintDebug(IDebuggable o, string description = null)
        {
            if (description == null)
            {
                description = o.GetType().ToString();
            }

            PrintDebug(description + ":\n" + o.ToDebugString());
            PrintDebug("");
        }
Beispiel #3
0
 public static void DeletePrefs(IDebuggable system, DebugSystemComponent.SystemInfo info, string prefix)
 {
     PlayerPrefs.DeleteKey(prefix + "isEnabled");
     PlayerPrefs.DeleteKey(prefix + "showLog");
     foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
     {
         if (CanDisplayField(field))
         {
             PlayerPrefs.DeleteKey(prefix + field.Name);
         }
     }
 }
Beispiel #4
0
    public static void LoadDefaultSettings(IDebuggable system, string prefix)
    {
        if (_settings == null)
        {
            LoadSettingsFromFile();
        }

        foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
        {
            string key = prefix + "_" + field.Name;
            if (CanDisplayField(field) && _settings.ContainsKey(key))
            {
                field.SetValue(system, _settings[key]);
            }
        }
    }
Beispiel #5
0
    public static void SaveDefaultSettings(IDebuggable system, string prefix)
    {
        if (_settings == null)
        {
            LoadSettingsFromFile();
        }

        foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
        {
            if (CanDisplayField(field))
            {
                _settings[prefix + "_" + field.Name] = field.GetValue(system);
            }
        }

        SaveSettingsToFile();
    }
Beispiel #6
0
    public static void LoadSettings(IDebuggable system, DebugSystemComponent.SystemInfo info, string prefix)
    {
        LoadVariable(prefix + "_isEnabled", ref info.isDebuggingEnabled);
        LoadVariable(prefix + "_showLog", ref info.showLog);

        foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
        {
            if (CanDisplayField(field) && field.GetCustomAttributes(typeof(DontRememberFieldValue), false).Length == 0)
            {
                if (field.FieldType == typeof(bool))
                {
                    bool value = (bool)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(int))
                {
                    int value = (int)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(float))
                {
                    float value = (float)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(string))
                {
                    string value = (string)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
            }
        }

        if (system is IDebuggableEx)
        {
            ((IDebuggableEx)system).OnPreviousValuesLoaded();
        }
    }
Beispiel #7
0
    private void RenderSystemRecursive(IDebuggable system)
    {
        SystemInfo info    = _gameSystems[system];
        bool       isDirty = false;

        GUILayout.BeginVertical();

        if (GUILayout.Button(new GUIContent(info.systemName, info.IsShowing ? toggleOn : toggleOff), "Toggle"))
        {
            info.ToggleIsShowing();
        }

        if (info.IsShowing)
        {
            GUI.skin.toggle.fontSize = (int)(fontSize * 0.9f);
            GUI.skin.label.fontSize  = (int)(fontSize * 0.9f);
            GUI.skin.button.fontSize = (int)(fontSize * 0.9f);

            // Show all SystemInfo bools
            foreach (FieldInfo field in typeof(SystemInfo).GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!DebuggerUtils.CanDisplayField(field))
                {
                    continue;
                }

                // Only way to make a tab...
                GUILayout.BeginHorizontal();
                GUILayout.Space(tabSize);
                if (!System.Object.ReferenceEquals(system, this) && !(system == _log && (field.Name == "showLog")) && field.Name != "systemName")
                {
                    bool oldValue = (bool)field.GetValue(info);
                    bool newValue = Toggle(oldValue, DebuggerUtils.FormatFieldName(field.Name));

                    // Save if is changed
                    if (oldValue != newValue)
                    {
                        DebuggerUtils.SaveVariable(GetSystemPrefix(system) + "_" + field.Name, newValue);
                        isDirty = true;
                    }

                    field.SetValue(info, newValue);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.BeginVertical();

            // Draw public bools of the class
            foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(tabSize);

                if (DebuggerUtils.CanDisplayField(field))
                {
                    object oldValue = field.GetValue(system);
                    object newValue;

                    if (field.FieldType == typeof(bool))
                    {
                        newValue = Toggle((bool)oldValue, DebuggerUtils.FormatFieldName(field.Name));
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(DebuggerUtils.FormatFieldName(field.Name));
                        newValue = GUILayout.TextField(oldValue.ToString());
                        GUILayout.EndHorizontal();

                        try
                        {
                            if (field.FieldType == typeof(float))
                            {
                                newValue = float.Parse(newValue.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture);
                            }
                            else if (field.FieldType == typeof(int))
                            {
                                newValue = int.Parse(newValue.ToString());
                            }
                        } catch
                        {
                            newValue = oldValue;
                        }
                    }

                    // If value changed
                    if (!newValue.Equals(oldValue))
                    {
                        field.SetValue(system, newValue);
                        DebuggerUtils.SaveVariable(GetSystemPrefix(system) + "_" + field.Name, newValue);
                        isDirty = true;

                        if (system is IDebuggableEx)
                        {
                            ((IDebuggableEx)system).OnValueChanged(field, oldValue, newValue);
                        }
                    }
                }

                GUILayout.EndHorizontal();
            }

            // If the system's designer wants to add anything
            GUILayout.BeginHorizontal();
            GUILayout.Space(tabSize);
            system.OnDebugPanelGUI();
            GUILayout.EndHorizontal();

            GUI.skin.toggle.fontSize = fontSize;
            GUI.skin.label.fontSize  = fontSize;
            GUI.skin.button.fontSize = fontSize;

            if (!info.IsUnique && GUILayout.Button("Save Instance's Settings As Default"))
            {
                DebuggerUtils.SaveDefaultSettings(system, GetSystemPrefix(system));
            }

            // Draw sub-systems
            if (info.subSystems != null && info.subSystems.Count > 0)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(tabSize);

                GUILayout.BeginVertical();

                foreach (IDebuggable subSystem in info.subSystems)
                {
                    if (_gameSystems[subSystem].ShowInDebugger)
                    {
                        RenderSystemRecursive(subSystem);
                    }
                }

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }

        GUILayout.EndVertical();

        if (isDirty)
        {
            PlayerPrefs.Save();
        }
    }
Beispiel #8
0
    public void RegisterSystem(IDebuggable system, string name = null, IDebuggable parent = null, bool isUnique = false, bool showInDebugger = true)
    {
        if (_gameSystems.ContainsKey(system))
        {
            return;
        }

        if (isUnique && GetSystemFromName(name) != null)
        {
            Log(this, "The system name " + name + " already exists. Please find another name or use RegisterInstance.", LogType.Error);
            return;
        }
        if (!isUnique)
        {
            IDebuggable otherSys = GetSystemFromName(name);
            if (otherSys != null && _gameSystems[otherSys].IsUnique)
            {
                Log(this, "The instance name " + name + " is already used by a system. Please find another name.", LogType.Error);
                return;
            }
        }

        SystemInfo info = new SystemInfo(isUnique, showInDebugger);

        // If name is null, default to type name
        if (name == null)
        {
            name = system.GetType().Name;
        }
        info.systemName = name;

        // If parent is not null, check if it exists;
        // if it doesn't, default to null
        if (parent != null)
        {
            if (!_gameSystems.ContainsKey(parent))
            {
                parent = null;
                Log(this, "Specified parent of type " + parent.GetType().Name + " is not a registered system; defaulted to null", LogType.Warning);
            }
            else
            {
                if (_gameSystems[parent].subSystems == null)
                {
                    _gameSystems[parent].subSystems = new List <IDebuggable>();
                }
                _gameSystems[parent].subSystems.Add(system);
            }
        }
        info.parent = parent;

        // If non-sub system, create list of subsystems
        if (parent == null)
        {
            info.subSystems = new List <IDebuggable>();
        }

        _gameSystems.Add(system, info);

        // Load default settings from PlayerPrefs
        DebuggerUtils.LoadSettings(system, info, GetSystemPrefix(system));
    }
 public void AttachDebuggerTo(IDebuggable debuggable)
 {
     debuggable.setDebugger(this);
     Debug(this, "Attached debugger to " + debuggable.GetType().ToString());
 }
 public void AttachDebuggerTo(IDebuggable debuggable)
 {
     debuggable.setDebugger(this);
     Debug(this, "Attached debugger to " + debuggable.GetType().ToString());
 }