EnginesDeluxe.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using GadgetCore.API;
  2. using GadgetCore.API.ConfigMenu;
  3. using ScrapYard.API;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. namespace EnginesDeluxe
  7. {
  8. [Gadget("EnginesDeluxe", LoadAfter: new string[] { "ScrapYard" }, Dependencies: new string[] { "ScrapYard" })]
  9. public class EnginesDeluxe : Gadget<EnginesDeluxe>
  10. {
  11. public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
  12. public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
  13. protected override void LoadConfig()
  14. {
  15. Config.Load();
  16. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  17. if (fileVersion != CONFIG_VERSION)
  18. {
  19. Config.Reset();
  20. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  21. }
  22. Core.settingStarsEnum = Config.ReadEnum("StarType", StarTypeEnum.NewStarsAndPlanetes, requiresRestart: false, comments: new string[] { "Should the stars on the ship be replaced?" });
  23. Config.Save();
  24. }
  25. public override string GetModDescription()
  26. {
  27. return "A mod that adds some more engines.";
  28. }
  29. protected override void Initialize()
  30. {
  31. Logger.Log("Engines Deluxe v" + Info.Mod.Version);
  32. Core.logger = Logger;
  33. var asset = GadgetCoreAPI.LoadAssetBundle("engine");
  34. { // Part Engine Blue
  35. var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineBlue.prefab"));
  36. engine.name = "engineBlue";
  37. engine.transform.localScale = new Vector3(2, 2, 2);
  38. GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineBlue", engine);
  39. }
  40. { // Part Engine Yellow
  41. var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineYellow.prefab"));
  42. engine.name = "engineYellow";
  43. engine.transform.localScale = new Vector3(2, 2, 2);
  44. GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineYellow", engine);
  45. }
  46. { // Part Engine Red
  47. var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineRed.prefab"));
  48. engine.name = "engineRed";
  49. engine.transform.localScale = new Vector3(2, 2, 2);
  50. GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineRed", engine);
  51. }
  52. { // Part Engine Green
  53. var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineGreen.prefab"));
  54. engine.name = "engineGreen";
  55. engine.transform.localScale = new Vector3(2, 2, 2);
  56. GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineGreen", engine);
  57. }
  58. foreach (var e in ShopPlatform.DefaultBlocks.GetShopPlatformEntries())
  59. {
  60. if (e.ItemID == 2400)
  61. {
  62. ShopPlatform.DefaultBlocks.RemoveShopPlatformEntry(e);
  63. }
  64. }
  65. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cBlueEngineBlock.png", "iBlueEngineBlock.png", "engineBlue", "Plasma Engine", "An engine for a ship.", "BlueEngineBlock"), 7000));
  66. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cYellowEngineBlock.png", "iYellowEngineBlock.png", "engineYellow", "Differential Engine", "An engine for a ship.", "YellowEngineBlock"), 7000));
  67. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateOverrideEngineItem("cRedEngineBlock.png", "iRedEngineBlock.png", "engineRed", "Combustion Engine", "An engine for a ship.", "RedEngineBlock"), 7000));
  68. ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cGreenEngineBlock.png", "iGreenEngineBlock.png", "engineGreen", "Burst Engine", "An engine for a ship.", "GreenEngineBlock"), 7000));
  69. SceneManager.sceneLoaded += OnSceneLoaded;
  70. }
  71. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  72. {
  73. if (scene.buildIndex == 1 && Core.settingStarsEnum != StarTypeEnum.OriginalStars)
  74. {
  75. try
  76. {
  77. var oldParticleSystemObject = GameObject.Find("Ship").transform.Find("Particle System").gameObject;
  78. oldParticleSystemObject.GetComponent<ParticleSystem>().Stop(true, stopBehavior: ParticleSystemStopBehavior.StopEmittingAndClear);
  79. GameObject.DestroyImmediate(oldParticleSystemObject);
  80. var particleContainer = new GameObject("Particles");
  81. particleContainer.transform.SetParent(GameObject.Find("Ship").transform);
  82. oldParticleSystemObject = GameObject.Find("Ship").transform.Find("Particle System").gameObject;
  83. oldParticleSystemObject.GetComponent<ParticleSystem>().Stop(true, stopBehavior: ParticleSystemStopBehavior.StopEmittingAndClear);
  84. AddParticleSystem(particleContainer, oldParticleSystemObject, 1f, 0.8f);
  85. AddParticleSystem(particleContainer, oldParticleSystemObject, 2f, 0.6f);
  86. AddParticleSystem(particleContainer, oldParticleSystemObject, 4f, 0.4f);
  87. AddParticleSystem(particleContainer, oldParticleSystemObject, 8f, 0.3f);
  88. AddParticleSystem(particleContainer, oldParticleSystemObject, 1.5f, 0.45f);
  89. AddParticleSystem(particleContainer, oldParticleSystemObject, 2.5f, 0.35f);
  90. AddParticleSystem(particleContainer, oldParticleSystemObject, 4.5f, 1.1f);
  91. AddParticleSystem(particleContainer, oldParticleSystemObject, 8.5f, 1f);
  92. AddParticleSystem(particleContainer, oldParticleSystemObject, 1.2f, 1.2f);
  93. AddParticleSystem(particleContainer, oldParticleSystemObject, 15f, 0.3f);
  94. if (Core.settingStarsEnum == StarTypeEnum.NewStarsAndPlanetes)
  95. {
  96. foreach (var r in PlanetRegistry.Singleton.GetAllEntries())
  97. AddParticleSystem(particleContainer, oldParticleSystemObject, r.SelectorIconMat.mainTexture);
  98. for (int i = 0; i < 14; i++)
  99. AddParticleSystem(particleContainer, oldParticleSystemObject, ((Material)Resources.Load("mat/planet" + i)).mainTexture);
  100. }
  101. GameObject.DestroyImmediate(oldParticleSystemObject);
  102. }
  103. catch (System.Exception e) { Core.logger.LogConsole(e.Message); }
  104. }
  105. }
  106. private static void AddParticleSystem(GameObject container, GameObject old, float speed, float size)
  107. {
  108. var stars = GameObject.Instantiate(old);
  109. stars.name = "Particle System";
  110. stars.transform.SetParent(container.transform);
  111. stars.transform.localPosition = new Vector3(150, -7, 15.8f);
  112. stars.transform.localRotation = Quaternion.Euler(180, 90, -90);
  113. stars.transform.localScale = new Vector3(300, 1, 0);
  114. var particleSystem = stars.GetComponent<ParticleSystem>();
  115. var emission = particleSystem.emission;
  116. emission.rateOverTime = new ParticleSystem.MinMaxCurve(6f);
  117. var main = particleSystem.main;
  118. main.startSpeed = new ParticleSystem.MinMaxCurve(10f);
  119. main.startSize = new ParticleSystem.MinMaxCurve(size);
  120. main.startLifetime = new ParticleSystem.MinMaxCurve(50);
  121. main.simulationSpeed = speed;
  122. main.loop = true;
  123. particleSystem.Simulate(10);
  124. particleSystem.Play();
  125. }
  126. private static void AddParticleSystem(GameObject container, GameObject old, Texture texture)
  127. {
  128. var stars = GameObject.Instantiate(old);
  129. stars.name = "Particle System";
  130. stars.transform.SetParent(container.transform);
  131. stars.transform.localPosition = new Vector3(150, -7, 15.5f);
  132. stars.transform.localRotation = Quaternion.Euler(180, 90, -90);
  133. stars.transform.localScale = new Vector3(300, 1, 0);
  134. var particleSystem = stars.GetComponent<ParticleSystem>();
  135. var emission = particleSystem.emission;
  136. emission.rateOverTime = new ParticleSystem.MinMaxCurve(1);
  137. var main = particleSystem.main;
  138. main.startSpeed = new ParticleSystem.MinMaxCurve(10f);
  139. main.startSize = new ParticleSystem.MinMaxCurve(1.3f, 2.4f);
  140. main.startLifetime = new ParticleSystem.MinMaxCurve(50);
  141. main.simulationSpeed = 0.4f + (Random.Range(0, 40) / 10f);
  142. main.loop = true;
  143. main.maxParticles = 3;
  144. particleSystem.GetComponent<Renderer>().material = new Material(Shader.Find("Transparent/Diffuse"))
  145. {
  146. mainTexture = texture
  147. };
  148. particleSystem.Simulate(10 + Random.Range(0, 140));
  149. particleSystem.Play();
  150. }
  151. }
  152. }