using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using GameNetcodeStuff; namespace ScarletMansion.GamePatch.Components { public class ScarletFireExit : MonoBehaviour { public bool enablePortalAnimation; [Header("Animations")] public MeshRenderer portalRenderer; public MeshRenderer blackRenderer; private Material portalMaterial; private Material blackMaterial; private Coroutine timerCoroutine; private Coroutine currentCoroutine; public const float animationTime = 0.4f; void Start(){ portalMaterial = portalRenderer.material; blackMaterial = blackRenderer.material; } public void DisableEnablePortal(){ if (!enablePortalAnimation) return; if (timerCoroutine != null) StopCoroutine(timerCoroutine); timerCoroutine = StartCoroutine(DisableEnablePortalCoroutine()); } private IEnumerator DisableEnablePortalCoroutine(){ DisablePortal(); yield return new WaitForSeconds(3f); EnablePortal(); } public void DisablePortal(){ if (currentCoroutine != null) StopCoroutine(currentCoroutine); currentCoroutine = StartCoroutine(SetPortalCoroutine(-0.5f, 0f)); } public void EnablePortal(){ if (currentCoroutine != null) StopCoroutine(currentCoroutine); currentCoroutine = StartCoroutine(SetPortalCoroutine(1.5f, 1f)); } private IEnumerator SetPortalCoroutine(float dissolveTarget, float blackTarget){ float dv; Color bv; do { dv = portalMaterial.GetFloat("_DissolveValue"); dv = Mathf.MoveTowards(dv, dissolveTarget, 2f / animationTime * Time.deltaTime); portalMaterial.SetFloat("_DissolveValue", dv); bv = blackMaterial.color; bv.a = Mathf.MoveTowards(bv.a, blackTarget, 1f / animationTime * Time.deltaTime); blackMaterial.color = bv; yield return null; } while (dv != dissolveTarget && bv.a != blackTarget); } } }