Game.Prefabs.IColored
Assembly:
Assembly-CSharp.dll (typical Unity/game assembly; actual assembly name may vary)
Namespace:
Game.Prefabs
Type:
interface
Base:
None (interfaces do not declare a base type; implicitly inherit from System.Object)
Summary:
Defines a simple contract for objects (typically prefabs/components) that expose a color value. The interface exposes a read-only UnityEngine.Color32 property named color
, commonly used by rendering code, UI, or tools that need to query a prefab's or component's color.
Fields
This interface declares no fields. Implementations may store a backing Color32 field or serialize a Color/Color32 on a component.
Properties
public UnityEngine.Color32 color { get; }
Read-only Color32 value (RGBA bytes). Use this to obtain the object's color in byte-based form. If you need a normalized float-based Color, convert vianew Color(color.r/255f, color.g/255f, color.b/255f, color.a/255f)
or useColor32
implicit conversion toColor
.
Constructors
Interfaces do not declare constructors. Concrete types implementing IColored will provide their own constructors or MonoBehaviour lifecycle initialization.
Methods
This interface declares no methods. Implementing types may provide additional methods or properties as needed.
Usage Example
using UnityEngine;
using Game.Prefabs;
public class MyColoredPrefab : MonoBehaviour, IColored
{
[SerializeField]
private Color32 m_color = new Color32(200, 120, 80, 255);
// Implement IColored
public Color32 color => m_color;
// Example usage inside the component
private void Start()
{
// Convert to Color (float) if needed
Color floatColor = m_color;
// Apply to a Renderer if present
var rend = GetComponent<Renderer>();
if (rend != null)
{
rend.material.color = floatColor;
}
}
}
// Example of reading the color from any GameObject
public static class ColorHelpers
{
public static void LogObjectColor(GameObject go)
{
var colored = go.GetComponent<IColored>();
if (colored != null)
{
Color32 c = colored.color;
Debug.Log($"Object color: r={c.r}, g={c.g}, b={c.b}, a={c.a}");
}
else
{
Debug.Log("Object does not implement IColored");
}
}
}
Notes: - Color32 is a byte-based representation (0–255) for RGBA. For shader/material APIs expecting UnityEngine.Color (float), implicit conversion is available. - Because the property is read-only, implementations should provide a serialized backing field (e.g., [SerializeField] Color32) if designers need to set it in the inspector.