From 8a66c2fd7d6f89c6e559d18075dda3ffb7f35000 Mon Sep 17 00:00:00 2001 From: VladV Date: Fri, 4 Nov 2022 15:38:58 +0400 Subject: [PATCH] Add domain reload support --- Runtime/Scripts/MeshCache.cs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Runtime/Scripts/MeshCache.cs b/Runtime/Scripts/MeshCache.cs index ca4b5ef..89113e8 100644 --- a/Runtime/Scripts/MeshCache.cs +++ b/Runtime/Scripts/MeshCache.cs @@ -1,19 +1,42 @@ -namespace CodeWriter.MeshAnimation { +namespace CodeWriter.MeshAnimation +{ using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR + using UnityEditor; - public static class MeshCache { +#endif + + public static class MeshCache + { private static readonly HashSet CachedUv = new HashSet(); - public static void GenerateSecondaryUv(Mesh mesh) { - if (CachedUv.Contains(mesh)) { +#if UNITY_EDITOR + [InitializeOnLoadMethod] + private static void Initialize() + { + EditorApplication.playModeStateChanged += change => + { + if (change == PlayModeStateChange.EnteredEditMode) + { + CachedUv.Clear(); + } + }; + } +#endif + + public static void GenerateSecondaryUv(Mesh mesh) + { + if (CachedUv.Contains(mesh)) + { return; } CachedUv.Add(mesh); var uvs = new Vector2[mesh.vertexCount]; - for (int i = 0; i < uvs.Length; i++) { + for (int i = 0; i < uvs.Length; i++) + { uvs[i] = new Vector2(1f * i, 0); }