| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- using UnityEngine;
- namespace HighlightPlus {
- [CreateAssetMenu(menuName = "Highlight Plus Profile", fileName = "Highlight Plus Profile", order = 100)]
- [HelpURL("https://www.dropbox.com/s/1p9h8xys68lm4a3/Documentation.pdf?dl=0")]
- public class HighlightProfile : ScriptableObject {
- [Tooltip("Different options to specify which objects are affected by this Highlight Effect component.")]
- public TargetOptions effectGroup = TargetOptions.Children;
- [Tooltip("The layer that contains the affected objects by this effect when effectGroup is set to LayerMask.")]
- public LayerMask effectGroupLayer = -1;
- [Tooltip("Only include objects whose names contains this text.")]
- public string effectNameFilter;
- [Tooltip("Combine meshes of all objects in this group affected by Highlight Effect reducing draw calls.")]
- public bool combineMeshes;
- [Tooltip("The alpha threshold for transparent cutout objects. Pixels with alpha below this value will be discarded.")]
- [Range(0, 1)]
- public float alphaCutOff;
- [Tooltip("If back facing triangles are ignored.Backfaces triangles are not visible but you may set this property to false to force highlight effects to act on those triangles as well.")]
- public bool cullBackFaces = true;
- [Tooltip("Normals handling option:\nPreserve original: use original mesh normals.\nSmooth: average normals to produce a smoother outline/glow mesh based effect.\nReorient: recomputes normals based on vertex direction to centroid.")]
- public NormalsOption normalsOption;
- public float fadeInDuration;
- public float fadeOutDuration;
- [Tooltip("Fades out effects based on distance to camera")]
- public bool cameraDistanceFade;
- [Tooltip("The closest distance particles can get to the camera before they fade from the camera’s view.")]
- public float cameraDistanceFadeNear;
- [Tooltip("The farthest distance particles can get away from the camera before they fade from the camera’s view.")]
- public float cameraDistanceFadeFar = 1000;
- [Tooltip("Keeps the outline/glow size unaffected by object distance.")]
- public bool constantWidth = true;
- [Range(0, 1)]
- [Tooltip("Intensity of the overlay effect. A value of 0 disables the overlay completely.")]
- public float overlay;
- public OverlayMode overlayMode = OverlayMode.WhenHighlighted;
- [ColorUsage(true, true)] public Color overlayColor = Color.yellow;
- public float overlayAnimationSpeed = 1f;
- [Range(0, 1)]
- public float overlayMinIntensity = 0.5f;
- [Range(0, 1)]
- [Tooltip("Controls the blending or mix of the overlay color with the natural colors of the object.")]
- public float overlayBlending = 1.0f;
- [Tooltip("Optional overlay texture.")]
- public Texture2D overlayTexture;
- public TextureUVSpace overlayTextureUVSpace;
- public float overlayTextureScale = 1f;
- public Visibility overlayVisibility = Visibility.Normal;
-
- [Range(0, 1)]
- [Tooltip("Intensity of the outline. A value of 0 disables the outline completely.")]
- public float outline = 1f;
- [ColorUsage(true, true)] public Color outlineColor = Color.black;
- public ColorStyle outlineColorStyle = ColorStyle.SingleColor;
- [GradientUsage(hdr: true, ColorSpace.Linear)] public Gradient outlineGradient;
- public bool outlineGradientInLocalSpace;
- [Range(1, 3)]
- public int outlineBlurPasses = 2;
- public float outlineWidth = 0.45f;
- public QualityLevel outlineQuality = QualityLevel.High;
- public OutlineEdgeMode outlineEdgeMode = OutlineEdgeMode.Exterior;
- public float outlineEdgeThreshold = 0.995f;
- [Range(1, 8)]
- [Tooltip("Reduces the quality of the outline but improves performance a bit.")]
- public int outlineDownsampling = 1;
- public ContourStyle outlineContourStyle = ContourStyle.AroundVisibleParts;
- public Visibility outlineVisibility = Visibility.Normal;
- [Tooltip("If enabled, this object won't combine the outline with other objects.")]
- public bool outlineIndependent;
- [Range(0, 5)]
- [Tooltip("The intensity of the outer glow effect. A value of 0 disables the glow completely.")]
- public float glow;
- public float glowWidth = 0.4f;
- public QualityLevel glowQuality = QualityLevel.High;
- public BlurMethod glowBlurMethod = BlurMethod.Gaussian;
- [Range(1, 8)]
- [Tooltip("Reduces the quality of the glow but improves performance a bit.")]
- public int glowDownsampling = 2;
- [ColorUsage(true, true)] public Color glowHQColor = new Color(0.64f, 1f, 0f, 1f);
- [Tooltip("When enabled, outer glow renders with dithering. When disabled, glow appears as a solid color.")]
- public bool glowDithering = true;
- [Tooltip("Seed for the dithering effect")]
- public float glowMagicNumber1 = 0.75f;
- [Tooltip("Another seed for the dithering effect that combines with first seed to create different patterns")]
- public float glowMagicNumber2 = 0.5f;
- public float glowAnimationSpeed = 1f;
- public Visibility glowVisibility = Visibility.Normal;
- public GlowBlendMode glowBlendMode = GlowBlendMode.Additive;
- [Tooltip("Blends glow passes one after another. If this option is disabled, glow passes won't overlap (in this case, make sure the glow pass 1 has a smaller offset than pass 2, etc.)")]
- public bool glowBlendPasses = true;
- public GlowPassData[] glowPasses;
- [Tooltip("If enabled, glow effect will not use a stencil mask. This can be used to render the glow effect alone.")]
- public bool glowIgnoreMask;
- [Range(0, 5f)]
- [Tooltip("The intensity of the inner glow effect. A value of 0 disables the glow completely.")]
- public float innerGlow;
- [Range(0, 2)]
- public float innerGlowWidth = 1f;
- public InnerGlowBlendMode innerGlowBlendMode = InnerGlowBlendMode.Additive;
- [ColorUsage(true, true)] public Color innerGlowColor = Color.white;
- public Visibility innerGlowVisibility = Visibility.Normal;
- [Tooltip("Enables the targetFX effect. This effect draws an animated sprite over the object.")]
- public bool targetFX;
- public Texture2D targetFXTexture;
- [ColorUsage(true, true)] public Color targetFXColor = Color.white;
- public float targetFXRotationSpeed = 50f;
- public float targetFXInitialScale = 4f;
- public float targetFXEndScale = 1.5f;
- [Tooltip("Makes target scale relative to object renderer bounds.")]
- public bool targetFXScaleToRenderBounds;
- [Tooltip("Places target FX sprite at the bottom of the highlighted object.")]
- public bool targetFXAlignToGround;
- [Tooltip("Max distance from the center of the highlighted object to the ground.")]
- public float targetFXGroundMaxDistance = 15f;
- public LayerMask targetFXGroundLayerMask = -1;
- [Tooltip("Fade out effect with altitude")]
- public float targetFXFadePower = 32;
- public float targetFXTransitionDuration = 0.5f;
- public float targetFXStayDuration = 1.5f;
- public Visibility targetFXVisibility = Visibility.AlwaysOnTop;
- [Tooltip("See-through mode for this Highlight Effect component.")]
- public SeeThroughMode seeThrough = SeeThroughMode.Never;
- [Tooltip("This mask setting let you specify which objects will be considered as occluders and cause the see-through effect for this Highlight Effect component. For example, you assign your walls to a different layer and specify that layer here, so only walls and not other objects, like ground or ceiling, will trigger the see-through effect.")]
- public LayerMask seeThroughOccluderMask = -1;
- [Tooltip("Uses stencil buffers to ensure pixel-accurate occlusion test. If this option is disabled, only physics raycasting is used to test for occlusion.")]
- public bool seeThroughOccluderMaskAccurate;
- [Tooltip("A multiplier for the occluder volume size which can be used to reduce the actual size of occluders when Highlight Effect checks if they're occluding this object.")]
- [Range(0.01f, 0.9f)] public float seeThroughOccluderThreshold = 0.4f;
- [Tooltip("The interval of time between occlusion tests.")]
- public float seeThroughOccluderCheckInterval = 1f;
- [Tooltip("If enabled, occlusion test is performed for each children element. If disabled, the bounds of all children is combined and a single occlusion test is performed for the combined bounds.")]
- public bool seeThroughOccluderCheckIndividualObjects;
- [Tooltip("Shows the see-through effect only if the occluder if at this 'offset' distance from the object.")]
- public float seeThroughDepthOffset;
- [Tooltip("Hides the see-through effect if the occluder is further than this distance from the object (0 = infinite)")]
- public float seeThroughMaxDepth;
- [Range(0, 5f)] public float seeThroughIntensity = 0.8f;
- [Range(0, 1)] public float seeThroughTintAlpha = 0.5f;
- public Color seeThroughTintColor = Color.red;
- [Range(0, 1)] public float seeThroughNoise = 1f;
- [Range(0, 1)] public float seeThroughBorder;
- public Color seeThroughBorderColor = Color.black;
- public float seeThroughBorderWidth = 0.45f;
- [Tooltip("Only display the border instead of the full see-through effect.")]
- public bool seeThroughBorderOnly;
- [Tooltip("This option clears the stencil buffer after rendering the see-through effect which results in correct rendering order and supports other stencil-based effects that render afterwards.")]
- public bool seeThroughOrdered;
- [Tooltip("Optional see-through mask effect texture.")]
- public Texture2D seeThroughTexture;
- public TextureUVSpace seeThroughTextureUVSpace;
- public float seeThroughTextureScale = 1f;
- [Tooltip("The order by which children objects are rendered by the see-through effect")]
- public SeeThroughSortingMode seeThroughChildrenSortingMode = SeeThroughSortingMode.Default;
- [Range(0, 1)] public float hitFxInitialIntensity;
- public HitFxMode hitFxMode = HitFxMode.Overlay;
- public float hitFxFadeOutDuration = 0.25f;
- [ColorUsage(true, true)] public Color hitFxColor = Color.white;
- public float hitFxRadius = 0.5f;
- public void Load(HighlightEffect effect) {
- effect.effectGroup = effectGroup;
- effect.effectGroupLayer = effectGroupLayer;
- effect.effectNameFilter = effectNameFilter;
- effect.combineMeshes = combineMeshes;
- effect.alphaCutOff = alphaCutOff;
- effect.cullBackFaces = cullBackFaces;
- effect.normalsOption = normalsOption;
- effect.fadeInDuration = fadeInDuration;
- effect.fadeOutDuration = fadeOutDuration;
- effect.cameraDistanceFade = cameraDistanceFade;
- effect.cameraDistanceFadeFar = cameraDistanceFadeFar;
- effect.cameraDistanceFadeNear = cameraDistanceFadeNear;
- effect.constantWidth = constantWidth;
- effect.overlay = overlay;
- effect.overlayMode = overlayMode;
- effect.overlayColor = overlayColor;
- effect.overlayAnimationSpeed = overlayAnimationSpeed;
- effect.overlayMinIntensity = overlayMinIntensity;
- effect.overlayBlending = overlayBlending;
- effect.overlayTexture = overlayTexture;
- effect.overlayTextureUVSpace = overlayTextureUVSpace;
- effect.overlayTextureScale = overlayTextureScale;
- effect.overlayVisibility = overlayVisibility;
- effect.outline = outline;
- effect.outlineColor = outlineColor;
- effect.outlineColorStyle = outlineColorStyle;
- effect.outlineGradient = outlineGradient;
- effect.outlineGradientInLocalSpace = outlineGradientInLocalSpace;
- effect.outlineWidth = outlineWidth;
- effect.outlineBlurPasses = outlineBlurPasses;
- effect.outlineQuality = outlineQuality;
- effect.outlineEdgeMode = outlineEdgeMode;
- effect.outlineEdgeThreshold = outlineEdgeThreshold;
- effect.outlineDownsampling = outlineDownsampling;
- effect.outlineVisibility = outlineVisibility;
- effect.outlineIndependent = outlineIndependent;
- effect.outlineContourStyle = outlineContourStyle;
- effect.glow = glow;
- effect.glowWidth = glowWidth;
- effect.glowQuality = glowQuality;
- effect.glowBlurMethod = glowBlurMethod;
- effect.glowDownsampling = glowDownsampling;
- effect.glowHQColor = glowHQColor;
- effect.glowDithering = glowDithering;
- effect.glowMagicNumber1 = glowMagicNumber1;
- effect.glowMagicNumber2 = glowMagicNumber2;
- effect.glowAnimationSpeed = glowAnimationSpeed;
- effect.glowVisibility = glowVisibility;
- effect.glowBlendMode = glowBlendMode;
- effect.glowBlendPasses = glowBlendPasses;
- effect.glowPasses = GetGlowPassesCopy(glowPasses);
- effect.glowIgnoreMask = glowIgnoreMask;
- effect.innerGlow = innerGlow;
- effect.innerGlowWidth = innerGlowWidth;
- effect.innerGlowColor = innerGlowColor;
- effect.innerGlowBlendMode = innerGlowBlendMode;
- effect.innerGlowVisibility = innerGlowVisibility;
- effect.targetFX = targetFX;
- effect.targetFXColor = targetFXColor;
- effect.targetFXInitialScale = targetFXInitialScale;
- effect.targetFXEndScale = targetFXEndScale;
- effect.targetFXScaleToRenderBounds = targetFXScaleToRenderBounds;
- effect.targetFXAlignToGround = targetFXAlignToGround;
- effect.targetFXGroundMaxDistance = targetFXGroundMaxDistance;
- effect.targetFXGroundLayerMask = targetFXGroundLayerMask;
- effect.targetFXFadePower = targetFXFadePower;
- effect.targetFXRotationSpeed = targetFXRotationSpeed;
- effect.targetFXStayDuration = targetFXStayDuration;
- effect.targetFXTexture = targetFXTexture;
- effect.targetFXTransitionDuration = targetFXTransitionDuration;
- effect.targetFXVisibility = targetFXVisibility;
- effect.seeThrough = seeThrough;
- effect.seeThroughOccluderMask = seeThroughOccluderMask;
- effect.seeThroughOccluderMaskAccurate = seeThroughOccluderMaskAccurate;
- effect.seeThroughOccluderThreshold = seeThroughOccluderThreshold;
- effect.seeThroughOccluderCheckInterval = seeThroughOccluderCheckInterval;
- effect.seeThroughOccluderCheckIndividualObjects = seeThroughOccluderCheckIndividualObjects;
- effect.seeThroughIntensity = seeThroughIntensity;
- effect.seeThroughTintAlpha = seeThroughTintAlpha;
- effect.seeThroughTintColor = seeThroughTintColor;
- effect.seeThroughNoise = seeThroughNoise;
- effect.seeThroughBorder = seeThroughBorder;
- effect.seeThroughBorderColor = seeThroughBorderColor;
- effect.seeThroughBorderWidth = seeThroughBorderWidth;
- effect.seeThroughBorderOnly = seeThroughBorderOnly;
- effect.seeThroughDepthOffset = seeThroughDepthOffset;
- effect.seeThroughMaxDepth = seeThroughMaxDepth;
- effect.seeThroughOrdered = seeThroughOrdered;
- effect.seeThroughTexture = seeThroughTexture;
- effect.seeThroughTextureScale = seeThroughTextureScale;
- effect.seeThroughTextureUVSpace = seeThroughTextureUVSpace;
- effect.seeThroughChildrenSortingMode = seeThroughChildrenSortingMode;
- effect.hitFxInitialIntensity = hitFxInitialIntensity;
- effect.hitFxMode = hitFxMode;
- effect.hitFxFadeOutDuration = hitFxFadeOutDuration;
- effect.hitFxColor = hitFxColor;
- effect.hitFxRadius = hitFxRadius;
- effect.UpdateMaterialProperties();
- }
- public void Save(HighlightEffect effect) {
- effectGroup = effect.effectGroup;
- effectGroupLayer = effect.effectGroupLayer;
- effectNameFilter = effect.effectNameFilter;
- combineMeshes = effect.combineMeshes;
- alphaCutOff = effect.alphaCutOff;
- cullBackFaces = effect.cullBackFaces;
- normalsOption = effect.normalsOption;
- fadeInDuration = effect.fadeInDuration;
- fadeOutDuration = effect.fadeOutDuration;
- cameraDistanceFade = effect.cameraDistanceFade;
- cameraDistanceFadeFar = effect.cameraDistanceFadeFar;
- cameraDistanceFadeNear = effect.cameraDistanceFadeNear;
- constantWidth = effect.constantWidth;
- overlay = effect.overlay;
- overlayMode = effect.overlayMode;
- overlayColor = effect.overlayColor;
- overlayAnimationSpeed = effect.overlayAnimationSpeed;
- overlayMinIntensity = effect.overlayMinIntensity;
- overlayBlending = effect.overlayBlending;
- overlayTexture = effect.overlayTexture;
- overlayTextureUVSpace = effect.overlayTextureUVSpace;
- overlayTextureScale = effect.overlayTextureScale;
- overlayVisibility = effect.overlayVisibility;
- outline = effect.outline;
- outlineColor = effect.outlineColor;
- outlineColorStyle = effect.outlineColorStyle;
- outlineGradient = effect.outlineGradient;
- outlineGradientInLocalSpace = effect.outlineGradientInLocalSpace;
- outlineWidth = effect.outlineWidth;
- outlineBlurPasses = effect.outlineBlurPasses;
- outlineQuality = effect.outlineQuality;
- outlineEdgeMode = effect.outlineEdgeMode;
- outlineEdgeThreshold = effect.outlineEdgeThreshold;
- outlineDownsampling = effect.outlineDownsampling;
- outlineVisibility = effect.outlineVisibility;
- outlineIndependent = effect.outlineIndependent;
- outlineContourStyle = effect.outlineContourStyle;
- glow = effect.glow;
- glowWidth = effect.glowWidth;
- glowQuality = effect.glowQuality;
- glowBlurMethod = effect.glowBlurMethod;
- glowDownsampling = effect.glowDownsampling;
- glowHQColor = effect.glowHQColor;
- glowDithering = effect.glowDithering;
- glowMagicNumber1 = effect.glowMagicNumber1;
- glowMagicNumber2 = effect.glowMagicNumber2;
- glowAnimationSpeed = effect.glowAnimationSpeed;
- glowVisibility = effect.glowVisibility;
- glowBlendMode = effect.glowBlendMode;
- glowBlendPasses = effect.glowBlendPasses;
- glowPasses = GetGlowPassesCopy(effect.glowPasses);
- glowIgnoreMask = effect.glowIgnoreMask;
- innerGlow = effect.innerGlow;
- innerGlowWidth = effect.innerGlowWidth;
- innerGlowColor = effect.innerGlowColor;
- innerGlowBlendMode = effect.innerGlowBlendMode;
- innerGlowVisibility = effect.innerGlowVisibility;
- targetFX = effect.targetFX;
- targetFXColor = effect.targetFXColor;
- targetFXInitialScale = effect.targetFXInitialScale;
- targetFXEndScale = effect.targetFXEndScale;
- targetFXScaleToRenderBounds = effect.targetFXScaleToRenderBounds;
- targetFXAlignToGround = effect.targetFXAlignToGround;
- targetFXGroundMaxDistance = effect.targetFXGroundMaxDistance;
- targetFXGroundLayerMask = effect.targetFXGroundLayerMask;
- targetFXFadePower = effect.targetFXFadePower;
- targetFXRotationSpeed = effect.targetFXRotationSpeed;
- targetFXStayDuration = effect.targetFXStayDuration;
- targetFXTexture = effect.targetFXTexture;
- targetFXTransitionDuration = effect.targetFXTransitionDuration;
- targetFXVisibility = effect.targetFXVisibility;
- seeThrough = effect.seeThrough;
- seeThroughOccluderMask = effect.seeThroughOccluderMask;
- seeThroughOccluderMaskAccurate = effect.seeThroughOccluderMaskAccurate;
- seeThroughOccluderThreshold = effect.seeThroughOccluderThreshold;
- seeThroughOccluderCheckInterval = effect.seeThroughOccluderCheckInterval;
- seeThroughOccluderCheckIndividualObjects = effect.seeThroughOccluderCheckIndividualObjects;
- seeThroughIntensity = effect.seeThroughIntensity;
- seeThroughTintAlpha = effect.seeThroughTintAlpha;
- seeThroughTintColor = effect.seeThroughTintColor;
- seeThroughNoise = effect.seeThroughNoise;
- seeThroughBorder = effect.seeThroughBorder;
- seeThroughBorderColor = effect.seeThroughBorderColor;
- seeThroughBorderWidth = effect.seeThroughBorderWidth;
- seeThroughDepthOffset = effect.seeThroughDepthOffset;
- seeThroughBorderOnly = effect.seeThroughBorderOnly;
- seeThroughMaxDepth = effect.seeThroughMaxDepth;
- seeThroughOrdered = effect.seeThroughOrdered;
- seeThroughTexture = effect.seeThroughTexture;
- seeThroughTextureScale = effect.seeThroughTextureScale;
- seeThroughTextureUVSpace = effect.seeThroughTextureUVSpace;
- seeThroughChildrenSortingMode = effect.seeThroughChildrenSortingMode;
- hitFxInitialIntensity = effect.hitFxInitialIntensity;
- hitFxMode = effect.hitFxMode;
- hitFxFadeOutDuration = effect.hitFxFadeOutDuration;
- hitFxColor = effect.hitFxColor;
- hitFxRadius = effect.hitFxRadius;
- }
- GlowPassData[] GetGlowPassesCopy(GlowPassData[] glowPasses) {
- if (glowPasses == null) {
- return new GlowPassData[0];
- }
- GlowPassData[] pd = new GlowPassData[glowPasses.Length];
- for (int k = 0; k < glowPasses.Length; k++) {
- pd[k].alpha = glowPasses[k].alpha;
- pd[k].color = glowPasses[k].color;
- pd[k].offset = glowPasses[k].offset;
- }
- return pd;
- }
- private void OnValidate() {
- outlineEdgeThreshold = Mathf.Clamp01(outlineEdgeThreshold);
- seeThroughDepthOffset = Mathf.Max(0, seeThroughDepthOffset);
- seeThroughMaxDepth = Mathf.Max(0, seeThroughMaxDepth);
- seeThroughBorderWidth = Mathf.Max(0, seeThroughBorderWidth);
- targetFXFadePower = Mathf.Max(0, targetFXFadePower);
- cameraDistanceFadeNear = Mathf.Max(0, cameraDistanceFadeNear);
- cameraDistanceFadeFar = Mathf.Max(0, cameraDistanceFadeFar);
- if (glowPasses == null || glowPasses.Length == 0) {
- glowPasses = new GlowPassData[4];
- glowPasses[0] = new GlowPassData() { offset = 4, alpha = 0.1f, color = new Color(0.64f, 1f, 0f, 1f) };
- glowPasses[1] = new GlowPassData() { offset = 3, alpha = 0.2f, color = new Color(0.64f, 1f, 0f, 1f) };
- glowPasses[2] = new GlowPassData() { offset = 2, alpha = 0.3f, color = new Color(0.64f, 1f, 0f, 1f) };
- glowPasses[3] = new GlowPassData() { offset = 1, alpha = 0.4f, color = new Color(0.64f, 1f, 0f, 1f) };
- }
- }
- }
- }
|