using GadgetCore.API; using GadgetCore.API.ConfigMenu; using System; using System.Linq; using UnityEngine; using UnityEngine.SceneManagement; namespace VanitySlots { [Gadget("VanitySlots", RequiredOnClients: false)] public class VanitySlots : Gadget { public const string MOD_VERSION = "1.2"; // Set this to the version of your mod. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file. public override IGadgetConfigMenu GetConfigMenu() { return null; } public override string GetModDescription() { return "A mod that adds vanity slots to the players inventory."; } protected override void Initialize() { Logger.Log("Vanity Slots v" + Info.Mod.Version); Core.logger = Logger; if (Environment.GetCommandLineArgs().Any((string x) => x == "-batchmode")) Logger.Log("Starting on no ui server"); SceneManager.sceneLoaded += OnSceneLoaded; } internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.buildIndex == 1) { try { var storageMenu = GameObject.Find("Main Camera").transform.Find("inventoryMain").gameObject; var newSlots = UnityEngine.Object.Instantiate(storageMenu).transform.GetChild(0).GetChild(1).gameObject; Component.DestroyImmediate(newSlots.GetComponent()); newSlots.transform.SetParent(storageMenu.transform); newSlots.name = "inventoryMainVanitySlots"; newSlots.transform.localPosition = new Vector3(0, 0, 0); newSlots.transform.localScale = new Vector3(1, 1, 1); newSlots.SetActive(true); newSlots.GetComponent().material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("inventoryMainVanitySlots.png") }; CreateSlot(storageMenu, 0); CreateSlot(storageMenu, 1); CreateSlot(storageMenu, 2); } catch (System.Exception e) { Core.logger.Log(e.Message); } } } private static void CreateSlot(GameObject menu, int id) { var originalSlot = menu.transform.Find("" + (6 + 6 * id)); var slot = UnityEngine.Object.Instantiate(originalSlot, originalSlot.transform.parent).gameObject; slot.name = "vanity_slot_" + id; slot.layer = 0; slot.transform.SetParent(menu.transform); slot.transform.localPosition = originalSlot.transform.localPosition + new Vector3(-0.1495f, 0, 0); Core.itemStore.SetSlotGameObject(id, slot); Core.itemStore.UpdateUI(); } } }