Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Hygge v1.4.0
Hygge.dll
Decompiled 7 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; using Valheim.SettingsGui; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Hygge")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Hygge")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e57e6cf6-5849-4472-8848-85950388f318")] [assembly: AssemblyFileVersion("1.4.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.4.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Hygge { public static class ComfortPanelManager { private static Piece _lastUpdatePiece; private static float _lastUpdateTime; public static ComfortPanel ComfortPanel { get; private set; } public static bool HasValidPanel() { if (ComfortPanel != null) { return Object.op_Implicit((Object)(object)ComfortPanel.Panel); } return false; } public static void ToggleOn(Piece piece) { if (!HasValidPanel() && !InstantiateComfortPanel(piece)) { Hygge.LogWarning("Failed to instantiate ComfortPanel."); } else { ComfortPanel.Panel.SetActive(true); } } public static void ToggleOff() { if (HasValidPanel()) { ComfortPanel.Panel.SetActive(false); } } public static void Update(Piece piece) { float time = Time.time; if (!((Object)(object)_lastUpdatePiece == (Object)(object)piece) || !(time - _lastUpdateTime < 0.5f)) { _lastUpdatePiece = piece; _lastUpdateTime = time; ComfortPanel.Update(piece); } } public static void DestroyPanel() { if (HasValidPanel()) { ComfortPanel.Panel.SetActive(false); Object.Destroy((Object)(object)ComfortPanel.Panel); ComfortPanel = null; } } private static bool InstantiateComfortPanel(Piece piece) { ComfortPanel = ComfortPanel.CreateComfortPanel(); if (ComfortPanel == null) { return false; } ComfortPanel.Update(piece); return true; } } public sealed class LabelValueRow { public GameObject Container { get; private set; } public RectTransform RectTransform { get; private set; } public TextMeshProUGUI Label { get; private set; } public TextMeshProUGUI Value { get; private set; } public LabelValueRow(Transform parentTransform) { Container = CreateContainer(parentTransform); RectTransform = Container.GetComponent<RectTransform>(); Label = CreateLabel((Transform)(object)RectTransform); Value = CreateValue((Transform)(object)RectTransform); } private static GameObject CreateContainer(Transform parentTransform) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown GameObject val = new GameObject("LabelValueRow", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parentTransform, false); val.GetComponent<RectTransform>().SetAnchorMin(Vector2.up).SetAnchorMax(Vector2.one) .SetPivot(new Vector2(0.5f, 1f)) .SetPosition(Vector2.zero) .SetSizeDelta(new Vector2(-20f, 30f)); return val; } private static TextMeshProUGUI CreateLabel(Transform parentTransform) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI obj = UIBuilder.CreateTMPLabel(parentTransform); ((TMP_Text)obj).rectTransform.SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one).SetPivot(new Vector2(0f, 0.5f)) .SetPosition(Vector2.zero) .SetSizeDelta(Vector2.zero); ((TMP_Text)obj.SetAlignment<TextMeshProUGUI>((TextAlignmentOptions)513).SetFontSize<TextMeshProUGUI>(18f)).SetText("Label"); return obj; } private static TextMeshProUGUI CreateValue(Transform parentTransform) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI obj = UIBuilder.CreateTMPLabel(parentTransform); ((TMP_Text)obj).rectTransform.SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one).SetPivot(new Vector2(0f, 0.5f)) .SetPosition(Vector2.zero) .SetSizeDelta(Vector2.zero); ((TMP_Text)obj.SetAlignment<TextMeshProUGUI>((TextAlignmentOptions)516).SetFontSize<TextMeshProUGUI>(18f)).SetText("Value"); return obj; } } [BepInPlugin("bruce.valheim.comfymods.hygge", "Hygge", "1.4.0")] public sealed class Hygge : BaseUnityPlugin { public const string PluginGuid = "bruce.valheim.comfymods.hygge"; public const string PluginName = "Hygge"; public const string PluginVersion = "1.4.0"; private static ManualLogSource _logger; private void Awake() { _logger = ((BaseUnityPlugin)this).Logger; PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruce.valheim.comfymods.hygge"); } public static void LogWarning(object obj) { _logger.LogWarning((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } } [HarmonyPatch(typeof(Hud))] public class HudPatch { [HarmonyPostfix] [HarmonyPatch("SetupPieceInfo")] private static void SetupPieceInfoPostfix(Hud __instance, Piece piece) { if (PluginConfig.IsModEnabled.Value) { ProcessPieceInfo(piece, __instance.m_hoveredPiece, Player.m_localPlayer); } } private static void ProcessPieceInfo(Piece piece, Piece hoveredPiece, Player player) { Piece val = default(Piece); if (Object.op_Implicit((Object)(object)piece) && piece.m_comfort == 0) { ComfortPanelManager.ToggleOff(); } else if (Object.op_Implicit((Object)(object)hoveredPiece) && hoveredPiece.m_comfort != 0) { ComfortPanelManager.ToggleOn(hoveredPiece); ComfortPanelManager.Update(hoveredPiece); } else if (Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)player.m_placementGhost) && player.m_placementGhost.TryGetComponent<Piece>(ref val) && val.m_comfort != 0) { ComfortPanelManager.ToggleOn(val); ComfortPanelManager.Update(val); } else { ComfortPanelManager.ToggleOff(); } } [HarmonyPostfix] [HarmonyPatch("OnDestroy")] private static void OnDestroyPostfix(Hud __instance) { if (PluginConfig.IsModEnabled.Value) { ComfortPanelManager.DestroyPanel(); } } } [HarmonyPatch(typeof(GraphicsSettings))] internal static class SettingsPatch { [HarmonyPostfix] [HarmonyPatch("ApplyResolution")] public static void ApplyResolutionPostfix(GraphicsSettings __instance) { if (PluginConfig.IsModEnabled.Value) { ComfortPanelManager.DestroyPanel(); } } } public static class PluginConfig { public static ConfigEntry<bool> IsModEnabled { get; private set; } public static void BindConfig(ConfigFile config) { IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); IsModEnabled.OnSettingChanged<bool>(ComfortPanelManager.ToggleOff); } } public sealed class ComfortPanel { public const int MaxComfortSearchRadius = 10; public GameObject Panel { get; private set; } public RectTransform RectTransform { get; private set; } public TextMeshProUGUI Title { get; private set; } public LabelValueRow ComfortGroupRow { get; private set; } public LabelValueRow ComfortValueRow { get; private set; } public LabelValueRow NearestSimilarRow { get; private set; } public static ComfortPanel CreateComfortPanel() { Transform val = Hud.instance.m_buildHud.transform.Find("SelectedInfo"); if (!Object.op_Implicit((Object)(object)val)) { Hygge.LogWarning("Failed to find 'SelectedInfo' transform in build hud."); return null; } return new ComfortPanel(val); } public ComfortPanel(Transform parentTransform) { Panel = CreatePanel(parentTransform); RectTransform = Panel.GetComponent<RectTransform>(); Title = CreateTitle((Transform)(object)RectTransform); ComfortGroupRow = CreateComfortGroupRow((Transform)(object)RectTransform); ComfortValueRow = CreateComfortValueRow((Transform)(object)RectTransform); NearestSimilarRow = CreateNearestSimilarRow((Transform)(object)RectTransform); } private static GameObject CreatePanel(Transform parentTransform) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown GameObject val = new GameObject("ComfortPanel", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parentTransform, false); ImageExtensions.SetColor<Image>(val.AddComponent<Image>().SetSprite<Image>(UIResources.GetSprite("Background")).SetType<Image>((Type)1), new Color(0f, 0f, 0f, 0.5f)); val.GetComponent<RectTransform>().SetAnchorMin(Vector2.right).SetAnchorMax(Vector2.one) .SetPivot(Vector2.zero) .SetPosition(new Vector2(2.5f, 0f)) .SetSizeDelta(new Vector2(175f, 0f)); val.AddComponent<CanvasGroup>().SetBlocksRaycasts(blocksRaycasts: false).SetAlpha(1f); return val; } private static TextMeshProUGUI CreateTitle(Transform parentTransform) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI obj = UIBuilder.CreateTMPHeaderLabel(parentTransform); ((Object)obj).name = "Title"; ((TMP_Text)obj.SetAlignment<TextMeshProUGUI>((TextAlignmentOptions)258).SetFontSize<TextMeshProUGUI>(24f)).SetText("Comfort"); ((TMP_Text)obj).rectTransform.SetAnchorMin(Vector2.up).SetAnchorMax(Vector2.one).SetPivot(new Vector2(0.5f, 1f)) .SetPosition(new Vector2(0f, -2.5f)) .SetSizeDelta(new Vector2(-20f, 40f)); return obj; } private static LabelValueRow CreateComfortGroupRow(Transform parentTransform) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) LabelValueRow labelValueRow = new LabelValueRow(parentTransform); ((Object)labelValueRow.Container).name = "ComfortGroup"; labelValueRow.RectTransform.SetPosition(new Vector2(0f, -40f)); ((TMP_Text)labelValueRow.Label).SetText("Group"); return labelValueRow; } private static LabelValueRow CreateComfortValueRow(Transform parentTransform) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) LabelValueRow labelValueRow = new LabelValueRow(parentTransform); ((Object)labelValueRow.Container).name = "ComfortValue"; labelValueRow.RectTransform.SetPosition(new Vector2(0f, -70f)); ((TMP_Text)labelValueRow.Label).SetText("Value"); return labelValueRow; } private static LabelValueRow CreateNearestSimilarRow(Transform parentTransform) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) LabelValueRow labelValueRow = new LabelValueRow(parentTransform); ((Object)labelValueRow.Container).name = "NearestSimilar"; labelValueRow.RectTransform.SetPosition(new Vector2(0f, -100f)); ((TMP_Text)labelValueRow.Label).SetText("Nearest"); return labelValueRow; } public void Update(Piece piece) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)TextMeshProExtensions.SetColor<TextMeshProUGUI>(ComfortGroupRow.Value, GetColorForComfortGroup(piece.m_comfortGroup))).SetText($"{piece.m_comfortGroup:F}"); ((TMP_Text)TextMeshProExtensions.SetColor<TextMeshProUGUI>(ComfortValueRow.Value, GetColorForComfortValue(piece.m_comfortGroup, piece.m_comfort))).SetText($"{piece.m_comfort}"); if (TryGetNearestSimilarPiece(piece, out var _, out var nearestDistance)) { ((TMP_Text)NearestSimilarRow.Value).SetText($"{nearestDistance:F1}m"); } else { ((TMP_Text)NearestSimilarRow.Value).SetText("None"); } } private bool TryGetNearestSimilarPiece(Piece piece, out Piece nearestSimilarPiece, out float nearestDistance) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)Player.m_localPlayer).transform.position; GameObject placementGhost = Player.m_localPlayer.m_placementGhost; string name = piece.m_name; ComfortGroup comfortGroup = piece.m_comfortGroup; nearestSimilarPiece = null; nearestDistance = 10f; foreach (Piece s_allComfortPiece in Piece.s_allComfortPieces) { if (s_allComfortPiece.m_comfortGroup == comfortGroup && !((Object)(object)((Component)s_allComfortPiece).gameObject == (Object)(object)placementGhost) && ((int)s_allComfortPiece.m_comfortGroup != 0 || !(s_allComfortPiece.m_name != name))) { float num = Vector3.Distance(position, ((Component)s_allComfortPiece).transform.position); if (num < nearestDistance) { nearestDistance = num; nearestSimilarPiece = s_allComfortPiece; } } } return Object.op_Implicit((Object)(object)nearestSimilarPiece); } public static Color GetColorForComfortGroup(ComfortGroup comfortGroup) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected I4, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) return (Color)((int)comfortGroup switch { 1 => new Color(0.545f, 0f, 0f), 6 => Color.blue, 3 => new Color(0.5f, 0f, 0.5f), 5 => Color.yellow, 2 => new Color(0.855f, 0.647f, 0.125f), 4 => new Color(0.663f, 0.663f, 0.663f), 0 => Color.cyan, _ => Color.white, }); } public static Color GetColorForComfortValue(ComfortGroup comfortGroup, int comfort) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected I4, but got Unknown //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) if ((int)comfortGroup == 0) { return Color.white; } int num = (int)comfortGroup switch { 1 => 2, 6 => 1, 3 => 1, 5 => 2, 2 => 2, 4 => 3, 0 => 6, _ => 0, }; if (num <= 0) { return Color.white; } if (comfort >= num) { return Color.green; } if (comfort == 1) { return Color.red; } return new Color(1f, 0.55f, 0f); } } } namespace ComfyLib { public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } } public static class ObjectExtensions { public static T FirstByNameOrThrow<T>(this IEnumerable<T> unityObjects, string name) where T : Object { foreach (T unityObject in unityObjects) { if (((Object)unityObject).name == name) { return unityObject; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref<T>(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } public static class UIBuilder { public static TextMeshProUGUI CreateTMPLabel(Transform parentTransform) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI obj = Object.Instantiate<TextMeshProUGUI>(UnifiedPopup.instance.bodyText, parentTransform); ((Object)obj).name = "Label"; ((TMP_Text)TextMeshProExtensions.SetColor<TextMeshProUGUI>(obj.SetEnableAutoSizing<TextMeshProUGUI>(enableAutoSizing: false).SetRichText<TextMeshProUGUI>(richText: true).SetOverflowMode<TextMeshProUGUI>((TextOverflowModes)0) .SetTextWrappingMode<TextMeshProUGUI>((TextWrappingModes)0) .SetFontSize<TextMeshProUGUI>(16f), Color.white)).SetText(string.Empty); return obj; } public static TextMeshProUGUI CreateTMPHeaderLabel(Transform parentTransform) { TextMeshProUGUI obj = Object.Instantiate<TextMeshProUGUI>(UnifiedPopup.instance.headerText, parentTransform, false); ((Object)obj).name = "Label"; ((TMP_Text)obj.SetEnableAutoSizing<TextMeshProUGUI>(enableAutoSizing: false).SetRichText<TextMeshProUGUI>(richText: true).SetOverflowMode<TextMeshProUGUI>((TextOverflowModes)0) .SetTextWrappingMode<TextMeshProUGUI>((TextWrappingModes)0) .SetFontSize<TextMeshProUGUI>(32f)).SetText(string.Empty); return obj; } } public static class CanvasGroupExtensions { public static CanvasGroup SetAlpha(this CanvasGroup canvasGroup, float alpha) { canvasGroup.alpha = alpha; return canvasGroup; } public static CanvasGroup SetBlocksRaycasts(this CanvasGroup canvasGroup, bool blocksRaycasts) { canvasGroup.blocksRaycasts = blocksRaycasts; return canvasGroup; } } public static class ColorExtensions { public static Color SetAlpha(this Color color, float alpha) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) color.a = alpha; return color; } } public static class ContentSizeFitterExtensions { public static ContentSizeFitter SetHorizontalFit(this ContentSizeFitter fitter, FitMode fitMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) fitter.horizontalFit = fitMode; return fitter; } public static ContentSizeFitter SetVerticalFit(this ContentSizeFitter fitter, FitMode fitMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) fitter.verticalFit = fitMode; return fitter; } } public static class LayoutGroupExtensions { public static T SetChildAlignment<T>(this T layoutGroup, TextAnchor alignment) where T : HorizontalOrVerticalLayoutGroup { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((LayoutGroup)(object)layoutGroup).childAlignment = alignment; return layoutGroup; } public static T SetChildControl<T>(this T layoutGroup, bool? width = null, bool? height = null) where T : HorizontalOrVerticalLayoutGroup { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlWidth = width.Value; } if (height.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlHeight = height.Value; } return layoutGroup; } public static T SetChildForceExpand<T>(this T layoutGroup, bool? width = null, bool? height = null) where T : HorizontalOrVerticalLayoutGroup { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandWidth = width.Value; } if (height.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandHeight = height.Value; } return layoutGroup; } public static T SetPadding<T>(this T layoutGroup, int? left = null, int? right = null, int? top = null, int? bottom = null) where T : HorizontalOrVerticalLayoutGroup { if (!left.HasValue && !right.HasValue && !top.HasValue && !bottom.HasValue) { throw new ArgumentException("Value for left, right, top or bottom must be provided."); } if (left.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.left = left.Value; } if (right.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.right = right.Value; } if (top.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.top = top.Value; } if (bottom.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.bottom = bottom.Value; } return layoutGroup; } public static T SetSpacing<T>(this T layoutGroup, float spacing) where T : HorizontalOrVerticalLayoutGroup { ((HorizontalOrVerticalLayoutGroup)layoutGroup).spacing = spacing; return layoutGroup; } } public static class ImageExtensions { public static T SetColor<T>(this T image, Color color) where T : Image { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Graphic)(object)image).color = color; return image; } public static T SetFillAmount<T>(this T image, float amount) where T : Image { ((Image)image).fillAmount = amount; return image; } public static T SetFillCenter<T>(this T image, bool fillCenter) where T : Image { ((Image)image).fillCenter = fillCenter; return image; } public static T SetFillMethod<T>(this T image, FillMethod fillMethod) where T : Image { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Image)image).fillMethod = fillMethod; return image; } public static T SetFillOrigin<T>(this T image, OriginHorizontal origin) where T : Image { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected I4, but got Unknown ((Image)image).fillOrigin = (int)origin; return image; } public static T SetFillOrigin<T>(this T image, OriginVertical origin) where T : Image { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected I4, but got Unknown ((Image)image).fillOrigin = (int)origin; return image; } public static T SetMaskable<T>(this T image, bool maskable) where T : Image { ((MaskableGraphic)(object)image).maskable = maskable; return image; } public static T SetMaterial<T>(this T image, Material material) where T : Image { ((Graphic)(object)image).material = material; return image; } public static T SetPixelsPerUnitMultiplier<T>(this T image, float pixelsPerUnitMultiplier) where T : Image { ((Image)image).pixelsPerUnitMultiplier = pixelsPerUnitMultiplier; return image; } public static T SetPreserveAspect<T>(this T image, bool preserveAspect) where T : Image { ((Image)image).preserveAspect = preserveAspect; return image; } public static T SetRaycastTarget<T>(this T image, bool raycastTarget) where T : Image { ((Graphic)(object)image).raycastTarget = raycastTarget; return image; } public static T SetSprite<T>(this T image, Sprite sprite) where T : Image { ((Image)image).sprite = sprite; return image; } public static T SetType<T>(this T image, Type type) where T : Image { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Image)image).type = type; return image; } } public static class LayoutElementExtensions { public static T SetFlexible<T>(this T layoutElement, float? width = null, float? height = null) where T : LayoutElement { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((LayoutElement)layoutElement).flexibleWidth = width.Value; } if (height.HasValue) { ((LayoutElement)layoutElement).flexibleHeight = height.Value; } return layoutElement; } public static T SetIgnoreLayout<T>(this T layoutElement, bool ignoreLayout) where T : LayoutElement { ((LayoutElement)layoutElement).ignoreLayout = ignoreLayout; return layoutElement; } public static T SetMinimum<T>(this T layoutElement, float? width = null, float? height = null) where T : LayoutElement { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((LayoutElement)layoutElement).minWidth = width.Value; } if (height.HasValue) { ((LayoutElement)layoutElement).minHeight = height.Value; } return layoutElement; } public static T SetPreferred<T>(this T layoutElement, float? width = null, float? height = null) where T : LayoutElement { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((LayoutElement)layoutElement).preferredWidth = width.Value; } if (height.HasValue) { ((LayoutElement)layoutElement).preferredHeight = height.Value; } return layoutElement; } } public static class RectMask2DExtensions { public static T SetPadding<T>(this T rectMask, Vector4 padding) where T : RectMask2D { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((RectMask2D)rectMask).padding = padding; return rectMask; } public static T SetSoftness<T>(this T rectMask, Vector2Int softness) where T : RectMask2D { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((RectMask2D)rectMask).softness = softness; return rectMask; } } public static class RectTransformExtensions { public static RectTransform SetAnchorMin(this RectTransform rectTransform, Vector2 anchorMin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchorMin = anchorMin; return rectTransform; } public static RectTransform SetAnchorMax(this RectTransform rectTransform, Vector2 anchorMax) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchorMax = anchorMax; return rectTransform; } public static RectTransform SetPivot(this RectTransform rectTransform, Vector2 pivot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.pivot = pivot; return rectTransform; } public static RectTransform SetPosition(this RectTransform rectTransform, Vector2 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchoredPosition = position; return rectTransform; } public static RectTransform SetSizeDelta(this RectTransform rectTransform, Vector2 sizeDelta) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.sizeDelta = sizeDelta; return rectTransform; } } public static class ScrollbarExtensions { public static T SetDirection<T>(this T scrollbar, Direction direction) where T : Scrollbar { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Scrollbar)scrollbar).direction = direction; return scrollbar; } public static T SetHandleRect<T>(this T scrollbar, RectTransform handleRect) where T : Scrollbar { ((Scrollbar)scrollbar).handleRect = handleRect; return scrollbar; } } public static class SelectableExtensions { public static T SetColors<T>(this T selectable, ColorBlock colors) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).colors = colors; return selectable; } public static T SetImage<T>(this T selectable, Image image) where T : Selectable { ((Selectable)selectable).image = image; return selectable; } public static T SetInteractable<T>(this T selectable, bool interactable) where T : Selectable { ((Selectable)selectable).interactable = interactable; return selectable; } public static T SetSpriteState<T>(this T selectable, SpriteState spriteState) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).spriteState = spriteState; return selectable; } public static T SetTargetGraphic<T>(this T selectable, Graphic graphic) where T : Selectable { ((Selectable)selectable).targetGraphic = graphic; return selectable; } public static T SetTransition<T>(this T selectable, Transition transition) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).transition = transition; return selectable; } public static T SetNavigationMode<T>(this T selectable, Mode mode) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Navigation navigation = ((Selectable)selectable).navigation; ((Navigation)(ref navigation)).mode = mode; ((Selectable)selectable).navigation = navigation; return selectable; } } public static class SliderExtensions { public static T SetDirection<T>(this T slider, Direction direction) where T : Slider { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Slider)slider).direction = direction; return slider; } public static T SetFillRect<T>(this T slider, RectTransform fillRect) where T : Slider { ((Slider)slider).fillRect = fillRect; return slider; } public static T SetHandleRect<T>(this T slider, RectTransform handleRect) where T : Slider { ((Slider)slider).handleRect = handleRect; return slider; } public static T SetMaxValue<T>(this T slider, float maxValue) where T : Slider { ((Slider)slider).maxValue = maxValue; return slider; } public static T SetMinValue<T>(this T slider, float minValue) where T : Slider { ((Slider)slider).minValue = minValue; return slider; } public static T SetWholeNumbers<T>(this T slider, bool wholeNumbers) where T : Slider { ((Slider)slider).wholeNumbers = wholeNumbers; return slider; } } public static class ScrollRectExtensions { public static T SetContent<T>(this T scrollRect, RectTransform content) where T : ScrollRect { ((ScrollRect)scrollRect).content = content; return scrollRect; } public static T SetHorizontal<T>(this T scrollRect, bool horizontal) where T : ScrollRect { ((ScrollRect)scrollRect).horizontal = horizontal; return scrollRect; } public static T SetMovementType<T>(this T scrollRect, MovementType movementType) where T : ScrollRect { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((ScrollRect)scrollRect).movementType = movementType; return scrollRect; } public static T SetScrollSensitivity<T>(this T scrollRect, float sensitivity) where T : ScrollRect { ((ScrollRect)scrollRect).scrollSensitivity = sensitivity; return scrollRect; } public static T SetVertical<T>(this T scrollRect, bool vertical) where T : ScrollRect { ((ScrollRect)scrollRect).vertical = vertical; return scrollRect; } public static T SetVerticalScrollbar<T>(this T scrollRect, Scrollbar verticalScrollbar) where T : ScrollRect { ((ScrollRect)scrollRect).verticalScrollbar = verticalScrollbar; return scrollRect; } public static T SetVerticalScrollPosition<T>(this T scrollRect, float position) where T : ScrollRect { ((ScrollRect)scrollRect).verticalNormalizedPosition = position; return scrollRect; } public static T SetVerticalScrollbarVisibility<T>(this T scrollRect, ScrollbarVisibility visibility) where T : ScrollRect { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((ScrollRect)scrollRect).verticalScrollbarVisibility = visibility; return scrollRect; } public static T SetViewport<T>(this T scrollRect, RectTransform viewport) where T : ScrollRect { ((ScrollRect)scrollRect).viewport = viewport; return scrollRect; } } public static class TextMeshProExtensions { public static T SetAlignment<T>(this T tmpText, TextAlignmentOptions alignment) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).alignment = alignment; return tmpText; } public static T SetCharacterSpacing<T>(this T tmpText, float characterSpacing) where T : TMP_Text { ((TMP_Text)tmpText).characterSpacing = characterSpacing; return tmpText; } public static T SetColor<T>(this T tmpText, Color color) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Graphic)(object)tmpText).color = color; return tmpText; } public static T SetEnableAutoSizing<T>(this T tmpText, bool enableAutoSizing) where T : TMP_Text { ((TMP_Text)tmpText).enableAutoSizing = enableAutoSizing; return tmpText; } public static T SetFont<T>(this T tmpText, TMP_FontAsset font) where T : TMP_Text { ((TMP_Text)tmpText).font = font; return tmpText; } public static T SetFontSize<T>(this T tmpText, float fontSize) where T : TMP_Text { ((TMP_Text)tmpText).fontSize = fontSize; return tmpText; } public static T SetFontMaterial<T>(this T tmpText, Material fontMaterial) where T : TMP_Text { ((TMP_Text)tmpText).fontMaterial = fontMaterial; return tmpText; } public static T SetLineSpacing<T>(this T tmpText, float lineSpacing) where T : TMP_Text { ((TMP_Text)tmpText).lineSpacing = lineSpacing; return tmpText; } public static T SetMargin<T>(this T tmpText, Vector4 margin) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).margin = margin; return tmpText; } public static T SetOverflowMode<T>(this T tmpText, TextOverflowModes overflowMode) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).overflowMode = overflowMode; return tmpText; } public static T SetRichText<T>(this T tmpText, bool richText) where T : TMP_Text { ((TMP_Text)tmpText).richText = richText; return tmpText; } public static T SetTextWrappingMode<T>(this T tmpText, TextWrappingModes textWrappingMode) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).textWrappingMode = textWrappingMode; return tmpText; } } public static class Texture2DExtensions { public static Texture2D SetFilterMode(this Texture2D texture, FilterMode filterMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((Texture)texture).filterMode = filterMode; return texture; } public static Texture2D SetWrapMode(this Texture2D texture, TextureWrapMode wrapMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((Texture)texture).wrapMode = wrapMode; return texture; } } public static class ToggleExtensions { public static T SetGraphic<T>(this T toggle, Graphic graphic) where T : Toggle { ((Toggle)toggle).graphic = graphic; return toggle; } public static T SetIsOn<T>(this T toggle, bool isOn) where T : Toggle { ((Toggle)toggle).isOn = isOn; return toggle; } public static T SetToggleTransition<T>(this T toggle, ToggleTransition toggleTransition) where T : Toggle { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) ((Toggle)toggle).toggleTransition = toggleTransition; return toggle; } } public static class UIResources { public static readonly ResourceCache<Sprite> SpriteCache = new ResourceCache<Sprite>(); public static readonly ResourceCache<Material> MaterialCache = new ResourceCache<Material>(); public static Sprite GetSprite(string spriteName) { return SpriteCache.GetResource(spriteName); } public static Material GetMaterial(string materialName) { return MaterialCache.GetResource(materialName); } } public sealed class ResourceCache<T> where T : Object { private readonly Dictionary<string, T> _cache = new Dictionary<string, T>(); public T GetResource(string resourceName) { if (!_cache.TryGetValue(resourceName, out var value)) { value = Resources.FindObjectsOfTypeAll<T>().FirstByNameOrThrow(resourceName); _cache[resourceName] = value; } return value; } } }