Beispiel #1
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();
        }
    }