29 lines
903 B
C#
29 lines
903 B
C#
using System;
|
|
using BlockSpace.Voxels;
|
|
using UnityEngine;
|
|
|
|
[DisallowMultipleComponent]
|
|
public sealed class SetGroupVisibleBehavior : NodeBehavior
|
|
{
|
|
public override void OnRun(string inputPortName)
|
|
{
|
|
if (!base.IsAuthoritative || !string.Equals(inputPortName, "Set", StringComparison.Ordinal) || !TryGetInputGroup("Group", out var group) || group == null || group.voxels == null)
|
|
{
|
|
return;
|
|
}
|
|
VoxelMaterial material = ((!GetInputValue("Visible").AsBool()) ? VoxelMaterial.Invisible : VoxelMaterial.Lit);
|
|
for (int i = 0; i < group.voxels.Length; i++)
|
|
{
|
|
byte voxel = group.voxels[i];
|
|
if (!PackedVoxel.IsAir(voxel))
|
|
{
|
|
byte colorIndex = PackedVoxel.GetColorIndex(voxel);
|
|
group.voxels[i] = PackedVoxel.Create(colorIndex, material);
|
|
}
|
|
}
|
|
group.MarkDirty(mesh: true, collider: true);
|
|
VoxelGroupManager.Instance?.BroadcastGroupModify(group);
|
|
TriggerOutput("Done");
|
|
}
|
|
}
|