Writing Custom Rules
Extend AI Scene Organizer by writing custom C# rules. This allows your technical artists to enforce studio-specific workflows, such as checking that all meshes have LOD groups, checking texture sizes, or ensuring colliders share static flags.
The ISceneRule Interface
All rules must implement the Decnet.SceneOrganizer.ISceneRule interface. This interface contains metadata properties and an evaluation method:
namespace Decnet.SceneOrganizer
{
public interface ISceneRule
{
string RuleID { get; }
string DisplayName { get; }
string Description { get; }
SceneIssueSeverity DefaultSeverity { get; }
List<SceneIssue> Evaluate(UnityEngine.SceneManagement.Scene scene);
}
}
Step-by-Step Custom Rule Implementation
Here is a complete, copy-pasteable C# template to enforce that every Directional Light must have shadow casting enabled.
Save this script as DirectionalLightShadowRule.cs inside your Editor/Rules/ folder:
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Decnet.SceneOrganizer;
public class DirectionalLightShadowRule : ISceneRule
{
public string RuleID => "decnet.rules.directional_light_shadows";
public string DisplayName => "Directional Light Shadows";
public string Description => "Ensures all active Directional Lights have shadow casting enabled for correct lighting.";
public SceneIssueSeverity DefaultSeverity => SceneIssueSeverity.Warning;
public List<SceneIssue> Evaluate(UnityEngine.SceneManagement.Scene scene)
{
var issues = new List<SceneIssue>();
var lights = GameObject.FindObjectsOfType<Light>();
foreach (var light in lights)
{
// Only check Directional Lights
if (light.type == LightType.Directional && light.enabled)
{
if (light.shadows == LightShadows.None)
{
issues.Add(new SceneIssue(
ruleId: RuleID,
gameObject: light.gameObject,
message: $"Directional Light '{light.name}' has shadows disabled! This may cause flat lighting.",
severity: DefaultSeverity,
fixAction: () =>
{
Undo.RecordObject(light, "Enable Shadows");
light.shadows = LightShadows.Soft;
EditorUtility.SetDirty(light);
}
));
}
}
}
return issues;
}
}
Registering and Running the Rule
- Save the file. Unity will compile the assembly automatically.
- The scanner engine uses reflection to locate all classes implementing
ISceneRule. - Open the Dashboard ➔ Scanner.
- Your new rule Directional Light Shadows will appear in the active rule sets checklist in the settings panel.
- Click Scan Scene to run your rule. The issues list will flag any lights failing the check.