VanitySlots.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using GadgetCore.API;
  2. using GadgetCore.API.ConfigMenu;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7. namespace VanitySlots
  8. {
  9. [Gadget("VanitySlots", RequiredOnClients: false)]
  10. public class VanitySlots : Gadget<VanitySlots>
  11. {
  12. public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
  13. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  14. public override IGadgetConfigMenu GetConfigMenu() { return null; }
  15. public override string GetModDescription()
  16. {
  17. return "A mod that adds vanity slots to the players inventory.";
  18. }
  19. protected override void Initialize()
  20. {
  21. Logger.Log("Vanity Slots v" + Info.Mod.Version);
  22. Core.logger = Logger;
  23. if (Environment.GetCommandLineArgs().Any((string x) => x == "-batchmode"))
  24. Logger.Log("Starting on no ui server");
  25. SceneManager.sceneLoaded += OnSceneLoaded;
  26. }
  27. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  28. {
  29. if (scene.buildIndex == 1)
  30. {
  31. try
  32. {
  33. var storageMenu = GameObject.Find("Main Camera").transform.Find("inventoryMain").gameObject;
  34. var newSlots = UnityEngine.Object.Instantiate(storageMenu).transform.GetChild(0).GetChild(1).gameObject;
  35. Component.DestroyImmediate(newSlots.GetComponent<AnimIcon>());
  36. newSlots.transform.SetParent(storageMenu.transform);
  37. newSlots.name = "inventoryMainVanitySlots";
  38. newSlots.transform.localPosition = new Vector3(0, 0, 0);
  39. newSlots.transform.localScale = new Vector3(1, 1, 1);
  40. newSlots.SetActive(true);
  41. newSlots.GetComponent<Renderer>().material = new Material(Shader.Find("Unlit/Transparent"))
  42. {
  43. mainTexture = GadgetCoreAPI.LoadTexture2D("inventoryMainVanitySlots.png")
  44. };
  45. CreateSlot(storageMenu, 0);
  46. CreateSlot(storageMenu, 1);
  47. CreateSlot(storageMenu, 2);
  48. }
  49. catch (System.Exception e) { Core.logger.Log(e.Message); }
  50. }
  51. }
  52. private static void CreateSlot(GameObject menu, int id)
  53. {
  54. var originalSlot = menu.transform.Find("" + (6 + 6 * id));
  55. var slot = UnityEngine.Object.Instantiate(originalSlot, originalSlot.transform.parent).gameObject;
  56. slot.name = "vanity_slot_" + id;
  57. slot.layer = 0;
  58. slot.transform.SetParent(menu.transform);
  59. slot.transform.localPosition = originalSlot.transform.localPosition + new Vector3(-0.1495f, 0, 0);
  60. Core.itemStore.SetSlotGameObject(id, slot);
  61. Core.itemStore.UpdateUI();
  62. }
  63. }
  64. }