new Hightlight system

This commit is contained in:
2023-12-13 20:01:38 +02:00
parent e1d2951ee0
commit 11c4d217c3
15 changed files with 267 additions and 4426 deletions
+48
View File
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using UnityEngine;
public class Hightlight : MonoBehaviour
{
[SerializeField]
private Color color = new Color(147, 142, 142, 1);
private Renderer[] renderers;
//helper list to cache all the materials ofd this object
private List<Material> materials;
//Gets all the materials from each renderer
private void Awake()
{
renderers = GetComponentsInChildren<Renderer>();
materials = new List<Material>();
foreach (var renderer in renderers)
{
//A single child-object might have mutliple materials on it
//that is why we need to all materials with "s"
materials.AddRange(new List<Material>(renderer.materials));
}
}
public void ToggleHighlight(bool val)
{
if (val)
{
foreach (var material in materials)
{
//We need to enable the EMISSION
material.EnableKeyword("_EMISSION");
//before we can set the color
material.SetColor("_EmissionColor", color);
}
}
else
{
foreach (var material in materials)
{
//we can just disable the EMISSION
//if we don't use emission color anywhere else
material.DisableKeyword("_EMISSION");
}
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 58e5a6d4728f393419100a54758a4e62