| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using GadgetCore.API;
- using GadgetCore.Util;
- using HarmonyLib;
- using System.Collections;
- using System.Linq;
- using UnityEngine;
- namespace MultiplayerClientSpawn.Patches
- {
- [HarmonyPatch(typeof(KylockeStand))]
- [HarmonyPatch("Set")]
- [HarmonyGadget("MultiplayerClientSpawn")]
- public static class Patch_KylockeStand_Set
- {
- [HarmonyPostfix]
- public static void Prefix(KylockeStand __instance, int[] p)
- {
- if (animate == null)
- {
- animate = true;
- foreach (var gadget in GadgetCore.API.Gadgets.ListAllEnabledGadgets())
- if (gadget.Info?.ModName == "More Lights" || gadget.Info?.ModName == "Ship Decorations")
- {
- animate = false;
- break;
- }
- }
- if (animate ?? false)
- __instance.StartCoroutine(DoUpdateLampAnimation(__instance));
- if (new int[] { Core.itemSpawnId, 2403 }.Contains(p[0]))
- __instance.StartCoroutine(DoUpdateLoadingAnimation(__instance));
- }
- private static bool? animate = null;
- private static IEnumerator DoUpdateLampAnimation(KylockeStand instance)
- {
- if (!GameScript.inInstance)
- {
- instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shipdroid" + UnityEngine.Random.Range(0, 3)), Menuu.soundLevel / 10f);
- }
- var scale = instance.icon.transform.localScale;
- instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
- yield return new WaitForSeconds(0.05f);
- instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
- yield return new WaitForSeconds(0.05f);
- instance.icon.transform.localScale = new Vector3(scale.x * 0.70f, scale.y);
- yield return new WaitForSeconds(0.05f);
- instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
- yield return new WaitForSeconds(0.05f);
- instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
- yield return new WaitForSeconds(0.05f);
- instance.icon.transform.localScale = new Vector3(scale.y, scale.y);
- }
- private static Texture2D textureStand0 = GadgetCoreAPI.LoadTexture2D("stand0.png");
- private static Texture2D textureStand1 = GadgetCoreAPI.LoadTexture2D("stand1.png");
- private static Texture2D textureStand2 = GadgetCoreAPI.LoadTexture2D("stand2.png");
- private static Texture2D textureStand3 = GadgetCoreAPI.LoadTexture2D("stand3.png");
- private static Texture2D textureStand4 = GadgetCoreAPI.LoadTexture2D("stand4.png");
- private static Texture2D textureStand5 = GadgetCoreAPI.LoadTexture2D("stand5.png");
- private static Texture2D textureStand6 = GadgetCoreAPI.LoadTexture2D("stand6.png");
- private static IEnumerator DoUpdateLoadingAnimation(KylockeStand instance)
- {
- UpdateTexture(instance, textureStand0);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand1);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand2);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand3);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand4);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand5);
- yield return new WaitForSeconds(1.43f);
- UpdateTexture(instance, textureStand6);
- }
- private static void UpdateTexture(KylockeStand instance, Texture2D texture)
- {
- Renderer renderer = instance.gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
- renderer.material = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = texture
- };
- }
- }
- }
|