using UnityEngine; using System.Collections; using System.Collections.Generic; namespace HighlightingSystem { public partial class Highlighter : MonoBehaviour { #region Editable Parameters // Constant highlighting turning on speed (common property for all Highlighters) static private float constantOnSpeed = 4.5f; // Constant highlighting turning off speed (common property for all Highlighters) static private float constantOffSpeed = 4f; // Default transparency cutoff value (used for shaders without _Cutoff property) static private float transparentCutoff = 0.5f; // Builtin layer reserved for the highlighting. This layer shouldn't be used for anything else in the project! public const int highlightingLayer = 7; // Only these types of Renderers will be highlighted static public readonly List types = new List() { typeof(MeshRenderer), typeof(SkinnedMeshRenderer), typeof(SpriteRenderer), typeof(ParticleRenderer), typeof(ParticleSystemRenderer), }; #endregion #region Public Methods /// /// Renderers reinitialization. /// Call this method if your highlighted object has changed it's materials, renderers or child objects. /// Can be called multiple times per update - renderers reinitialization will occur only once. /// public void ReinitMaterials() { renderersDirty = true; } /// /// Set color for one-frame highlighting mode. /// /// /// Highlighting color. /// public void OnParams(Color color) { onceColor = color; } /// /// Turn on one-frame highlighting. /// public void On() { // Highlight object only in this frame once = true; } /// /// Turn on one-frame highlighting with given color. /// Can be called multiple times per update, color only from the latest call will be used. /// /// /// Highlighting color. /// public void On(Color color) { // Set new color for one-frame highlighting onceColor = color; On(); } /// /// Set flashing parameters. /// /// /// Starting color. /// /// /// Ending color. /// /// /// Flashing frequency (times per second). /// public void FlashingParams(Color color1, Color color2, float freq) { flashingColorMin = color1; flashingColorMax = color2; flashingFreq = freq; } /// /// Turn on flashing. /// public void FlashingOn() { flashing = true; } /// /// Turn on flashing from color1 to color2. /// /// /// Starting color. /// /// /// Ending color. /// public void FlashingOn(Color color1, Color color2) { flashingColorMin = color1; flashingColorMax = color2; FlashingOn(); } /// /// Turn on flashing from color1 to color2 with given frequency. /// /// /// Starting color. /// /// /// Ending color. /// /// /// Flashing frequency (times per second). /// public void FlashingOn(Color color1, Color color2, float freq) { flashingFreq = freq; FlashingOn(color1, color2); } /// /// Turn on flashing with given frequency. /// /// /// Flashing frequency (times per second). /// public void FlashingOn(float freq) { flashingFreq = freq; FlashingOn(); } /// /// Turn off flashing. /// public void FlashingOff() { flashing = false; } /// /// Switch flashing mode. /// public void FlashingSwitch() { flashing = !flashing; } /// /// Set constant highlighting color. /// /// /// Constant highlighting color. /// public void ConstantParams(Color color) { constantColor = color; } /// /// Fade in constant highlighting. /// public void ConstantOn() { // Enable constant highlighting constantly = true; // Start transition transitionActive = true; } /// /// Fade in constant highlighting with given color. /// /// /// Constant highlighting color. /// public void ConstantOn(Color color) { // Set constant highlighting color constantColor = color; ConstantOn(); } /// /// Fade out constant highlighting. /// public void ConstantOff() { // Disable constant highlighting constantly = false; // Start transition transitionActive = true; } /// /// Switch Constant Highlighting. /// public void ConstantSwitch() { // Switch constant highlighting constantly = !constantly; // Start transition transitionActive = true; } /// /// Turn on constant highlighting immediately (without fading in). /// public void ConstantOnImmediate() { constantly = true; // Set transition value to 1 transitionValue = 1f; // Stop transition transitionActive = false; } /// /// Turn on constant highlighting with given color immediately (without fading in). /// /// /// Constant highlighting color. /// public void ConstantOnImmediate(Color color) { // Set constant highlighting color constantColor = color; ConstantOnImmediate(); } /// /// Turn off constant highlighting immediately (without fading out). /// public void ConstantOffImmediate() { constantly = false; // Set transition value to 0 transitionValue = 0f; // Stop transition transitionActive = false; } /// /// Switch constant highlighting immediately (without fading in/out). /// public void ConstantSwitchImmediate() { constantly = !constantly; // Set transition value to the final value transitionValue = constantly ? 1f : 0f; // Stop transition transitionActive = false; } /// /// Enable see-through mode /// public void SeeThroughOn() { seeThrough = true; } /// /// Disable see-through mode /// public void SeeThroughOff() { seeThrough = false; } /// /// Switch see-through mode /// public void SeeThroughSwitch() { seeThrough = !seeThrough; } /// /// Enable occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderOn() { occluder = true; } /// /// Disable occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderOff() { occluder = false; } /// /// Switch occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderSwitch() { occluder = !occluder; } /// /// Turn off all types of highlighting. /// public void Off() { once = false; flashing = false; constantly = false; // Set transition value to 0 transitionValue = 0f; // Stop transition transitionActive = false; } /// /// Destroy this Highlighter component. /// public void Die() { Destroy(this); } #endregion } }