Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions Runtime/Scripts/MeshCache.cs
Original file line number Diff line number Diff line change
@@ -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<Mesh> CachedUv = new HashSet<Mesh>();

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

Expand Down