rj-action-library/Runtime/Procedural/Scatter/ScatterList.cs

85 lines
1.6 KiB
C#
Raw Normal View History

2024-09-14 06:41:52 +00:00
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class ScatterList:Scatterer
{
[Export]
public bool childrenNeedToBeVisible = true;
[Export]
public bool childrenNeedToBeProcessing = false;
[Export]
public bool clearChildContainers = false;
public override void _Process( double delta )
{
2025-01-03 12:09:23 +00:00
if ( clearCache )
{
clearCache = false;
ClearCache();
}
2024-09-14 06:41:52 +00:00
if ( clearContainers )
{
clearContainers = false;
ClearContainers();
}
if ( clearChildContainers )
{
clearChildContainers = false;
Nodes.ForEachDirectChild<Scatterer>( this, s => s.ClearContainers() );
}
if ( ! ( update || updateAlways ) )
{
return;
}
update = false;
ScatterAndInstantiatePoints();
}
2025-01-03 12:09:23 +00:00
protected override List<ScatterPoint> _Scatter( List<ScatterPoint> points, Scatterer root = null )
2024-09-14 06:41:52 +00:00
{
2025-01-03 12:09:23 +00:00
if ( root == null )
{
root = this;
}
2024-09-14 06:41:52 +00:00
var output = points;
Nodes.ForEachDirectChild<Scatterer>( this,
( s )=>
{
if ( ! IsChildEnabled( s ) )
{
return;
}
2025-01-03 12:09:23 +00:00
var before = output.Count ;
output = s.Scatter( output, root );
RJLog.Log( "Processed", before, "to", output.Count );
2024-09-14 06:41:52 +00:00
}
);
return output;
}
bool IsChildEnabled( Scatterer s )
{
return IsChildEnabled( s, childrenNeedToBeVisible, childrenNeedToBeProcessing );
}
}
}