using UnityEngine; using System.Collections; using System.Collections.Generic; namespace HighlightingSystem { public partial class Highlighter : MonoBehaviour { #region Editable Parameters // 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() { once = true; } /// /// Turn on one-frame highlighting with specified color. /// Can be called multiple times per update, color only from the latest call will be used. /// /// /// Highlighting color. /// public void On(Color color) { onceColor = color; once = true; } /// /// 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; flashing = true; } /// /// Turn on flashing from color1 to color2 and specified frequency. /// /// /// Starting color. /// /// /// Ending color. /// /// /// Flashing frequency (times per second). /// public void FlashingOn(Color color1, Color color2, float freq) { flashingColorMin = color1; flashingColorMax = color2; flashingFreq = freq; flashing = true; } /// /// Turn on flashing with specified frequency. /// /// /// Flashing frequency (times per second). /// public void FlashingOn(float freq) { flashingFreq = freq; flashing = true; } /// /// 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 using specified transition duration. /// /// /// Transition time. /// public void ConstantOn(float time = 0.25f) { transitionTime = (time >= 0f ? time : 0f); transitionTarget = 1f; } /// /// Fade in constant highlighting using specified color and transition duration. /// /// /// Constant highlighting color. /// /// /// Transition duration. /// public void ConstantOn(Color color, float time = 0.25f) { constantColor = color; transitionTime = (time >= 0f ? time : 0f); transitionTarget = 1f; } /// /// Fade out constant highlighting using specified transition duration. /// /// /// Transition time. /// public void ConstantOff(float time = 0.25f) { transitionTime = (time >= 0f ? time : 0f); transitionTarget = 0f; } /// /// Switch constant highlighting using specified transition duration. /// /// /// Transition time. /// public void ConstantSwitch(float time = 0.25f) { transitionTime = (time >= 0f ? time : 0f); transitionTarget = (transitionTarget > 0f ? 0f : 1f); } /// /// Turn on constant highlighting immediately (without fading in). /// public void ConstantOnImmediate() { transitionValue = transitionTarget = 1f; } /// /// Turn on constant highlighting using specified color immediately (without fading in). /// /// /// Constant highlighting color. /// public void ConstantOnImmediate(Color color) { constantColor = color; transitionValue = transitionTarget = 1f; } /// /// Turn off constant highlighting immediately (without fading out). /// public void ConstantOffImmediate() { transitionValue = transitionTarget = 0f; } /// /// Switch constant highlighting immediately (without fading in/out). /// public void ConstantSwitchImmediate() { transitionValue = transitionTarget = (transitionTarget > 0f ? 0f : 1f); } /// /// Turn off all types of highlighting (occlusion mode remains intact). /// public void Off() { once = false; flashing = false; transitionValue = transitionTarget = 0f; } /// /// Destroy this Highlighter component. /// public void Die() { Destroy(this); } #endregion #region Deprecated Methods /// /// DEPRECATED. Use seeThrough property directly. Set see-through mode /// public void SeeThrough(bool state) { seeThrough = state; } /// /// DEPRECATED. Use seeThrough property directly. Enable see-through mode /// public void SeeThroughOn() { seeThrough = true; } /// /// DEPRECATED. Use seeThrough property directly. Disable see-through mode /// public void SeeThroughOff() { seeThrough = false; } /// /// DEPRECATED. Use seeThrough property directly. Switch see-through mode /// public void SeeThroughSwitch() { seeThrough = !seeThrough; } /// /// DEPRECATED. Use occluder property directly. Enable occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderOn() { occluder = true; } /// /// DEPRECATED. Use occluder property directly. Disable occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderOff() { occluder = false; } /// /// DEPRECATED. Use occluder property directly. Switch occluder mode. Non-see-through occluders will be used only in case frame depth buffer is not accessible. /// public void OccluderSwitch() { occluder = !occluder; } #endregion } }