VanitySlots.cs 2.4 KB

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