Patch_KylockeStand_Set.cs 3.6 KB

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