86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using AppleHills;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Core.Lifecycle;
|
|
|
|
public class GlowOutline : ManagedBehaviour
|
|
{
|
|
|
|
private SpriteRenderer parentSprite;
|
|
private Color outlineColor;
|
|
private Transform[] childrenTransforms;
|
|
private SpriteRenderer[] childrenSprites;
|
|
private List<GlowOutlineData> 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();
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|