Made outline shader debuggable in editor

This commit is contained in:
journaliciouz
2025-12-11 21:19:31 +01:00
parent e7141b79c5
commit ca84414998
13 changed files with 7485 additions and 83 deletions

View File

@@ -1,20 +1,26 @@
using System;
using AppleHills;
using System.Collections.Generic;
using UnityEngine;
using Core.Lifecycle;
public class GlowOutline : MonoBehaviour
public class GlowOutline : ManagedBehaviour
{
private SpriteRenderer parentSprite;
private SpriteRenderer outlineSprite;
private Color outlineColor;
private Transform[] childrenTransforms;
private SpriteRenderer[] childrenSprites;
private Material[] childrenMaterials;
private List<GlowOutlineData> outlineColors;
public float thiccness;
public GlowOutlineData.InteractionType interactionType;
public float scaleFactor;
public GlowOutlineData[] outlineModes;
private void OnEnable()
internal override void OnManagedStart()
{
SetupOutline();
}
@@ -22,12 +28,61 @@ public class GlowOutline : MonoBehaviour
private void SetupOutline()
{
parentSprite = GetComponentInParent<SpriteRenderer>();
// Get references to item sprite, own sprite and the outline settings from Interaction Settings
outlineColors = SettingsAccess.GetInteractionOutlineColors();
outlineSprite = GetComponent<SpriteRenderer>();
outlineSprite.sprite = parentSprite.sprite;
gameObject.transform.localScale = gameObject.transform.localScale * scaleFactor;
//outlineSprite.color = outlineColour;
// Get the transforms and spriterenderers of children
childrenTransforms = GetComponentsInChildren<Transform>();
childrenSprites = GetComponentsInChildren<SpriteRenderer>();
// childrenMaterials = GetComponentsInChildren<Material>();
// Set the color overlay of the sprites to colour our outline with the colors set in Interaction Settings
foreach (GlowOutlineData data in outlineColors)
{
if (data.interaction == interactionType)
{
outlineColor = data.outlineColour;
Debug.Log(outlineColor);
}
}
// Find the spriterenderer in parent gameobject, but ignore our own spriterenderer
foreach (SpriteRenderer sprite in GetComponentsInParent<SpriteRenderer>())
{
if (sprite != this.GetComponent<SpriteRenderer>())
{
parentSprite = sprite;
}
}
// Set the scale and sprite of each child. Skip first child because that's the outline object.
childrenTransforms[1].localPosition = new Vector3(1, 0, 0) * thiccness;
childrenTransforms[2].localPosition = new Vector3(-1, 0, 0) * thiccness;
childrenTransforms[3].localPosition = new Vector3(0, 1, 0) * thiccness;
childrenTransforms[4].localPosition = new Vector3(0, -1, 0) * thiccness;
foreach (SpriteRenderer childSprite in childrenSprites)
{
childSprite.sprite = parentSprite.sprite;
childSprite.material.color = outlineColor;
}
}
#if UNITY_EDITOR
// Update outline in editor
private void OnValidate()
{
SetupOutline();
}
#endif
}