Patch_KylockeStand_Set.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using GadgetCore.API;
  2. using GadgetCore.Util;
  3. using HarmonyLib;
  4. using System.Collections;
  5. using UnityEngine;
  6. namespace ShipDecorations.Patches
  7. {
  8. [HarmonyPatch(typeof(KylockeStand))]
  9. [HarmonyPatch("Set")]
  10. [HarmonyGadget("ShipDecorations")]
  11. public static class Patch_KylockeStand_Set
  12. {
  13. [HarmonyPostfix]
  14. public static void Prefix(KylockeStand __instance, int[] p)
  15. {
  16. if(animate == null)
  17. {
  18. animate = true;
  19. foreach (var gadget in GadgetCore.API.Gadgets.ListAllEnabledGadgets())
  20. if (gadget.Info?.ModName == "More Lights")
  21. {
  22. animate = false;
  23. break;
  24. }
  25. }
  26. if (animate ?? false)
  27. __instance.StartCoroutine(DoUpdateLampAnimation(__instance));
  28. if (Core.itemStoreList.Contains(p[0]))
  29. __instance.StartCoroutine(DoUpdateLoadingAnimation(__instance));
  30. }
  31. private static bool? animate = null;
  32. private static IEnumerator DoUpdateLampAnimation(KylockeStand instance)
  33. {
  34. if (!GameScript.inInstance)
  35. {
  36. instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shipdroid" + UnityEngine.Random.Range(0, 3)), Menuu.soundLevel / 10f);
  37. }
  38. var scale = instance.icon.transform.localScale;
  39. instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
  40. yield return new WaitForSeconds(0.05f);
  41. instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
  42. yield return new WaitForSeconds(0.05f);
  43. instance.icon.transform.localScale = new Vector3(scale.x * 0.70f, scale.y);
  44. yield return new WaitForSeconds(0.05f);
  45. instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
  46. yield return new WaitForSeconds(0.05f);
  47. instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
  48. yield return new WaitForSeconds(0.05f);
  49. instance.icon.transform.localScale = new Vector3(scale.y, scale.y);
  50. }
  51. private static Texture2D textureStand0 = GadgetCoreAPI.LoadTexture2D("stand0.png");
  52. private static Texture2D textureStand1 = GadgetCoreAPI.LoadTexture2D("stand1.png");
  53. private static Texture2D textureStand2 = GadgetCoreAPI.LoadTexture2D("stand2.png");
  54. private static Texture2D textureStand3 = GadgetCoreAPI.LoadTexture2D("stand3.png");
  55. private static Texture2D textureStand4 = GadgetCoreAPI.LoadTexture2D("stand4.png");
  56. private static Texture2D textureStand5 = GadgetCoreAPI.LoadTexture2D("stand5.png");
  57. private static Texture2D textureStand6 = GadgetCoreAPI.LoadTexture2D("stand6.png");
  58. private static IEnumerator DoUpdateLoadingAnimation(KylockeStand instance)
  59. {
  60. UpdateTexture(instance, textureStand0);
  61. yield return new WaitForSeconds(1.43f);
  62. UpdateTexture(instance, textureStand1);
  63. yield return new WaitForSeconds(1.43f);
  64. UpdateTexture(instance, textureStand2);
  65. yield return new WaitForSeconds(1.43f);
  66. UpdateTexture(instance, textureStand3);
  67. yield return new WaitForSeconds(1.43f);
  68. UpdateTexture(instance, textureStand4);
  69. yield return new WaitForSeconds(1.43f);
  70. UpdateTexture(instance, textureStand5);
  71. yield return new WaitForSeconds(1.43f);
  72. UpdateTexture(instance, textureStand6);
  73. }
  74. private static void UpdateTexture(KylockeStand instance, Texture2D texture)
  75. {
  76. Renderer renderer = instance.gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
  77. renderer.material = new Material(Shader.Find("Unlit/Transparent"))
  78. {
  79. mainTexture = texture
  80. };
  81. }
  82. }
  83. }