StationObscurum/Assets/FishNet/Runtime/Editor/Configuring/SettingsProvider.cs

87 lines
2.9 KiB
C#

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using FishNet.Configuring;
using UnitySettingsProviderAttribute = UnityEditor.SettingsProviderAttribute;
using UnitySettingsProvider = UnityEditor.SettingsProvider;
using System.Collections.Generic;
namespace FishNet.Configuring.Editing
{
internal static class SettingsProvider
{
private static Vector2 _scrollView;
[UnitySettingsProvider]
private static UnitySettingsProvider Create()
{
return new UnitySettingsProvider("Project/Fish-Networking/Configuration", SettingsScope.Project)
{
label = "Configuration",
guiHandler = OnGUI,
keywords = new string[]
{
"Fish",
"Networking",
"Configuration",
},
};
}
private static void OnGUI(string searchContext)
{
ConfigurationData configuration = Configuration.LoadConfigurationData();
if (configuration == null)
{
EditorGUILayout.HelpBox("Unable to load configuration data.", MessageType.Error);
return;
}
EditorGUI.BeginChangeCheck();
GUIStyle scrollViewStyle = new GUIStyle()
{
padding = new RectOffset(10, 10, 10, 10),
};
_scrollView = GUILayout.BeginScrollView(_scrollView, scrollViewStyle);
EditorGUILayout.BeginHorizontal();
GUIStyle toggleStyle = new GUIStyle(EditorStyles.toggle)
{
richText = true,
};
configuration.CodeStripping.StripReleaseBuilds = GUILayout.Toggle(configuration.CodeStripping.StripReleaseBuilds, $"{ObjectNames.NicifyVariableName(nameof(configuration.CodeStripping.StripReleaseBuilds))} <color=yellow>(Pro Only)</color>", toggleStyle);
EditorGUILayout.EndHorizontal();
if (configuration.CodeStripping.StripReleaseBuilds)
{
EditorGUI.indentLevel++;
//Stripping Method.
List<string> enumStrings = new List<string>();
foreach (string item in System.Enum.GetNames(typeof(StrippingTypes)))
enumStrings.Add(item);
configuration.CodeStripping.StrippingType = EditorGUILayout.Popup($"{ObjectNames.NicifyVariableName(nameof(configuration.CodeStripping.StrippingType))}", (int)configuration.CodeStripping.StrippingType, enumStrings.ToArray());
EditorGUILayout.HelpBox("Development builds will not have code stripped. Additionally, if you plan to run as host disable code stripping.", MessageType.Warning);
EditorGUI.indentLevel--;
}
GUILayout.EndScrollView();
if (EditorGUI.EndChangeCheck()) Configuration.Configurations.Write(true);
}
}
}
#endif