Class ScyllaShapeBase3D
Abstract base class for all concrete Scylla 3D shape components. A shape owns its UnityEngine.Mesh, regenerates it on demand from serialized parameters, and exposes a uniform set of features: tint, double-sided rendering, collider mode, bounds query.
Inheritance
Inherited Members
Namespace: Scylla.Core.Util.Geom
Assembly: ScyllaCore.dll
Syntax
[ExecuteAlways]
[DisallowMultipleComponent]
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public abstract class ScyllaShapeBase3D : MonoBehaviour
Remarks
Each shape subclass implements BuildMesh(Mesh) to populate the owned mesh from its serialized parameters. The base class handles the Unity plumbing (mesh allocation, component lifecycle, editor-time rebuild scheduling, collider attachment, tint application).
The owned UnityEngine.Mesh is created lazily in Awake() and the first Rebuild() call. It is destroyed in OnDestroy(). The mesh is marked UnityEngine.HideFlags.DontSaveInEditor so it does not bloat scene and prefab files.
In the editor, OnValidate() defers Rebuild() via EditorApplication.delayCall so the rebuild runs after the property change has settled and Unity allows mesh mutation. In Play Mode, callers must invoke Rebuild() explicitly after changing parameters via code (or use one of the tween extensions that does so automatically).
Properties
ActiveFaceColorResolver
The per-face color resolver active for the current rebuild, or null when
per-face coloring is disabled or the palette could not be resolved. Subclass
BuildMesh(Mesh) implementations that support per-face coloring forward
this to their static builder so it emits the mesh's vertex color channel; shapes that
do not yet support per-face coloring simply ignore it.
Declaration
protected IFaceColorResolver ActiveFaceColorResolver { get; }
Property Value
| Type | Description |
|---|---|
| IFaceColorResolver |
Bounds
Local-space axis-aligned bounding box of the most recently rebuilt mesh. Returns Empty when no mesh has been built. Implicit conversion is defined between AABB3D and UnityEngine.Bounds so callers can treat the result as either type.
Declaration
public AABB3D Bounds { get; }
Property Value
| Type | Description |
|---|---|
| AABB3D |
ColliderMode
Controls the collider attached to this shape's UnityEngine.GameObject when the mesh is rebuilt. See ColliderMode for variant behaviour.
Declaration
public ColliderMode ColliderMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ColliderMode |
ColorPaletteName
Name of the ColorPalette (resolved via ColorAssetRegistry) used for per-face coloring. Ignored when FaceColoringMode is None or the name does not resolve to a palette. Setting this triggers a rebuild.
Declaration
public string ColorPaletteName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
ColorSeed
Seed for Hash. Changing it reshuffles the per-face color assignment deterministically and triggers a rebuild.
Declaration
public int ColorSeed { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
DoubleSided
When true, the shape renders both faces by sharing
GetDoubleSided(). Useful for flat or single-sided
meshes (planes, quads, single-quad floor tiles). Changing this triggers a material
swap on the next Rebuild().
Declaration
public bool DoubleSided { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
FaceColoringMode
Selects how the shape's faces are colored from the palette named by ColorPaletteName. None (the default) disables per-face coloring entirely. Setting this triggers a rebuild.
Declaration
public FaceColoringMode FaceColoringMode { get; set; }
Property Value
| Type | Description |
|---|---|
| FaceColoringMode |
FaceColoringPalette
Runtime override palette for per-face coloring. When non-null, it takes precedence over ColorPaletteName, letting code drive coloring with a ColorPalette it already holds (no registry lookup). This is not serialized; the Inspector path uses the palette name instead. Setting this triggers a rebuild.
Declaration
public ColorPalette FaceColoringPalette { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorPalette |
IsManuallyEdited
When true, this shape has been manually edited (e.g. a vertex was moved by
an external tool) and subsequent parameter changes no longer trigger an automatic
rebuild. This is reserved for future tooling and is always false in the
initial release.
Declaration
public bool IsManuallyEdited { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
SharedMesh
The UnityEngine.Mesh instance owned and rebuilt by this shape. Becomes non-null after the first Rebuild() call (or, in the editor, after the shape's OnValidate() deferred rebuild has run).
Declaration
public Mesh SharedMesh { get; }
Property Value
| Type | Description |
|---|---|
| Mesh |
Tint
Per-renderer tint applied via UnityEngine.MaterialPropertyBlock. Defaults to UnityEngine.Color.white (no visible tint). Setting this property triggers a property block refresh on the next Rebuild() or immediately in Play Mode.
Declaration
public Color Tint { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
TintEntryName
Name of the entry within TintPaletteName to use as the whole-shape tint. Ignored when TintPaletteName is empty or does not resolve. Setting this re-applies the tint.
Declaration
public string TintEntryName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
TintPaletteName
Name of a ColorPalette (resolved via ColorAssetRegistry) to draw the whole-shape tint from. When this and TintEntryName both resolve, the matching palette color overrides the inline Tint; otherwise Tint is used. Setting this re-applies the tint.
Declaration
public string TintPaletteName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
UniformColorIndex
Palette index used by Uniform. Clamped to the palette range at resolve time. Setting this triggers a rebuild.
Declaration
public int UniformColorIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Awake()
Caches the UnityEngine.MeshFilter and UnityEngine.MeshRenderer references, ensures the default material is assigned, then performs an initial mesh rebuild.
Declaration
protected virtual void Awake()
BuildMesh(Mesh)
Subclass extension point: write vertex / triangle / normal / uv data into
target from the shape's serialized parameters. The base class
calls Clear(bool) before invoking this method and
UnityEngine.Mesh.RecalculateBounds() afterwards, so subclasses should not invoke
either themselves.
Declaration
protected abstract void BuildMesh(Mesh target)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | target | The owned mesh to populate. Already cleared by the base class. |
GetMeshName()
Returns the shape's mesh name as it should appear on the generated mesh asset. Defaults to the subclass type name; override to provide a friendlier label.
Declaration
protected virtual string GetMeshName()
Returns
| Type | Description |
|---|---|
| string | A short identifier for the generated mesh, used as UnityEngine.Object.name. |
OnDestroy()
Releases the owned UnityEngine.Mesh instance and unsubscribes from
EditorApplication.delayCall if a deferred rebuild was pending.
Subclasses overriding this method must call base.OnDestroy() to avoid
leaking the mesh or the editor callback.
Declaration
protected virtual void OnDestroy()
OnValidate()
Editor-only validation hook. Schedules a deferred Rebuild() so the mesh
reflects the latest Inspector values without violating Unity's restriction on
mutating objects during OnValidate.
Declaration
protected virtual void OnValidate()
Rebuild()
Rebuilds the owned mesh from the shape's serialized parameters by invoking BuildMesh(Mesh), then refreshes the collider and tint.
Declaration
public void Rebuild()
Remarks
Safe to call from runtime, editor, and tests. When IsManuallyEdited
is true, the call is a no-op so manual mesh edits are preserved.
RebuildAndGet()
Calls Rebuild() and returns the resulting owned UnityEngine.Mesh. Intended for tween extensions and procedural systems that need a direct reference to the mesh immediately after a parameter change. The returned mesh is owned by this component and must not be destroyed by the caller.
Declaration
public Mesh RebuildAndGet()
Returns
| Type | Description |
|---|---|
| Mesh | The owned UnityEngine.Mesh after the rebuild completes. |
TryAttachPrimitiveCollider()
Subclass extension point: when ColliderMode is
MatchingPrimitive, attach the appropriate
primitive collider for this shape and return true. Return false to
let the base class fall back to UnityEngine.MeshCollider.
Declaration
protected virtual bool TryAttachPrimitiveCollider()
Returns
| Type | Description |
|---|---|
| bool |
|