35 lines
1014 B
C#
35 lines
1014 B
C#
using System;
|
|
using BlockSpace.Voxels;
|
|
using UnityEngine;
|
|
|
|
[DisallowMultipleComponent]
|
|
public sealed class SetGroupMaterialBehavior : 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 = Mathf.RoundToInt((float)GetInputNumber("Material")) switch
|
|
{
|
|
1 => VoxelMaterial.Unlit,
|
|
2 => VoxelMaterial.Transparent,
|
|
3 => 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");
|
|
}
|
|
}
|