ScrapYard.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using System.Collections.Generic;
  4. namespace ScrapYard
  5. {
  6. [Gadget("ScrapYard")]
  7. public class ScrapYard : Gadget<ScrapYard>
  8. {
  9. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  10. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  11. protected override void LoadConfig()
  12. {
  13. Config.Load();
  14. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  15. if (fileVersion != CONFIG_VERSION)
  16. {
  17. Config.Reset();
  18. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  19. }
  20. Config.Save();
  21. }
  22. public override string GetModDescription()
  23. {
  24. return "A mod that adds a scryp yard planet.";
  25. }
  26. protected override void Initialize()
  27. {
  28. Logger.Log("Scrap Yard v" + Info.Mod.Version);
  29. Core.logger = Logger;
  30. Texture2D texturePlanetIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYard.png");
  31. Texture2D texturePlanetPrevIcon = GadgetCoreAPI.LoadTexture2D("planetScrapYardPrev.png");
  32. Texture2D texturePortalSign = GadgetCoreAPI.LoadTexture2D("signScrapYard.png");
  33. Texture2D textureBG = GadgetCoreAPI.LoadTexture2D("bgScrapYard.png");
  34. Texture2D textureParalex = GadgetCoreAPI.LoadTexture2D("parallax.png");
  35. Texture2D textureParalex0 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png");
  36. Texture2D textureParalex1 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png");
  37. Texture2D textureParalex2 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png");
  38. Texture2D textureParalex3 = GadgetCoreAPI.LoadTexture2D("bScrapYardbg3.png");
  39. Texture2D textureEntrance = GadgetCoreAPI.LoadTexture2D("entranceScrapYard.png");
  40. Texture2D textureSmallSide = GadgetCoreAPI.LoadTexture2D("sideSmallScrapYard.png");
  41. Texture2D textureBigSide = GadgetCoreAPI.LoadTexture2D("sideBigScrapYard.png");
  42. Texture2D textureMid0 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk0.png");
  43. Texture2D textureMid1 = GadgetCoreAPI.LoadTexture2D("midScrapYardChunk1.png");
  44. PlanetInfo scrapYardPlanet = new PlanetInfo(PlanetType.SINGLE, "Scrap Yard", new GadgetCore.Util.Tuple<int, int>[] { new GadgetCore.Util.Tuple<int, int>(1, 100) });
  45. scrapYardPlanet.SetPortalInfo(texturePortalSign, texturePlanetPrevIcon, texturePlanetIcon);
  46. scrapYardPlanet.SetBackgroundInfo(textureParalex, textureParalex0, textureParalex1, textureParalex2, textureParalex3);
  47. scrapYardPlanet.SetTerrainInfo(textureEntrance, textureBG, textureMid0, textureMid1, textureBigSide, textureSmallSide);
  48. scrapYardPlanet.OnGenerateInsideTown += GenerateTown;
  49. scrapYardPlanet.PortalUses = 300;
  50. {
  51. var scrapYardShopBuilding = Object.Instantiate((GameObject)Resources.Load("prop/2501"));
  52. scrapYardShopBuilding.transform.localScale *= 8;
  53. Texture2D texture = GadgetCoreAPI.LoadTexture2D("shopStand.png");
  54. var renderer = scrapYardShopBuilding.GetComponentInChildren<Renderer>();
  55. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  56. {
  57. mainTexture = texture
  58. };
  59. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardShopBuilding", scrapYardShopBuilding);
  60. }
  61. {
  62. var scrapYardMerchant = Object.Instantiate((GameObject)Resources.Load("npc/perceval"));
  63. Texture2D textureBody = GadgetCoreAPI.LoadTexture2D("merchantBody.png");
  64. Texture2D textureHead = GadgetCoreAPI.LoadTexture2D("merchantHead.png");
  65. var gameObjectBody = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane_002");
  66. var rendererBody = gameObjectBody.gameObject.GetComponentInChildren<Renderer>();
  67. rendererBody.material = new Material(Shader.Find("Unlit/Transparent"))
  68. {
  69. mainTexture = textureBody
  70. };
  71. rendererBody.transform.position = new Vector3(0, 0, 0.1f);
  72. var gameObjectHead = scrapYardMerchant.transform.Find("e").Find("perceval").FindChild("Plane");
  73. var rendererHead = gameObjectHead.gameObject.GetComponentInChildren<Renderer>();
  74. rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
  75. {
  76. mainTexture = textureHead
  77. };
  78. Component.DestroyImmediate(scrapYardMerchant.GetComponent<npcTurnScript>());
  79. GadgetCoreAPI.AddCustomResource("prop/ScrapYard/scrapYardMerchant", scrapYardMerchant);
  80. }
  81. scrapYardPlanet.Register("Scrap Yard");
  82. }
  83. private static IEnumerable<GameObject> GenerateTown(Chunk chunk)
  84. {
  85. var list = new List<GameObject>();
  86. list.Add((GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardShopBuilding"), new Vector3(250f, -6f + 0.118f, 0.3f), Quaternion.identity, 0));
  87. list.Add((GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/scrapYardMerchant"), new Vector3(255f, -6f - 0.118f * 12, 0.2f), Quaternion.identity, 0));
  88. return list;
  89. }
  90. }
  91. }