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); }