Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- namespace sc.modeling.splines.runtime.auxiliary
- {
- [ExecuteAlways]
- public class SplineMesherLightmapUV : MonoBehaviour
- {
- [Tooltip("Let Unity automatically create a new UV (slow but accurate)")]
- public bool autoUnwrap = true;
- public SplineMesher splineMesher;
- private void Reset()
- {
- splineMesher = GetComponent<SplineMesher>();
- }
- private void OnEnable()
- {
- //Subscribe
- SplineMesher.onPostRebuildMesh += OnPostRebuild;
- }
- private void OnPostRebuild(SplineMesher instance)
- {
- //Is the instance being rebuild the one we want to work with
- if (instance == splineMesher)
- {
- MeshFilter mf = splineMesher.GetComponent<MeshFilter>();
- if (mf)
- {
- #if UNITY_EDITOR
- if (autoUnwrap)
- {
- UnityEditor.Unwrapping.GenerateSecondaryUVSet(mf.sharedMesh);
- }
- else
- {
- mf.sharedMesh.uv2 = mf.sharedMesh.uv;
- }
- #endif
- }
- }
- }
- private void OnDisable()
- {
- //Unsubscribe
- SplineMesher.onPostRebuildMesh -= OnPostRebuild;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement