using AppleHills; using System.Collections.Generic; using UnityEngine; using Core.Lifecycle; public class GlowOutline : ManagedBehaviour { private SpriteRenderer parentSprite; private SpriteRenderer outlineSprite; private Color outlineColor; private Transform[] childrenTransforms; private SpriteRenderer[] childrenSprites; private Material[] childrenMaterials; private List outlineColors; public float thiccness; public GlowOutlineData.InteractionType interactionType; internal override void OnManagedStart() { SetupOutline(); } private void SetupOutline() { // Get references to item sprite, own sprite and the outline settings from Interaction Settings outlineColors = SettingsAccess.GetInteractionOutlineColors(); outlineSprite = GetComponent(); // Get the transforms and spriterenderers of children childrenTransforms = GetComponentsInChildren(); childrenSprites = GetComponentsInChildren(); // childrenMaterials = GetComponentsInChildren(); // 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()) { if (sprite != this.GetComponent()) { 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 }