private void OnDisable() { _meshSource?.Dispose(); _meshSource = null; if (TryGetComponent(out MeshFilter meshFilter)) { meshFilter.mesh = null; } }
private void OnEnable() { _meshSource?.Dispose(); _meshSource = new MeshSource(8192 * 3); if (!TryGetComponent(out MeshFilter meshFilter)) { meshFilter = gameObject.AddComponent <MeshFilter>(); } meshFilter.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; meshFilter.mesh = _meshSource.Mesh; Generate(); }