-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
here is my simple realization of Behaviour, that adds to OutlineLayerCollection to specific level.
Odin Inspector is used, but you can get the point:
` [DisallowMultipleComponent]
[ExecuteInEditMode]
public class Outline : MonoBehaviour
{
[SerializeField, Required] private OutlineLayerCollection _collection;
[field: SerializeField, OnValueChanged("OnLayerChanged"), PropertyRange(0, "MaxLayer")] private int _layer;
[UsedImplicitly] private int MaxLayer => (int)_collection?.Count - 1;
private void OnEnable() => AddGameObject(gameObject, _layer);
private void OnDisable() => RemoveGameObject(gameObject);
public void SetLayer(int layer) => OnLayerChanged(layer);
private void OnLayerChanged(int layer)
{
_layer = layer;
if (!isActiveAndEnabled)
return;
OnDisable();
OnEnable();
}
/// <summary>
/// Adds the <see cref="GameObject"/> passed to the specified outline layer. Creates the layer if needed.
/// </summary>
/// <param name="go">The <see cref="GameObject"/> to add and render outline for.</param>
/// <seealso cref="AddGameObject(GameObject)"/>
private void AddGameObject(GameObject go, int layerIndex)
{
if (layerIndex < 0)
{
throw new ArgumentOutOfRangeException("layerIndex");
}
_collection[layerIndex].Add(go);
}
/// <summary>
/// Removes the specified <see cref="GameObject"/> from <see cref="OutlineLayers"/>.
/// </summary>
/// <param name="go">A <see cref="GameObject"/> to remove.</param>
public void RemoveGameObject(GameObject go)
{
if (_collection)
{
_collection.Remove(go);
}
}
}`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels