Advertisement
Staggart

RiverStencilCopy

Jun 3rd, 2024 (edited)
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using sc.modeling.river.runtime;
  2. using UnityEngine;
  3.  
  4. [ExecuteAlways]
  5. //Mirrors a RiverModeler component, but with an altered height offset and added width
  6. public class RiverStencilCopy : MonoBehaviour
  7. {
  8.     public RiverModeler source;
  9.     public RiverModeler destination;
  10.  
  11.     public float offset;
  12.     public float width;
  13.  
  14.     private void Reset()
  15.     {
  16.         destination = GetComponent<RiverModeler>();
  17.     }
  18.    
  19.     private void OnEnable()
  20.     {
  21.         RiverModeler.onPostRebuildRiver += OnPostRebuild;
  22.     }
  23.  
  24.     private void OnDisable()
  25.     {
  26.         RiverModeler.onPostRebuildRiver -= OnPostRebuild;
  27.     }
  28.  
  29.     private void OnPostRebuild(RiverModeler instance, RiverModeler.ChangeFlags updateflags)
  30.     {
  31.         if (instance != source) return;
  32.  
  33.         Rebuild(updateflags);
  34.     }
  35.  
  36.     private void Rebuild(RiverModeler.ChangeFlags updateflags)
  37.     {
  38.         if (source == null || destination == null) return;
  39.        
  40.         destination.settings = source.settings;
  41.  
  42.         float prevOffset = destination.settings.shape.offset.y;
  43.         float prevWidth = destination.settings.shape.width;
  44.         destination.settings.shape.offset.y = offset;
  45.         destination.settings.shape.width += width;
  46.        
  47.         destination.Rebuild(updateflags);
  48.        
  49.         //Reset
  50.         destination.settings.shape.offset.y = prevOffset;
  51.         destination.settings.shape.width = prevWidth;
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement