new Hightlight system
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58e5a6d4728f393419100a54758a4e62
|
||||
Reference in New Issue
Block a user