| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using GadgetCore.API;
- using GadgetCore.API.ConfigMenu;
- using ScrapYard.API;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace EnginesDeluxe
- {
- [Gadget("EnginesDeluxe", LoadAfter: new string[] { "ScrapYard" }, Dependencies: new string[] { "ScrapYard" })]
- public class EnginesDeluxe : Gadget<EnginesDeluxe>
- {
- public const string MOD_VERSION = "1.0"; // 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.
- protected override void LoadConfig()
- {
- Config.Load();
- string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
- if (fileVersion != CONFIG_VERSION)
- {
- Config.Reset();
- Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
- }
- Core.settingStarsEnum = Config.ReadEnum("StarType", StarTypeEnum.NewStarsAndPlanetes, requiresRestart: false, comments: new string[] { "Should the stars on the ship be replaced?" });
- Config.Save();
- }
- public override string GetModDescription()
- {
- return "A mod that adds some more engines.";
- }
- protected override void Initialize()
- {
- Logger.Log("Engines Deluxe v" + Info.Mod.Version);
- Core.logger = Logger;
- var asset = GadgetCoreAPI.LoadAssetBundle("engine");
- { // Part Engine Blue
- var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineBlue.prefab"));
- engine.name = "engineBlue";
- engine.transform.localScale = new Vector3(2, 2, 2);
- GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineBlue", engine);
- }
- { // Part Engine Yellow
- var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineYellow.prefab"));
- engine.name = "engineYellow";
- engine.transform.localScale = new Vector3(2, 2, 2);
- GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineYellow", engine);
- }
- { // Part Engine Red
- var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineRed.prefab"));
- engine.name = "engineRed";
- engine.transform.localScale = new Vector3(2, 2, 2);
- GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineRed", engine);
- }
- { // Part Engine Green
- var engine = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/engineGreen.prefab"));
- engine.name = "engineGreen";
- engine.transform.localScale = new Vector3(2, 2, 2);
- GadgetCoreAPI.AddCustomResource("prop/EnginesDeluxe/component/engineGreen", engine);
- }
- foreach (var e in ShopPlatform.DefaultBlocks.GetShopPlatformEntries())
- {
- if (e.ItemID == 2400)
- {
- ShopPlatform.DefaultBlocks.RemoveShopPlatformEntry(e);
- }
- }
- ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cBlueEngineBlock.png", "iBlueEngineBlock.png", "engineBlue", "Plasma Engine", "An engine for a ship.", "BlueEngineBlock"), 7000));
- ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cYellowEngineBlock.png", "iYellowEngineBlock.png", "engineYellow", "Differential Engine", "An engine for a ship.", "YellowEngineBlock"), 7000));
- ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateOverrideEngineItem("cRedEngineBlock.png", "iRedEngineBlock.png", "engineRed", "Combustion Engine", "An engine for a ship.", "RedEngineBlock"), 7000));
- ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreateEngineItem("cGreenEngineBlock.png", "iGreenEngineBlock.png", "engineGreen", "Burst Engine", "An engine for a ship.", "GreenEngineBlock"), 7000));
- SceneManager.sceneLoaded += OnSceneLoaded;
- }
- internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
- {
- if (scene.buildIndex == 1 && Core.settingStarsEnum != StarTypeEnum.OriginalStars)
- {
- try
- {
- var oldParticleSystemObject = GameObject.Find("Ship").transform.Find("Particle System").gameObject;
- oldParticleSystemObject.GetComponent<ParticleSystem>().Stop(true, stopBehavior: ParticleSystemStopBehavior.StopEmittingAndClear);
- GameObject.DestroyImmediate(oldParticleSystemObject);
- var particleContainer = new GameObject("Particles");
- particleContainer.transform.SetParent(GameObject.Find("Ship").transform);
- oldParticleSystemObject = GameObject.Find("Ship").transform.Find("Particle System").gameObject;
- oldParticleSystemObject.GetComponent<ParticleSystem>().Stop(true, stopBehavior: ParticleSystemStopBehavior.StopEmittingAndClear);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 1f, 0.8f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 2f, 0.6f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 4f, 0.4f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 8f, 0.3f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 1.5f, 0.45f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 2.5f, 0.35f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 4.5f, 1.1f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 8.5f, 1f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 1.2f, 1.2f);
- AddParticleSystem(particleContainer, oldParticleSystemObject, 15f, 0.3f);
- if (Core.settingStarsEnum == StarTypeEnum.NewStarsAndPlanetes)
- {
- foreach (var r in PlanetRegistry.Singleton.GetAllEntries())
- AddParticleSystem(particleContainer, oldParticleSystemObject, r.SelectorIconMat.mainTexture);
- for (int i = 0; i < 14; i++)
- AddParticleSystem(particleContainer, oldParticleSystemObject, ((Material)Resources.Load("mat/planet" + i)).mainTexture);
- }
- GameObject.DestroyImmediate(oldParticleSystemObject);
- }
- catch (System.Exception e) { Core.logger.LogConsole(e.Message); }
- }
- }
- private static void AddParticleSystem(GameObject container, GameObject old, float speed, float size)
- {
- var stars = GameObject.Instantiate(old);
- stars.name = "Particle System";
- stars.transform.SetParent(container.transform);
- stars.transform.localPosition = new Vector3(150, -7, 15.8f);
- stars.transform.localRotation = Quaternion.Euler(180, 90, -90);
- stars.transform.localScale = new Vector3(300, 1, 0);
- var particleSystem = stars.GetComponent<ParticleSystem>();
- var emission = particleSystem.emission;
- emission.rateOverTime = new ParticleSystem.MinMaxCurve(6f);
- var main = particleSystem.main;
- main.startSpeed = new ParticleSystem.MinMaxCurve(10f);
- main.startSize = new ParticleSystem.MinMaxCurve(size);
- main.startLifetime = new ParticleSystem.MinMaxCurve(50);
- main.simulationSpeed = speed;
- main.loop = true;
- particleSystem.Simulate(10);
- particleSystem.Play();
- }
- private static void AddParticleSystem(GameObject container, GameObject old, Texture texture)
- {
- var stars = GameObject.Instantiate(old);
- stars.name = "Particle System";
- stars.transform.SetParent(container.transform);
- stars.transform.localPosition = new Vector3(150, -7, 15.5f);
- stars.transform.localRotation = Quaternion.Euler(180, 90, -90);
- stars.transform.localScale = new Vector3(300, 1, 0);
- var particleSystem = stars.GetComponent<ParticleSystem>();
- var emission = particleSystem.emission;
- emission.rateOverTime = new ParticleSystem.MinMaxCurve(1);
- var main = particleSystem.main;
- main.startSpeed = new ParticleSystem.MinMaxCurve(10f);
- main.startSize = new ParticleSystem.MinMaxCurve(1.3f, 2.4f);
- main.startLifetime = new ParticleSystem.MinMaxCurve(50);
- main.simulationSpeed = 0.4f + (Random.Range(0, 40) / 10f);
- main.loop = true;
- main.maxParticles = 3;
- particleSystem.GetComponent<Renderer>().material = new Material(Shader.Find("Transparent/Diffuse"))
- {
- mainTexture = texture
- };
- particleSystem.Simulate(10 + Random.Range(0, 140));
- particleSystem.Play();
- }
- }
- }
|