Advertisement
Staggart

Copy Spline Mesher Scale

Apr 1st, 2024
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. namespace sc.modeling.splines.runtime.auxiliary
  5. {
  6.     [ExecuteAlways]
  7.     //Copies the SplineMesher scale data from the source to the destination
  8.     public class CopySplineMesherScale : MonoBehaviour
  9.     {
  10.         public SplineMesher source;
  11.         public SplineMesher destination;
  12.  
  13.         private void Reset()
  14.         {
  15.             destination = GetComponent<SplineMesher>();
  16.         }
  17.        
  18.         private void OnEnable()
  19.         {
  20.             SplineMesher.onPreRebuildMesh += OnPreRebuild;
  21.         }
  22.  
  23.         private void OnDisable()
  24.         {
  25.             SplineMesher.onPreRebuildMesh -= OnPreRebuild;
  26.         }
  27.  
  28.         private void OnPreRebuild(SplineMesher instance)
  29.         {
  30.             //Scale data is tailored to specific splines, so only allow copying if both components actually use the same splines.
  31.             if (source.splineContainer == destination.splineContainer)
  32.             {
  33.                 destination.scaleData = source.scaleData;
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement