Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using sc.modeling.river.runtime;
- using UnityEngine;
- [ExecuteAlways]
- //Mirrors a RiverModeler component, but with an altered height offset and added width
- public class RiverStencilCopy : MonoBehaviour
- {
- public RiverModeler source;
- public RiverModeler destination;
- public float offset;
- public float width;
- private void Reset()
- {
- destination = GetComponent<RiverModeler>();
- }
- private void OnEnable()
- {
- RiverModeler.onPostRebuildRiver += OnPostRebuild;
- }
- private void OnDisable()
- {
- RiverModeler.onPostRebuildRiver -= OnPostRebuild;
- }
- private void OnPostRebuild(RiverModeler instance, RiverModeler.ChangeFlags updateflags)
- {
- if (instance != source) return;
- Rebuild(updateflags);
- }
- private void Rebuild(RiverModeler.ChangeFlags updateflags)
- {
- if (source == null || destination == null) return;
- destination.settings = source.settings;
- float prevOffset = destination.settings.shape.offset.y;
- float prevWidth = destination.settings.shape.width;
- destination.settings.shape.offset.y = offset;
- destination.settings.shape.width += width;
- destination.Rebuild(updateflags);
- //Reset
- destination.settings.shape.offset.y = prevOffset;
- destination.settings.shape.width = prevWidth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement