From e08cb72d38015e07deffb4bdf3fd5a39937e3237 Mon Sep 17 00:00:00 2001 From: YangHua <1475658476@qq.com> Date: Sun, 22 Oct 2023 16:58:10 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=97=A0=E4=BA=BA=E6=9C=BA=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E8=8F=9C=E5=8D=95=E6=94=BB=E5=87=BB=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E8=A1=A5=E5=85=A8=EF=BC=8C=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E4=B8=BA=E7=82=B9=E5=87=BB=E6=94=BB=E5=87=BB=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E9=80=89=E6=8B=A9=E6=95=8C=E6=96=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=EF=BC=8C=E9=A3=9E=E8=A1=8C=E8=87=B3=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E9=99=84=E8=BF=91=E8=BF=9B=E8=A1=8C=E6=89=93=E6=9C=BA?= =?UTF-8?q?=E3=80=82=E4=B8=8E=E8=AE=BE=E7=BD=AE=E8=88=AA=E7=BA=BF=E4=B8=BA?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E5=8A=9F=E8=83=BD=202=E3=80=81=E6=BF=80?= =?UTF-8?q?=E5=85=89=E7=81=AB=E7=82=AE=E6=89=93=E6=9C=BA=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E7=A8=8B=E5=BA=8F=E5=BC=82=E5=B8=B8=203?= =?UTF-8?q?=E3=80=81=E5=AD=90=E5=BC=B9=E5=B0=84=E9=80=9F=E5=8A=A0=E5=BF=AB?= =?UTF-8?q?=E3=80=82=204=E3=80=81=E6=B7=BB=E5=8A=A0=E6=97=A0=E4=BA=BA?= =?UTF-8?q?=E6=9C=BA=E5=BC=B9=E8=8D=AF=E6=95=B0=E4=B8=BA30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/GameAssets/Prefebs/LinePoint.prefab | 6 +- .../Prefebs/Models/无人机List.prefab | 80 ++ .../HighlightingSystem.meta} | 2 +- Assets/Plugins/HighlightingSystem/Editor.meta | 5 + .../Editor/HighlighterEditor.cs | 260 +++++ .../Editor/HighlighterEditor.cs.meta | 13 + .../Editor/HighlightingBlitterEditor.cs | 15 + .../Editor/HighlightingBlitterEditor.cs.meta | 12 + .../Editor/HighlightingPresetEditor.cs | 79 ++ .../Editor/HighlightingPresetEditor.cs.meta | 12 + .../Editor/HighlightingRendererEditor.cs | 369 +++++++ .../Editor/HighlightingRendererEditor.cs.meta | 8 + .../Plugins/HighlightingSystem/Resources.meta | 5 + .../Resources/HighlightingBlur.shader | 172 ++++ .../Resources/HighlightingBlur.shader.meta | 5 + .../Resources/HighlightingComposite.shader | 72 ++ .../HighlightingComposite.shader.meta | 5 + .../Resources/HighlightingCut.shader | 111 +++ .../Resources/HighlightingCut.shader.meta | 5 + .../Resources/HighlightingOpaque.shader | 88 ++ .../Resources/HighlightingOpaque.shader.meta | 5 + .../Resources/HighlightingTransparent.shader | 108 +++ .../HighlightingTransparent.shader.meta | 5 + .../Plugins/HighlightingSystem/Scripts.meta | 5 + .../HighlightingSystem/Scripts/Highlighter.cs | 899 ++++++++++++++++++ .../Scripts/Highlighter.cs.meta | 8 + .../Scripts/HighlighterBlocker.cs | 11 + .../Scripts/HighlighterBlocker.cs.meta | 12 + .../Scripts/HighlightingBlitter.cs | 68 ++ .../Scripts/HighlightingBlitter.cs.meta | 12 + .../Scripts/HighlightingRenderer.cs | 129 +++ .../Scripts/HighlightingRenderer.cs.meta | 15 + .../HighlightingSystem/Scripts/Internal.meta | 5 + .../Scripts/Internal/EndOfFrame.cs | 96 ++ .../Scripts/Internal/EndOfFrame.cs.meta | 12 + .../Scripts/Internal/HighlighterCore.cs | 548 +++++++++++ .../Scripts/Internal/HighlighterCore.cs.meta | 13 + .../Scripts/Internal/HighlighterRenderer.cs | 215 +++++ .../Internal/HighlighterRenderer.cs.meta | 12 + .../Scripts/Internal/HighlightingBase.cs | 634 ++++++++++++ .../Scripts/Internal/HighlightingBase.cs.meta | 8 + .../Scripts/Internal/HighlightingPreset.cs | 43 + .../Internal/HighlightingPreset.cs.meta | 12 + .../Scripts/Internal/MaterialExtensions.cs | 16 + .../Internal/MaterialExtensions.cs.meta | 13 + .../Scripts/Internal/ShaderPropertyID.cs | 24 + .../Scripts/Internal/ShaderPropertyID.cs.meta | 8 + .../AdamTraining_pilot_terminal_panl 1.unity | 619 +++++++++++- .../Adam/Components/BulletController.cs | 6 +- .../Zion/Scripts/Adam/Components/On3DClick.cs | 31 + .../Scripts/Adam/Components/On3DClick.cs.meta | 11 + .../Adam/FiniteStateMachines/DrawingState.cs | 3 +- Assets/Zion/Scripts/Adam/HuoPaoController.cs | 27 +- Assets/Zion/Scripts/Adam/ToolsBootstrap.cs | 39 +- Assets/Zion/Scripts/Adam/WRJController.cs | 104 +- Assets/Zion/Scripts/Adam/WRJManager.cs | 5 +- Packages/manifest.json | 1 + Packages/packages-lock.json | 7 + ProjectSettings/ProjectSettings.asset | 14 +- ProjectSettings/QualitySettings.asset | 2 +- ProjectSettings/TagManager.asset | 6 +- 61 files changed, 5070 insertions(+), 65 deletions(-) rename Assets/{StreamingAssets.meta => Plugins/HighlightingSystem.meta} (77%) create mode 100644 Assets/Plugins/HighlightingSystem/Editor.meta create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs create mode 100644 Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader.meta create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader create mode 100644 Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs.meta create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs create mode 100644 Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs.meta create mode 100644 Assets/Zion/Scripts/Adam/Components/On3DClick.cs create mode 100644 Assets/Zion/Scripts/Adam/Components/On3DClick.cs.meta diff --git a/Assets/GameAssets/Prefebs/LinePoint.prefab b/Assets/GameAssets/Prefebs/LinePoint.prefab index d704b560..a355b41b 100644 --- a/Assets/GameAssets/Prefebs/LinePoint.prefab +++ b/Assets/GameAssets/Prefebs/LinePoint.prefab @@ -12,7 +12,7 @@ GameObject: - component: {fileID: 5180839583983594084} - component: {fileID: 1550731372138684840} - component: {fileID: 8476325289806523627} - m_Layer: 5 + m_Layer: 0 m_Name: Sphere m_TagString: Untagged m_Icon: {fileID: 0} @@ -102,8 +102,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1547420170257315258} - m_Layer: 5 - m_Name: Point + m_Layer: 0 + m_Name: LinePoint m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/GameAssets/Prefebs/Models/无人机List.prefab b/Assets/GameAssets/Prefebs/Models/无人机List.prefab index 08219843..9f14aa1c 100644 --- a/Assets/GameAssets/Prefebs/Models/无人机List.prefab +++ b/Assets/GameAssets/Prefebs/Models/无人机List.prefab @@ -135,6 +135,8 @@ GameObject: - component: {fileID: 6865737300552731159} - component: {fileID: 6865737300552731156} - component: {fileID: 41106886} + - component: {fileID: 1432105532577387308} + - component: {fileID: 3231389817124393935} m_Layer: 9 m_Name: "\u65E0\u4EBA\u673AList" m_TagString: Untagged @@ -191,6 +193,7 @@ MonoBehaviour: index1: 0 speed: 100 huoPaoControllerList: [] + attackTarget: [] isMove: 0 dis: 0 limitDis: 0 @@ -198,6 +201,8 @@ MonoBehaviour: firePrefab: {fileID: 3257275699554257525, guid: deb8a70a5ca26dd41b3c33876785f507, type: 3} isGoToPlace: 0 + isAuto: 0 + fireCount: 30 currentHuoPaoIndex: 0 --- !u!65 &41106886 BoxCollider: @@ -212,6 +217,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 6.96, y: 2.32, z: 4.92} m_Center: {x: 0, y: 1.5, z: 0.19} +--- !u!114 &1432105532577387308 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6865737300552731157} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &3231389817124393935 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6865737300552731157} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1001 &6865737299184050514 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/StreamingAssets.meta b/Assets/Plugins/HighlightingSystem.meta similarity index 77% rename from Assets/StreamingAssets.meta rename to Assets/Plugins/HighlightingSystem.meta index 809ab66b..d2013b8a 100644 --- a/Assets/StreamingAssets.meta +++ b/Assets/Plugins/HighlightingSystem.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2867c644cac2f7b488d4acbc11bd2ea4 +guid: 0610fddf11f98ba419a3c3dc100496ee folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins/HighlightingSystem/Editor.meta b/Assets/Plugins/HighlightingSystem/Editor.meta new file mode 100644 index 00000000..381db328 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 4de23785d38293b47b1aa97aef36ef95 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs b/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs new file mode 100644 index 00000000..3e99dee4 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs @@ -0,0 +1,260 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using UnityEditorInternal; + +namespace HighlightingSystem +{ + [CustomEditor(typeof(Highlighter)), CanEditMultipleObjects] + public class HighlighterEditor : Editor + { + private const string kShowTweenKey = "HighlightingSystem.Highlighter.ShowTween"; + private const string kShowConstantKey = "HighlightingSystem.Highlighter.ShowConstant"; + private const string kShowFilterKey = "HighlightingSystem.Highlighter.ShowFilter"; + + static private readonly GUIContent labelOverlay = new GUIContent("Overlay"); + static private readonly GUIContent labelOccluder = new GUIContent("Occluder"); + static private readonly GUIContent labelColor = new GUIContent("Color (Current)"); + static private readonly GUIContent labelForceRender = new GUIContent("Force Render"); + + static private readonly GUIContent labelTween = new GUIContent("Tween"); + static private readonly GUIContent labelGradient = new GUIContent("Gradient"); + static private readonly GUIContent labelDuration = new GUIContent("Duration"); + static private readonly GUIContent labelUseUnscaledTime = new GUIContent("Use Unscaled Time"); + static private readonly GUIContent labelDelay = new GUIContent("Delay"); + static private readonly GUIContent labelLoopMode = new GUIContent("Loop Mode"); + static private readonly GUIContent labelEasing = new GUIContent("Easing"); + static private readonly GUIContent labelReverse = new GUIContent("Reverse"); + static private readonly GUIContent labelRepeatCount = new GUIContent("Repeat Count"); + + static private readonly GUIContent labelConstant = new GUIContent("Constant"); + static private readonly GUIContent labelConstantColor = new GUIContent("Constant Color"); + static private readonly GUIContent labelFadeInTime = new GUIContent("Fade In Time"); + static private readonly GUIContent labelFadeOutTime = new GUIContent("Fade Out Time"); + + static private readonly GUIContent labelFilterMode = new GUIContent("Mode"); + static private readonly GUIContent labelFilterList = new GUIContent("Transform Filtering List"); + + static private readonly GUIContent labelGroupTween = new GUIContent("Tween"); + static private readonly GUIContent labelGroupConstant = new GUIContent("Constant"); + static private readonly GUIContent labelGroupFilter = new GUIContent("Filter"); + + private Dictionary fieldCache = new Dictionary(); + private Highlighter highlighter; + private SerializedProperty propertyFilterList; + + private ReorderableList listFilter; + + private bool showTween; + private bool showConstant; + private bool showFilter; + + // + void OnEnable() + { + highlighter = target as Highlighter; + + propertyFilterList = serializedObject.FindProperty("_filterList"); + + showTween = EditorPrefs.GetBool(kShowTweenKey, false); + showConstant = EditorPrefs.GetBool(kShowConstantKey, false); + showFilter = EditorPrefs.GetBool(kShowFilterKey, false); + + listFilter = new ReorderableList(serializedObject, propertyFilterList, true, true, true, true); + listFilter.drawHeaderCallback = new ReorderableList.HeaderCallbackDelegate(FilterListDrawHeader); + listFilter.onAddCallback = new ReorderableList.AddCallbackDelegate(FilterListAdd); + listFilter.onRemoveCallback = new ReorderableList.RemoveCallbackDelegate(FilterListRemove); + listFilter.drawElementCallback = new ReorderableList.ElementCallbackDelegate(FilterListDrawElement); + listFilter.elementHeight = EditorGUIUtility.singleLineHeight + 2f; + } + + // + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUI.BeginChangeCheck(); + + DoGeneralGUI(); + DoHighlighterGUI(); + + if (EditorGUI.EndChangeCheck()) + { + serializedObject.ApplyModifiedProperties(); + } + } + + // + private void DoGeneralGUI() + { + // General + EditorGUILayout.PropertyField(FindField("_overlay"), labelOverlay); + EditorGUILayout.PropertyField(FindField("_occluder"), labelOccluder); + EditorGUILayout.PropertyField(FindField("forceRender"), labelForceRender); + + // Current color (readonly, since Highlighter component overrides it's value every frame) + using (new EditorGUI.DisabledScope(true)) + { + EditorGUILayout.PropertyField(FindField("color"), labelColor); + } + } + + // + private void DoHighlighterGUI() + { + // Tween + if (Foldout(labelGroupTween, ref showTween, kShowTweenKey)) + { + using (new EditorGUI.IndentLevelScope()) + { + EditorGUILayout.PropertyField(FindField("_tween"), labelTween); + EditorGUILayout.PropertyField(FindField("_tweenGradient"), labelGradient); + //DoSpectrumButtonGUI(); + EditorGUILayout.PropertyField(FindField("_tweenDuration"), labelDuration); + EditorGUILayout.PropertyField(FindField("_tweenReverse"), labelReverse); + EditorGUILayout.PropertyField(FindField("_tweenLoop"), labelLoopMode); + EditorGUILayout.PropertyField(FindField("_tweenEasing"), labelEasing); + EditorGUILayout.PropertyField(FindField("_tweenDelay"), labelDelay); + EditorGUILayout.PropertyField(FindField("_tweenRepeatCount"), labelRepeatCount); + EditorGUILayout.PropertyField(FindField("_tweenUseUnscaledTime"), labelUseUnscaledTime); + } + } + + // Constant + if (Foldout(labelGroupConstant, ref showConstant, kShowConstantKey)) + { + using (new EditorGUI.IndentLevelScope()) + { + EditorGUILayout.PropertyField(FindField("_constant"), labelConstant); + EditorGUILayout.PropertyField(FindField("_constantColor"), labelConstantColor); + EditorGUILayout.PropertyField(FindField("_constantFadeInTime"), labelFadeInTime); + EditorGUILayout.PropertyField(FindField("_constantFadeOutTime"), labelFadeOutTime); + EditorGUILayout.PropertyField(FindField("_constantEasing"), labelEasing); + EditorGUILayout.PropertyField(FindField("_constantUseUnscaledTime"), labelUseUnscaledTime); + } + } + + if (Foldout(labelGroupFilter, ref showFilter, kShowFilterKey)) + { + using (new EditorGUI.IndentLevelScope()) + { + // filterMode + SerializedProperty fieldFilterMode = FindField("_filterMode"); + EditorGUILayout.PropertyField(fieldFilterMode, labelFilterMode); + + if (!fieldFilterMode.hasMultipleDifferentValues) + { + RendererFilterMode filterMode = (RendererFilterMode)fieldFilterMode.enumValueIndex; + + if (highlighter.rendererFilter != null) + { + EditorGUILayout.HelpBox("Custom RendererFilter assigned to this Highlighter. Filtering list disabled.", MessageType.Warning); + } + else + { + switch (filterMode) + { + case RendererFilterMode.None: + EditorGUILayout.HelpBox("All Renderers found in child GameObjects will be highlighted.", MessageType.Info); + break; + case RendererFilterMode.Include: + EditorGUILayout.HelpBox("Renderers only on specified Transforms (and any of their children) will be highlighted.", MessageType.Info); + break; + case RendererFilterMode.Exclude: + EditorGUILayout.HelpBox("Renderers on specified Transforms (and any of their children) will be excluded from highlighting.", MessageType.Info); + break; + } + } + } + + // filterList + Rect rect = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(0f, listFilter.GetHeight())); + listFilter.DoList(rect); + } + } + } + + // + private SerializedProperty FindField(string fieldPath) + { + SerializedProperty field; + if (!fieldCache.TryGetValue(fieldPath, out field)) + { + field = serializedObject.FindProperty(fieldPath); + fieldCache.Add(fieldPath, field); + } + return field; + } + + // + private bool Foldout(GUIContent content, ref bool isExpanded, string key) + { + Rect rect = GUILayoutUtility.GetRect(content, EditorStyles.foldout); + bool expanded = EditorGUI.Foldout(rect, isExpanded, content, true, EditorStyles.foldout); + if (expanded != isExpanded && !string.IsNullOrEmpty(key)) + { + isExpanded = expanded; + EditorPrefs.SetBool(key, isExpanded); + } + return isExpanded; + } + + // + private void DoSpectrumButtonGUI() + { + // Spectrum + if (GUILayout.Button("Spectrum")) + { + highlighter.tweenGradient = new Gradient() + { + colorKeys = new GradientColorKey[] + { + new GradientColorKey(new Color(1f, 0f, 0f, 1f), 0f / 6f), + new GradientColorKey(new Color(1f, 1f, 0f, 1f), 1f / 6f), + new GradientColorKey(new Color(0f, 1f, 0f, 1f), 2f / 6f), + new GradientColorKey(new Color(0f, 1f, 1f, 1f), 3f / 6f), + new GradientColorKey(new Color(0f, 0f, 1f, 1f), 4f / 6f), + new GradientColorKey(new Color(1f, 0f, 1f, 1f), 5f / 6f), + new GradientColorKey(new Color(1f, 0f, 0f, 1f), 6f / 6f), + }, + alphaKeys = new GradientAlphaKey[] + { + new GradientAlphaKey(1f, 0f), + new GradientAlphaKey(1f, 1f), + } + }; + GUI.changed = true; + } + } + + // + private void FilterListDrawHeader(Rect rect) + { + EditorGUI.LabelField(rect, labelFilterList); + } + + // + private void FilterListAdd(ReorderableList list) + { + ReorderableList.defaultBehaviours.DoAddButton(list); + } + + // + private void FilterListRemove(ReorderableList list) + { + ReorderableList.defaultBehaviours.DoRemoveButton(list); + } + + // + private void FilterListDrawElement(Rect rect, int index, bool selected, bool focused) + { + rect.height -= 2f; + var propertyElement = propertyFilterList.GetArrayElementAtIndex(index); + EditorGUI.ObjectField(rect, propertyElement); + //EditorGUIUtility.ShowObjectPicker; + } + } +} + diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs.meta b/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs.meta new file mode 100644 index 00000000..b6909e62 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlighterEditor.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: eaf65e4acd958f242864d8748239d7c0 +timeCreated: 1516708826 +licenseType: Store +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs b/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs new file mode 100644 index 00000000..f39368ab --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using UnityEditor; + +namespace HighlightingSystem +{ + [CustomEditor(typeof(HighlightingBlitter), true)] + public class HighlightingBlitterEditor : Editor + { + // + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Use order of this component (relatively to other Image Effects on this camera) to control the point at which highlighting will be applied to the framebuffer (click on a little gear icon to the right and choose Move Up / Move Down).", MessageType.Info); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs.meta b/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs.meta new file mode 100644 index 00000000..5daac305 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingBlitterEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f2c076edfe3724942afcb2b87d77e050 +timeCreated: 1454882223 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs b/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs new file mode 100644 index 00000000..c228d974 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs @@ -0,0 +1,79 @@ +using UnityEditor; +using UnityEngine; + +namespace HighlightingSystem +{ + [CustomPropertyDrawer(typeof(HighlightingPreset), true)] + public class HighlightingPresetEditor : PropertyDrawer + { + #region Static Fields and Constants + static public readonly GUIContent labelFillAlpha = new GUIContent("Fill Alpha", "Inner fill alpha value."); + static public readonly GUIContent labelDownsampling = new GUIContent("Downsampling:", "Downsampling factor."); + static public readonly GUIContent labelIterations = new GUIContent("Iterations:", "Blur iterations. Number of blur iterations performed. Larger number means more blur."); + static public readonly GUIContent labelBlurMinSpread = new GUIContent("Min Spread:", "Blur Min Spread. Lower values give better looking blur, but require more iterations to get large blurs. Pixel offset for each blur iteration is calculated as 'Min Spread + Spread * Iteration Index'. Usually 'Min Spread + Spread' value is between 0.5 and 1.0."); + static public readonly GUIContent labelBlurSpread = new GUIContent("Spread:", "Blur Spread. Lower values give better looking blur, but require more iterations to get large blurs. Pixel offset for each blur iteration is calculated as 'Min Spread + Spread * Iteration Index'. Usually 'Min Spread + Spread' value is between 0.5 and 1.0."); + static public readonly GUIContent labelBlurIntensity = new GUIContent("Intensity:", "Highlighting Intensity. Internally defines the value by which highlighting buffer alpha channel will be multiplied after each blur iteration."); + static public readonly GUIContent labelBlurDirections = new GUIContent("Blur Directions:", "Blur directions."); + + static public readonly GUIContent[] downsampleOptions = new GUIContent[] { new GUIContent("None"), new GUIContent("Half"), new GUIContent("Quarter") }; + static public readonly int[] downsampleGet = new int[] { -1, 0, 1, -1, 2 }; // maps downsampleFactor to the downsampleOptions index + static public readonly int[] downsampleSet = new int[] { 1, 2, 4 }; // maps downsampleOptions index to the downsampleFactor + static public readonly GUIContent[] blurDirections = new GUIContent[] { new GUIContent("Diagonal"), new GUIContent("Straight"), new GUIContent("All") }; + + private const float rowSpace = 2f; + #endregion + + #region Private Fields + private Rect[] rects = new Rect[8]; + #endregion + + #region PropertyDrawer + // + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + int l = rects.Length; + return 16f * l + rowSpace * (l - 1); + } + + // + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + // Draw label + position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); + + int indent = EditorGUI.indentLevel; + EditorGUI.indentLevel = 0; + + // Calculate rects + HighlightingRendererEditor.GetRowRects(position, rowSpace, rects); + + // Find properties + SerializedProperty propertyName = property.FindPropertyRelative("_name"); + SerializedProperty propertyFillAlpha = property.FindPropertyRelative("_fillAlpha"); + SerializedProperty propertyDownsampleFactor = property.FindPropertyRelative("_downsampleFactor"); + SerializedProperty propertyIterations = property.FindPropertyRelative("_iterations"); + SerializedProperty propertyBlurMinSpread = property.FindPropertyRelative("_blurMinSpread"); + SerializedProperty propertyBlurSpread = property.FindPropertyRelative("_blurSpread"); + SerializedProperty propertyBlurIntensty = property.FindPropertyRelative("_blurIntensity"); + SerializedProperty propertyBlurDirections = property.FindPropertyRelative("_blurDirections"); + + // Draw properties + int index = 0; + propertyName.stringValue = EditorGUI.TextField(rects[index], propertyName.stringValue); index++; + propertyFillAlpha.floatValue = EditorGUI.Slider(rects[index], labelFillAlpha, propertyFillAlpha.floatValue, 0f, 1f); index++; + propertyDownsampleFactor.intValue = downsampleSet[EditorGUI.Popup(rects[index], labelDownsampling, downsampleGet[propertyDownsampleFactor.intValue], downsampleOptions)]; index++; + propertyIterations.intValue = Mathf.Clamp(EditorGUI.IntField(rects[index], labelIterations, propertyIterations.intValue), 0, 50); index++; + propertyBlurMinSpread.floatValue = EditorGUI.Slider(rects[index], labelBlurMinSpread, propertyBlurMinSpread.floatValue, 0f, 3f); index++; + propertyBlurSpread.floatValue = EditorGUI.Slider(rects[index], labelBlurSpread, propertyBlurSpread.floatValue, 0f, 3f); index++; + propertyBlurIntensty.floatValue = EditorGUI.Slider(rects[index], labelBlurIntensity, propertyBlurIntensty.floatValue, 0f, 1f); index++; + propertyBlurDirections.enumValueIndex = (int)EditorGUI.Popup(rects[index], labelBlurDirections, propertyBlurDirections.enumValueIndex, blurDirections); index++; + + EditorGUI.indentLevel = indent; + + EditorGUI.EndProperty(); + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs.meta b/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs.meta new file mode 100644 index 00000000..17024d3b --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingPresetEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f38067eff9f5f884cbbc58b840c98311 +timeCreated: 1480274718 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs b/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs new file mode 100644 index 00000000..8e143e11 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs @@ -0,0 +1,369 @@ +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Reflection; + +namespace HighlightingSystem +{ + [CustomEditor(typeof(HighlightingRenderer), true)] + public class HighlightingRendererEditor : Editor + { + #region Static Fields and Constants + static protected readonly GUIContent labelButtonRemove = new GUIContent("Remove Preset"); + static protected readonly GUIContent labelAntiAliasing = new GUIContent("Anti Aliasing"); + static protected readonly GUIContent[] antiAliasingOptions = new GUIContent[] { new GUIContent("Use Value From Quality Settings"), new GUIContent("Disabled"), new GUIContent("2x Multi Sampling"), new GUIContent("4x Multi Sampling"), new GUIContent("8x Multi Sampling") }; + #endregion + + #region Protected Fields + protected HighlightingRenderer hr; + protected SavePresetWindow window; + protected MethodInfo boldFontMethodInfo; + protected Rect[] buttonRects = new Rect[2]; + protected GUIContent[] presetNames; + #endregion + + #region Editor + // + protected virtual void OnEnable() + { + hr = target as HighlightingRenderer; + } + + // + public override void OnInspectorGUI() + { + #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY + if (!PlayerSettings.use32BitDisplayBuffer) + { + EditorGUILayout.HelpBox("Highlighting System requires 32-bit display buffer. Set the 'Use 32-bit Display Buffer' checkbox under the 'Resolution and Presentation' section of Player Settings.", MessageType.Error); + } + #endif + + EditorGUILayout.Space(); + + // HighlightingBlitter field + if (hr.blitter == null) + { + EditorGUILayout.HelpBox("Use order of this component (relatively to other Image Effects on this camera) to control the point at which highlighting will be applied to the framebuffer (click on a little gear icon to the right and choose Move Up / Move Down) or assign HighlightingBlitter component from another camera.", MessageType.Info); + } + else if (hr.GetComponent() == hr.blitter.GetComponent()) + { + EditorGUILayout.HelpBox("Assigned HighlightingBlitter component exists on the same camera. This is not really necessary in most situations and affects rendering performance! Please make sure this is intended.", MessageType.Warning); + } + hr.blitter = EditorGUILayout.ObjectField("Blitter (Optional)", hr.blitter, typeof(HighlightingBlitter), true) as HighlightingBlitter; + + hr.antiAliasing = (AntiAliasing)EditorGUILayout.Popup(labelAntiAliasing, (int)hr.antiAliasing, antiAliasingOptions); + + InitializePresetNames(); + int presetIndex = IdentifyCurrentPreset(); + + EditorGUILayout.Space(); + + // Preset fields start + EditorGUILayout.LabelField("Preset:", EditorStyles.boldLabel); + + // Preset selection popup + int oldIndex = presetIndex; + int newIndex = EditorGUILayout.Popup(oldIndex, presetNames); + if (oldIndex != newIndex) + { + hr.LoadPreset(presetNames[newIndex].text); + presetIndex = newIndex; + } + + HighlightingPreset currentPreset = new HighlightingPreset(); + if (presetIndex >= 0) + { + hr.GetPreset(presetNames[presetIndex].text, out currentPreset); + } + + EditorGUI.BeginChangeCheck(); + + // Fill Alpha + SetBoldDefaultFont(presetIndex < 0 || hr.fillAlpha != currentPreset.fillAlpha); + hr.fillAlpha = EditorGUILayout.Slider(HighlightingPresetEditor.labelFillAlpha, hr.fillAlpha, 0f, 1f); + + // Downsample factor + SetBoldDefaultFont(presetIndex < 0 || hr.downsampleFactor != currentPreset.downsampleFactor); + hr.downsampleFactor = HighlightingPresetEditor.downsampleSet[EditorGUILayout.Popup(HighlightingPresetEditor.labelDownsampling, HighlightingPresetEditor.downsampleGet[hr.downsampleFactor], HighlightingPresetEditor.downsampleOptions)]; + + // Iterations + SetBoldDefaultFont(presetIndex < 0 || hr.iterations != currentPreset.iterations); + hr.iterations = Mathf.Clamp(EditorGUILayout.IntField(HighlightingPresetEditor.labelIterations, hr.iterations), 0, 50); + + // Blur min spread + SetBoldDefaultFont(presetIndex < 0 || hr.blurMinSpread != currentPreset.blurMinSpread); + hr.blurMinSpread = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurMinSpread, hr.blurMinSpread, 0f, 3f); + + // Blur spread + SetBoldDefaultFont(presetIndex < 0 || hr.blurSpread != currentPreset.blurSpread); + hr.blurSpread = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurSpread, hr.blurSpread, 0f, 3f); + + // Blur intensity + SetBoldDefaultFont(presetIndex < 0 || hr.blurIntensity != currentPreset.blurIntensity); + hr.blurIntensity = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurIntensity, hr.blurIntensity, 0f, 1f); + + // Blur straight directions + SetBoldDefaultFont(presetIndex < 0 || hr.blurDirections != currentPreset.blurDirections); + hr.blurDirections = (BlurDirections)EditorGUILayout.Popup(HighlightingPresetEditor.labelBlurDirections, (int)hr.blurDirections, HighlightingPresetEditor.blurDirections); + + SetBoldDefaultFont(false); + + if (EditorGUI.EndChangeCheck()) + { + EditorUtility.SetDirty(hr); + } + + // Define button rects + Rect position = GUILayoutUtility.GetRect(0f, 16f, GUILayout.ExpandWidth(true)); + HighlightingRendererEditor.GetColumnRects(position, 2f, buttonRects); + + // Save preset button + + using (new EditorGUI.DisabledScope(Application.isPlaying || + (hr.downsampleFactor == currentPreset.downsampleFactor && + hr.iterations == currentPreset.iterations && + hr.blurMinSpread == currentPreset.blurMinSpread && + hr.blurSpread == currentPreset.blurSpread && + hr.blurIntensity == currentPreset.blurIntensity && + hr.blurDirections == currentPreset.blurDirections))) + { + if (GUI.Button(buttonRects[0], "Save Preset")) + { + window = SavePresetWindow.Init(presetIndex < 0 ? "My Preset" : presetNames[presetIndex].text, SavePresetAs); + } + } + + // Remove preset button + using (new EditorGUI.DisabledScope(Application.isPlaying || presetIndex < 0)) + { + if (GUI.Button(buttonRects[1], labelButtonRemove) && presetIndex >= 0) + { + string presetName = presetNames[presetIndex].text; + if (EditorUtility.DisplayDialog("Removing Preset", "Are you sure you want to remove Preset '" + presetName + "'?", "Yes", "No")) + { + hr.RemovePreset(presetName); + EditorUtility.SetDirty(hr); + ReadOnlyCollection presets = hr.presets; + if (presets.Count > 0) + { + presetIndex = 0; + hr.ApplyPreset(presets[presetIndex]); + } + InitializePresetNames(); + } + } + } + + EditorGUILayout.Space(); + } + #endregion + + #region Protected Methods + // + protected virtual void InitializePresetNames() + { + ReadOnlyCollection presets = hr.presets; + int presetCount = presets.Count; + if (presetNames == null || presetNames.Length != presetCount) + { + presetNames = new GUIContent[presetCount]; + } + + for (int i = 0; i < presetCount; i++) + { + HighlightingPreset preset = presets[i]; + GUIContent presetName = presetNames[i]; + if (presetName == null) + { + presetName = new GUIContent(); + presetNames[i] = presetName; + } + presetName.text = preset.name; + } + } + + // Returns current preset index + protected virtual int IdentifyCurrentPreset() + { + ReadOnlyCollection presets = hr.presets; + for (int i = presets.Count - 1; i >= 0; i--) + { + HighlightingPreset p = presets[i]; + if (hr.downsampleFactor == p.downsampleFactor && + hr.iterations == p.iterations && + hr.blurMinSpread == p.blurMinSpread && + hr.blurSpread == p.blurSpread && + hr.blurIntensity == p.blurIntensity && + hr.blurDirections == p.blurDirections) + { + return i; + } + } + return -1; + } + + // + protected virtual bool SavePresetAs(string name) + { + name = name.Trim(); + + window = null; + + if (string.IsNullOrEmpty(name)) + { + EditorUtility.DisplayDialog("Unable to save Preset", "Please specify valid Preset name.", "Close"); + return false; + } + + // Preset with this name exists? + HighlightingPreset preset; + if (hr.GetPreset(name, out preset)) + { + // Overwrite? + if (!EditorUtility.DisplayDialog("Overwriting Preset", "Preset '" + name + "' already exists. Overwrite?", "Yes", "No")) + { + return false; + } + } + + // Add or overwrite preset + preset.name = name; + preset.downsampleFactor = hr.downsampleFactor; + preset.iterations = hr.iterations; + preset.blurMinSpread = hr.blurMinSpread; + preset.blurSpread = hr.blurSpread; + preset.blurIntensity = hr.blurIntensity; + preset.blurDirections = hr.blurDirections; + + hr.AddPreset(preset, true); + EditorUtility.SetDirty(hr); + InitializePresetNames(); + IdentifyCurrentPreset(); + + return true; + } + + // + protected void SetBoldDefaultFont(bool value) + { + if (boldFontMethodInfo == null) + { + boldFontMethodInfo = typeof(EditorGUIUtility).GetMethod("SetBoldDefaultFont", BindingFlags.Static | BindingFlags.NonPublic); + } + boldFontMethodInfo.Invoke(null, new[] { value as object }); + } + #endregion + + #region Helpers + // + static public void GetRowRects(Rect rect, float space, Rect[] rects) + { + int l = rects.Length; + for (int i = 0; i < l; i++) + { + float h = (rect.height - space * (l - 1)) / l; + if (h < 0f) { h = 0f; } + + Rect r = rects[i]; + + r.x = rect.x; + r.y = rect.y + i * (h + space); + r.width = rect.width; + r.height = h; + + rects[i] = r; + } + } + + // + static public void GetColumnRects(Rect rect, float space, Rect[] rects) + { + int l = rects.Length; + for (int i = 0; i < l; i++) + { + float w = (rect.width - space * (l - 1)) / l; + if (w < 0f) { w = 0f; } + + Rect r = rects[i]; + + r.x = rect.x + i * (w + space); + r.y = rect.y; + r.width = w; + r.height = rect.height; + + rects[i] = r; + } + } + #endregion + + #region Documentation + [MenuItem("Tools/Highlighting System/Documentation", priority = 0)] + static private void OnlineDocumentation() + { + Application.OpenURL("http://docs.deepdream.games/HighlightingSystem/5.0/"); + } + #endregion + } + + #region SavePresetWindow + public class SavePresetWindow : EditorWindow + { + static private readonly string presetTextFieldName = "PresetTextFieldName"; + public delegate bool InputResult(string input); + private event InputResult callback; + private string presetName; + + // + public static SavePresetWindow Init(string name, InputResult callback) + { + Rect rect = new Rect(Screen.width * 0.5f, Screen.height * 0.5f, 300f, 60f); + SavePresetWindow window = GetWindowWithRect(rect, true, "Specify Preset Name", true); + window.callback = callback; + window.presetName = name; + return window; + } + + // + void OnGUI() + { + GUI.SetNextControlName(presetTextFieldName); + presetName = EditorGUILayout.TextField("Preset Name", presetName); + + EditorGUI.FocusTextInControl(presetTextFieldName); + + bool pressed = GUILayout.Button("Save Preset", GUILayout.ExpandHeight(true)); + Event e = Event.current; + bool submitted = e.type == EventType.KeyUp && GUI.GetNameOfFocusedControl() == presetTextFieldName && (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter); + + if (pressed || submitted) + { + OnSavePreset(); + GUIUtility.ExitGUI(); + } + } + + // + void OnLostFocus() { Quit(); } + void OnSelectionChange() { Quit(); } + void OnProjectChange() { Quit(); } + + // + private void OnSavePreset() + { + if (callback(presetName)) + { + Close(); + } + } + + // + private void Quit() + { + Close(); + } + } + #endregion +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs.meta b/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs.meta new file mode 100644 index 00000000..6f385571 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Editor/HighlightingRendererEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 183043fd0398e0148aefaae999f3c9f3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources.meta b/Assets/Plugins/HighlightingSystem/Resources.meta new file mode 100644 index 00000000..5740ab1d --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 2e2dd921d0779af4dad3fbd326388e14 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader b/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader new file mode 100644 index 00000000..db8199c2 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader @@ -0,0 +1,172 @@ +Shader "Hidden/Highlighted/Blur" +{ + Properties + { + [HideInInspector] _MainTex ("", 2D) = "" {} + [HideInInspector] _HighlightingIntensity ("", Range (0.25,0.5)) = 0.3 + } + + SubShader + { + Pass + { + ZTest Always + Cull Off + ZWrite Off + Lighting Off + Fog { Mode Off } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + #pragma multi_compile DIAGONAL_DIRECTIONS STRAIGHT_DIRECTIONS ALL_DIRECTIONS + + #include "UnityCG.cginc" + + uniform sampler2D _MainTex; + uniform float4 _MainTex_ST; + uniform float4 _MainTex_TexelSize; + + uniform float _HighlightingBlurOffset; + uniform half _HighlightingIntensity; + + struct vs_input + { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + }; + + struct ps_input + { + float4 pos : SV_POSITION; + + #if defined(ALL_DIRECTIONS) + float4 uv0 : TEXCOORD0; + float4 uv1 : TEXCOORD1; + float4 uv2 : TEXCOORD2; + float4 uv3 : TEXCOORD3; + #else + float4 uv0 : TEXCOORD0; + float4 uv1 : TEXCOORD1; + #endif + }; + + ps_input vert(vs_input v) + { + ps_input o; + o.pos = UnityObjectToClipPos(v.vertex); + + float2 uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST); + float2 offs = _HighlightingBlurOffset * _MainTex_TexelSize.xy; + + #if defined(ALL_DIRECTIONS) + + // Diagonal + o.uv0.x = uv.x - offs.x; + o.uv0.y = uv.y - offs.y; + + o.uv0.z = uv.x + offs.x; + o.uv0.w = uv.y - offs.y; + + o.uv1.x = uv.x + offs.x; + o.uv1.y = uv.y + offs.y; + + o.uv1.z = uv.x - offs.x; + o.uv1.w = uv.y + offs.y; + + // Straight + o.uv2.x = uv.x - offs.x; + o.uv2.y = uv.y; + + o.uv2.z = uv.x + offs.x; + o.uv2.w = uv.y; + + o.uv3.x = uv.x; + o.uv3.y = uv.y - offs.y; + + o.uv3.z = uv.x; + o.uv3.w = uv.y + offs.y; + + #elif defined(STRAIGHT_DIRECTIONS) + + // Straight + o.uv0.x = uv.x - offs.x; + o.uv0.y = uv.y; + + o.uv0.z = uv.x + offs.x; + o.uv0.w = uv.y; + + o.uv1.x = uv.x; + o.uv1.y = uv.y - offs.y; + + o.uv1.z = uv.x; + o.uv1.w = uv.y + offs.y; + + #else + + // Diagonal + o.uv0.x = uv.x - offs.x; + o.uv0.y = uv.y - offs.y; + + o.uv0.z = uv.x + offs.x; + o.uv0.w = uv.y - offs.y; + + o.uv1.x = uv.x + offs.x; + o.uv1.y = uv.y + offs.y; + + o.uv1.z = uv.x - offs.x; + o.uv1.w = uv.y + offs.y; + + #endif + + return o; + } + + half4 frag(ps_input i) : SV_Target + { + half4 color1 = tex2D(_MainTex, i.uv0.xy); + fixed4 color2; + + // For straight or diagonal directions + color2 = tex2D(_MainTex, i.uv0.zw); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + color2 = tex2D(_MainTex, i.uv1.xy); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + color2 = tex2D(_MainTex, i.uv1.zw); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + // For all directions + #if defined(ALL_DIRECTIONS) + color2 = tex2D(_MainTex, i.uv2.xy); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + color2 = tex2D(_MainTex, i.uv2.zw); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + color2 = tex2D(_MainTex, i.uv3.xy); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + + color2 = tex2D(_MainTex, i.uv3.zw); + color1.rgb = max(color1.rgb, color2.rgb); + color1.a += color2.a; + #endif + + color1.a *= _HighlightingIntensity; + return color1; + } + ENDCG + } + } + + Fallback off +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader.meta b/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader.meta new file mode 100644 index 00000000..9bf4d0c6 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingBlur.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 3070218404d1de94c9d081d248597046 +ShaderImporter: + defaultTextures: [] + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader b/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader new file mode 100644 index 00000000..ff5fb406 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader @@ -0,0 +1,72 @@ +Shader "Hidden/Highlighted/Composite" +{ + Properties + { + [HideInInspector] _MainTex ("", 2D) = "" {} + [HideInInspector] _HighlightingBuffer ("", 2D) = "" {} + } + + SubShader + { + Pass + { + Lighting Off + Fog { Mode off } + ZWrite Off + ZTest Always + Cull Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + #include "UnityCG.cginc" + + struct vs_input + { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + }; + + struct ps_input + { + float4 pos : SV_POSITION; + half2 uv0 : TEXCOORD0; + half2 uv1 : TEXCOORD1; + }; + + uniform sampler2D _MainTex; + uniform float4 _MainTex_ST; + uniform float4 _MainTex_TexelSize; + uniform sampler2D _HighlightingBuffer; + + ps_input vert(vs_input v) + { + ps_input o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv0 = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST); + o.uv1 = o.uv0; + + #if UNITY_UV_STARTS_AT_TOP + if (_MainTex_TexelSize.y < 0) + { + o.uv1.y = 1-o.uv1.y; + } + #endif + + return o; + } + + fixed4 frag(ps_input i) : SV_Target + { + fixed4 c1 = tex2D(_MainTex, i.uv0); + fixed4 c2 = tex2D(_HighlightingBuffer, i.uv1); + c1.rgb = lerp(c1.rgb, c2.rgb, c2.a); + return c1; + } + ENDCG + } + } + FallBack Off +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader.meta b/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader.meta new file mode 100644 index 00000000..37eaf480 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingComposite.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: b0bd9de6a4f20954f9704e56568224a6 +ShaderImporter: + defaultTextures: [] + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader b/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader new file mode 100644 index 00000000..1bb22144 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader @@ -0,0 +1,111 @@ +Shader "Hidden/Highlighted/Cut" +{ + Properties + { + [HideInInspector] _MainTex ("", 2D) = "" {} + [HideInInspector] _HighlightingFillAlpha ("", Range(0.0, 1.0)) = 1.0 + } + + SubShader + { + Lighting Off + Fog { Mode off } + ZWrite Off + ZTest Always + Cull Back + + Pass + { + Stencil + { + Ref 1 + Comp NotEqual + Pass Keep + ZFail Keep + } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + + #include "UnityCG.cginc" + + struct vs_input + { + float4 vertex : POSITION; + half2 texcoord : TEXCOORD0; + }; + + struct ps_input + { + float4 pos : SV_POSITION; + half2 uv : TEXCOORD0; + }; + + uniform sampler2D _MainTex; + uniform float4 _MainTex_ST; + + ps_input vert(vs_input v) + { + ps_input o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST); + return o; + } + + fixed4 frag(ps_input i) : SV_Target + { + return tex2D(_MainTex, i.uv); + } + ENDCG + } + + Pass + { + Stencil + { + Ref 1 + Comp Equal + Pass Keep + ZFail Keep + } + ColorMask A + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + + #include "UnityCG.cginc" + + struct vs_input + { + float4 vertex : POSITION; + }; + + struct ps_input + { + float4 pos : SV_POSITION; + }; + + uniform float _HighlightingFillAlpha; + + ps_input vert(vs_input v) + { + ps_input o; + o.pos = UnityObjectToClipPos(v.vertex); + return o; + } + + fixed4 frag() : SV_Target + { + return fixed4(0, 0, 0, _HighlightingFillAlpha); + } + ENDCG + } + } + FallBack Off +} diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader.meta b/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader.meta new file mode 100644 index 00000000..3d3e60a2 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingCut.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 376af14ed82e64793b326012b8591fa9 +ShaderImporter: + defaultTextures: [] + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader b/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader new file mode 100644 index 00000000..a01b0249 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader @@ -0,0 +1,88 @@ +Shader "Hidden/Highlighted/Opaque" +{ + Properties + { + [HideInInspector] _HighlightingColor ("", Color) = (1, 1, 1, 1) + } + + SubShader + { + Lighting Off + Fog { Mode Off } + ZWrite Off // Manual depth test + ZTest Always // Manual depth test + + Pass + { + Stencil + { + Ref 1 + Comp Always + Pass Replace + ZFail Keep + } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + #pragma multi_compile __ HIGHLIGHTING_OVERLAY + #include "UnityCG.cginc" + + uniform fixed4 _HighlightingColor; + + #ifndef HIGHLIGHTING_OVERLAY + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + #endif + + struct vs_input + { + float4 vertex : POSITION; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct ps_input + { + float4 pos : SV_POSITION; + + #ifndef HIGHLIGHTING_OVERLAY + float4 screen : TEXCOORD0; + #endif + }; + + ps_input vert(vs_input v) + { + ps_input o; + + UNITY_SETUP_INSTANCE_ID(v); + o.pos = UnityObjectToClipPos(v.vertex); + + #ifndef HIGHLIGHTING_OVERLAY + o.screen = ComputeScreenPos(o.pos); + COMPUTE_EYEDEPTH(o.screen.z); + #endif + + return o; + } + + fixed4 frag(ps_input i) : SV_Target + { + #ifndef HIGHLIGHTING_OVERLAY + float z = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screen)); + float perspZ = LinearEyeDepth(z); // LinearEyeDepth automatically handles UNITY_REVERSED_Z case + #if defined(UNITY_REVERSED_Z) + z = 1 - z; + #endif + float orthoZ = _ProjectionParams.y + z * (_ProjectionParams.z - _ProjectionParams.y); // near + z * (far - near) + float sceneZ = lerp(perspZ, orthoZ, unity_OrthoParams.w); + clip(sceneZ - i.screen.z + 0.01); + #endif + + return _HighlightingColor; + } + ENDCG + } + } + Fallback Off +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader.meta b/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader.meta new file mode 100644 index 00000000..30ebfb18 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingOpaque.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: ce3b12ca636563c48afb814d9aeb5b90 +ShaderImporter: + defaultTextures: [] + userData: diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader b/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader new file mode 100644 index 00000000..8abf675d --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader @@ -0,0 +1,108 @@ +Shader "Hidden/Highlighted/Transparent" +{ + Properties + { + [HideInInspector] _MainTex ("", 2D) = "" {} + [HideInInspector] _HighlightingColor ("", Color) = (1, 1, 1, 1) + [HideInInspector] _Cutoff ("", Float) = 0.5 + [HideInInspector] _HighlightingCull ("", Int) = 2 // UnityEngine.Rendering.CullMode.Back + } + + SubShader + { + Lighting Off + Fog { Mode Off } + ZWrite Off // Manual depth test + ZTest Always // Manual depth test + Cull [_HighlightingCull] // For rendering both sides of the Sprite + + Pass + { + Stencil + { + Ref 1 + Comp Always + Pass Replace + ZFail Keep + } + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma fragmentoption ARB_precision_hint_fastest + #pragma target 2.0 + #pragma multi_compile __ HIGHLIGHTING_OVERLAY + #include "UnityCG.cginc" + + uniform fixed4 _HighlightingColor; + uniform sampler2D _MainTex; + uniform float4 _MainTex_ST; + uniform fixed _Cutoff; + + #ifndef HIGHLIGHTING_OVERLAY + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + #endif + + struct vs_input + { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + fixed4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct ps_input + { + float4 pos : SV_POSITION; + float2 texcoord : TEXCOORD0; + fixed alpha : TEXCOORD1; + + #ifndef HIGHLIGHTING_OVERLAY + float4 screen : TEXCOORD2; + #endif + }; + + ps_input vert(vs_input v) + { + ps_input o; + + UNITY_SETUP_INSTANCE_ID(v); + o.pos = UnityObjectToClipPos(v.vertex); + + #ifndef HIGHLIGHTING_OVERLAY + o.screen = ComputeScreenPos(o.pos); + COMPUTE_EYEDEPTH(o.screen.z); + #endif + + o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); + o.alpha = v.color.a; + return o; + } + + fixed4 frag(ps_input i) : SV_Target + { + fixed a = tex2D(_MainTex, i.texcoord).a; + clip(a - _Cutoff); + + #ifndef HIGHLIGHTING_OVERLAY + float z = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screen)); + float perspZ = LinearEyeDepth(z); // LinearEyeDepth automatically handles UNITY_REVERSED_Z case + #if defined(UNITY_REVERSED_Z) + z = 1 - z; + #endif + float orthoZ = _ProjectionParams.y + z * (_ProjectionParams.z - _ProjectionParams.y); // near + z * (far - near) + float sceneZ = lerp(perspZ, orthoZ, unity_OrthoParams.w); + clip(sceneZ - i.screen.z + 0.01); + #endif + + fixed4 c = _HighlightingColor; + c.a *= i.alpha; + + return c; + } + ENDCG + } + } + + Fallback Off +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader.meta b/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader.meta new file mode 100644 index 00000000..9862945b --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Resources/HighlightingTransparent.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 9fc04a058c8768648a6532aa07540ca5 +ShaderImporter: + defaultTextures: [] + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts.meta b/Assets/Plugins/HighlightingSystem/Scripts.meta new file mode 100644 index 00000000..8d6e05d9 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 4b92650ecd71b67409ab3aafea97bd7d +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs b/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs new file mode 100644 index 00000000..114572c5 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs @@ -0,0 +1,899 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace HighlightingSystem +{ + public enum LoopMode + { + Once, + Loop, + PingPong, + ClampForever, + } + + public enum Easing + { + Linear, + + QuadIn, + QuadOut, + QuadInOut, + + CubicIn, + CubicOut, + CubicInOut, + + SineIn, + SineOut, + SineInOut, + } + + public enum RendererFilterMode + { + None, + Include, + Exclude, + } + + [AddComponentMenu("Highlighting System/Highlighter", 0)] + public class Highlighter : HighlighterCore + { + #region Constants + protected const float HALFPI = Mathf.PI * 0.5f; + #endregion + + #region Inspector Fields + /* General */ + + /// + /// When set to true - highlighting will be rendered on top of all other geometry. + /// + public bool overlay + { + get { return _overlay; } + set { _overlay = value; } + } + + /// + /// Controls occluder mode. + /// + public bool occluder + { + get { return _occluder; } + set { _occluder = value; } + } + + /* Tween */ + + public bool tween + { + get { return _tween; } + set { TweenSet(value); } + } + + public Gradient tweenGradient + { + get { return _tweenGradient; } + set { _tweenGradient = value; } + } + + public float tweenDuration + { + get { return _tweenDuration; } + set { _tweenDuration = value; ValidateRanges(); } + } + + public float tweenDelay + { + get { return _tweenDelay; } + set { _tweenDelay = value; } + } + + public bool tweenUseUnscaledTime + { + get { return _tweenUseUnscaledTime; } + set + { + if (_tweenUseUnscaledTime != value) + { + float delta = GetTweenTime() - _tweenStart; + _tweenUseUnscaledTime = value; + _tweenStart = GetTweenTime() - delta; + } + } + } + + public LoopMode tweenLoop + { + get { return _tweenLoop; } + set { _tweenLoop = value; } + } + + public Easing tweenEasing + { + get { return _tweenEasing; } + set { _tweenEasing = value; } + } + + public bool tweenReverse + { + get { return _tweenReverse; } + set { _tweenReverse = value; } + } + + public int tweenRepeatCount + { + get { return _tweenRepeatCount; } + set { _tweenRepeatCount = value; } + } + + /* Constant */ + + public bool constant + { + get { return _constant; } + set { ConstantSet(value); } + } + + public Color constantColor + { + get { return _constantColor; } + set { _constantColor = value; } + } + + public float constantFadeTime + { + set + { + _constantFadeInTime = value; + _constantFadeOutTime = value; + ValidateRanges(); + ConstantSet(); + } + } + + public float constantFadeInTime + { + get { return _constantFadeInTime; } + set + { + _constantFadeInTime = value; + ValidateRanges(); + if (_constant) { ConstantSet(); } + } + } + + public float constantFadeOutTime + { + get { return _constantFadeOutTime; } + set + { + _constantFadeOutTime = value; + ValidateRanges(); + if (!_constant) { ConstantSet(); } + } + } + + public bool constantUseUnscaledTime + { + get { return _constantUseUnscaledTime; } + set + { + if (_constantUseUnscaledTime != value) + { + float delta = GetConstantTime() - _constantStart; + _constantUseUnscaledTime = value; + _constantStart = GetConstantTime() - delta; + } + } + } + + public Easing constantEasing + { + get { return _constantEasing; } + set { _constantEasing = value; } + } + + public RendererFilterMode filterMode + { + get { return _filterMode; } + set + { + if (_filterMode != value) + { + _filterMode = value; + // Update highlighted Renderers + SetDirty(); + } + } + } + + /// + /// Make sure to trigger SetDirty() after modifying this list + /// + public List filterList + { + get { return _filterList; } + } + + protected override RendererFilter rendererFilterToUse + { + get + { + if (rendererFilter != null) + { + return rendererFilter; + } + else if (_filterMode == RendererFilterMode.None) + { + return globalRendererFilter != null ? globalRendererFilter : DefaultRendererFilter; + } + else if (_filterMode == RendererFilterMode.Include) + { + return TransformFilterInclude; + } + else if (_filterMode == RendererFilterMode.Exclude) + { + return TransformFilterExclude; + } + + // Should never happen + return DefaultRendererFilter; + } + } + #endregion + + #region Protected Fields + // General + [SerializeField] protected bool _overlay; + [SerializeField] protected bool _occluder; + + // Hover (do not serialize this!) + protected Color _hoverColor = Color.red; + protected int _hoverFrame = -1; + + // Tween + [SerializeField] protected bool _tween = false; + [SerializeField] protected Gradient _tweenGradient = new Gradient() + { + colorKeys = new GradientColorKey[] + { + new GradientColorKey(new Color(0f, 1f, 1f, 1f), 0f), + new GradientColorKey(new Color(0f, 1f, 1f, 1f), 1f), + }, + alphaKeys = new GradientAlphaKey[] + { + new GradientAlphaKey(0f, 0f), + new GradientAlphaKey(1f, 1f), + } + }; + [SerializeField] protected float _tweenDuration = 1f; + [SerializeField] protected bool _tweenReverse = false; + [SerializeField] protected LoopMode _tweenLoop = LoopMode.PingPong; + [SerializeField] protected Easing _tweenEasing = Easing.Linear; + [SerializeField] protected float _tweenDelay = 0f; + [SerializeField] protected int _tweenRepeatCount = -1; + [SerializeField] protected bool _tweenUseUnscaledTime = false; + + // Constant highlighting mode (with optional fade in/out transition) + [SerializeField] protected bool _constant = false; + [SerializeField] protected Color _constantColor = Color.yellow; + [SerializeField] protected float _constantFadeInTime = 0.1f; + [SerializeField] protected float _constantFadeOutTime = 0.25f; + [SerializeField] protected Easing _constantEasing = Easing.Linear; + [SerializeField] protected bool _constantUseUnscaledTime = false; + + [SerializeField] protected RendererFilterMode _filterMode = RendererFilterMode.None; + [SerializeField] protected List _filterList = new List(); + + // Runtime only (do not serialize this!) + protected bool _tweenEnabled; + protected float _tweenStart; // Time when the tween has started + protected bool _constantEnabled; + protected float _constantStart; + protected float _constantDuration; + #endregion + + #region Protected Accessors + protected bool hover + { + get { return _hoverFrame == Time.frameCount; } + set { _hoverFrame = value ? Time.frameCount : -1; } + } + + // constantValue is always increasing from 0 to 1 (for both fade in and out transitions) + protected float constantValue + { + get { return _constantDuration > 0f ? Mathf.Clamp01((GetConstantTime() - _constantStart) / _constantDuration) : 1f; } + } + #endregion + + #region MonoBehaviour + // + protected virtual void OnDidApplyAnimationProperties() + { + ValidateAll(); + } + + #if UNITY_EDITOR + // + void OnValidate() + { + ValidateAll(); + } + + // + void Reset() + { + ValidateAll(); + } + #endif + #endregion + + #region MonoBehaviour Overrides + // + protected override void OnEnableSafe() + { + ValidateAll(); + } + + // + protected override void OnDisableSafe() + { + // Make sure transition won't continue if component will be re-enabled + _tweenEnabled = false; + _constantEnabled = false; + _constantStart = GetConstantTime() - _constantDuration; + } + #endregion + + #region Validation + // + protected void ValidateAll() + { + ValidateRanges(); + TweenSet(); + ConstantSet(); + SetDirty(); + } + + // + protected void ValidateRanges() + { + if (_tweenDuration < 0f) { _tweenDuration = 0f; } + if (_constantFadeInTime < 0f) { _constantFadeInTime = 0f; } + if (_constantFadeOutTime < 0f) { _constantFadeInTime = 0f; } + } + #endregion + + #region Public Methods + /// + /// 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 Hover(Color color) + { + _hoverColor = color; + hover = true; + } + + /// + /// Fade in constant highlighting using specified transition duration. + /// + /// + /// Transition time. + /// + public void ConstantOn(float fadeTime = 0.25f) + { + ConstantSet(fadeTime, true); + } + + /// + /// Fade in constant highlighting using specified color and transition duration. + /// + /// + /// Constant highlighting color. + /// + /// + /// Transition duration. + /// + public void ConstantOn(Color color, float fadeTime = 0.25f) + { + _constantColor = color; + ConstantSet(fadeTime, true); + } + + /// + /// Fade out constant highlighting using specified transition duration. + /// + /// + /// Transition time. + /// + public void ConstantOff(float fadeTime = 0.25f) + { + ConstantSet(fadeTime, false); + } + + /// + /// Switch constant highlighting using specified transition duration. + /// + /// + /// Transition time. + /// + public void ConstantSwitch(float fadeTime = 0.25f) + { + ConstantSet(fadeTime, !_constant); + } + + /// + /// Turn on constant highlighting immediately (without fading in). + /// + public void ConstantOnImmediate() + { + ConstantSet(0f, true); + } + + /// + /// Turn on constant highlighting using specified color immediately (without fading in). + /// + /// + /// Constant highlighting color. + /// + public void ConstantOnImmediate(Color color) + { + _constantColor = color; + ConstantSet(0f, true); + } + + /// + /// Turn off constant highlighting immediately (without fading out). + /// + public void ConstantOffImmediate() + { + ConstantSet(0f, false); + } + + /// + /// Switch constant highlighting immediately (without fading in/out). + /// + public void ConstantSwitchImmediate() + { + ConstantSet(0f, !_constant); + } + + /// + /// Turn off all types of highlighting (occlusion mode remains intact). + /// + public void Off() + { + hover = false; + TweenSet(false); + ConstantSet(0f, false); + } + + // + public void TweenStart() + { + TweenSet(true); + } + + // + public void TweenStop() + { + TweenSet(false); + } + + // Updates tween state. (!) Sets _tween value. + public void TweenSet(bool value) + { + _tween = value; + if (_tweenEnabled != _tween) + { + _tweenEnabled = _tween; + _tweenStart = GetTweenTime(); + } + } + + // Updates constant state. (!) Sets _constant value. + public void ConstantSet(float fadeTime, bool value) + { + // Order matters. Should always set _constantDuration prior to _constantEnabled + + // Transition duration + if (fadeTime < 0f) { fadeTime = 0f; } + if (_constantDuration != fadeTime) + { + float timeNow = GetConstantTime(); + // Recalculate start time if duration changed + _constantStart = _constantDuration > 0f ? timeNow - (fadeTime / _constantDuration) * (timeNow - _constantStart) : timeNow - fadeTime; + _constantDuration = fadeTime; + } + + // Transition target + _constant = value; + if (_constantEnabled != _constant) + { + _constantEnabled = _constant; + // Recalculate start time if value changed + _constantStart = GetConstantTime() - _constantDuration * (1f - constantValue); + } + } + #endregion + + #region Protected Methods + // Helper + protected void TweenSet() + { + TweenSet(_tween); + } + + // Helper + protected void ConstantSet() + { + ConstantSet(_constant); + } + + // Helper + protected void ConstantSet(bool value) + { + ConstantSet(value ? constantFadeInTime : _constantFadeOutTime, value); + } + + // Updates highlighting color + protected override void UpdateHighlighting() + { + // Hover + if (hover) + { + color = _hoverColor; + mode = _overlay ? HighlighterMode.Overlay : HighlighterMode.Default; + return; + } + + // Tween + if (_tweenEnabled) + { + float delta = GetTweenTime() - (_tweenStart + _tweenDelay); + if (delta >= 0f) + { + float t = _tweenDuration > 0f ? delta / _tweenDuration : 0f; + t = Loop(t, _tweenLoop, _tweenReverse, _tweenRepeatCount); + if (t >= 0f) + { + t = Ease(t, _tweenEasing); + color = _tweenGradient.Evaluate(t); + mode = _overlay ? HighlighterMode.Overlay : HighlighterMode.Default; + return; + } + } + } + + // Constant + float c = _constantEnabled ? constantValue : 1f - constantValue; + if (c > 0f) + { + c = Ease(c, _constantEasing); + color = _constantColor; + color.a *= c; + mode = _overlay ? HighlighterMode.Overlay : HighlighterMode.Default; + return; + } + + // Occluder + if (_occluder) + { + mode = HighlighterMode.Occluder; + return; + } + + // Disabled + mode = HighlighterMode.Disabled; + } + #endregion + + #region Protected Methods + // + protected bool TransformFilterInclude(Renderer renderer, List submeshIndices) + { + Transform child = renderer.transform; + + for (int i = 0; i < _filterList.Count; i++) + { + Transform parent = _filterList[i]; + if (parent == null) { continue; } + + // Highlight if child of inclusion list transform + if (child.IsChildOf(parent)) + { + // Highlight all submeshes + submeshIndices.Add(-1); + return true; + } + } + + return false; + } + + // + protected bool TransformFilterExclude(Renderer renderer, List submeshIndices) + { + Transform child = renderer.transform; + + for (int i = 0; i < _filterList.Count; i++) + { + Transform parent = _filterList[i]; + if (parent == null) { continue; } + + // Do not highlight if child of exclusion list transform + if (child.IsChildOf(parent)) { return false; } + } + + // Highlight all submeshes + submeshIndices.Add(-1); + + return true; + } + + // + protected float Loop(float x, LoopMode loop, bool reverse = false, int repeatCount = -1) + { + float y = -1f; + + switch (loop) + { + default: + case LoopMode.Once: + if (x >= 0f && x <= 1f) { y = x; } + break; + case LoopMode.Loop: + int n1 = Mathf.FloorToInt(x); + if (repeatCount < 0 || n1 < repeatCount) + { + y = x - n1; + } + break; + case LoopMode.PingPong: + // Performs 0-1-0 transition in tweenDuration time + //int n2 = Mathf.FloorToInt(x); + //if (repeatCount < 0 || n2 < repeatCount) + //{ + // y = 1f - Mathf.Abs((x - n2) * 2f - 1f); + //} + + // Performs 0-1-0 transition in 2 * tweenDuration time, + // so the 0-1 transition is performed with the same speed as in Loop mode. + int n2 = Mathf.FloorToInt(x * 0.5f); + if (repeatCount < 0 || n2 < repeatCount) + { + y = 1f - Mathf.Abs(x - n2 * 2f - 1f); + } + break; + case LoopMode.ClampForever: + y = Mathf.Clamp01(x); + break; + } + + // Reverse. Check y for positive value since there is no loop if it's negative. + if (y >= 0f && reverse) { y = 1f - y; } + + return y; + } + + // + protected float Ease(float x, Easing easing) + { + x = Mathf.Clamp01(x); + float y; + switch (easing) + { + // Linear + default: + case Easing.Linear: + y = x; + break; + + // Quad + case Easing.QuadIn: + y = x * x; + break; + case Easing.QuadOut: + y = -x * (x - 2f); + break; + case Easing.QuadInOut: + y = x < 0.5f ? 2f * x * x : 2f * x * (2f - x) - 1f; + break; + + // Cubic + case Easing.CubicIn: + y = x * x * x; + break; + case Easing.CubicOut: + x = x - 1f; + y = x * x * x + 1f; + break; + case Easing.CubicInOut: + if (x < 0.5f) + { + y = 4f * x * x * x; + } + else + { + x = 2f * x - 2f; + y = 0.5f * (x * x * x + 2f); + } + break; + + // Sine + case Easing.SineIn: + y = 1f - Mathf.Cos(x * HALFPI); + break; + case Easing.SineOut: + y = Mathf.Sin(x * HALFPI); + break; + case Easing.SineInOut: + y = -0.5f * (Mathf.Cos(x * Mathf.PI) - 1f); + break; + + //y = x * x * (3f - 2f * x); + } + return y; + } + + // + protected float GetTweenTime() + { + return _tweenUseUnscaledTime ? Time.unscaledTime : Time.time; + } + + // + protected float GetConstantTime() + { + return _constantUseUnscaledTime ? Time.unscaledTime : Time.time; + } + #endregion + + #region Static Methods + // Color helper + static public Color HSVToRGB(float hue, float saturation, float value) + { + float x = 6f * Mathf.Clamp01(hue); + saturation = Mathf.Clamp01(saturation); + value = Mathf.Clamp01(value); + return new Color + ( + value * (1f + (Mathf.Clamp01(Mathf.Max(2f - x, x - 4f)) - 1f) * saturation), + value * (1f + (Mathf.Clamp01(Mathf.Min(x, 4f - x)) - 1f) * saturation), + value * (1f + (Mathf.Clamp01(Mathf.Min(x - 2f, 6f - x)) - 1f) * saturation) + ); + } + #endregion + + #region DEPRECATED + private GradientColorKey[] flashingColorKeys = new GradientColorKey[] + { + new GradientColorKey(new Color(0f, 1f, 1f, 0f), 0f), + new GradientColorKey(new Color(0f, 1f, 1f, 1f), 1f) + }; + private GradientAlphaKey[] flashingAlphaKeys = new GradientAlphaKey[] + { + new GradientAlphaKey(1f, 0f), + new GradientAlphaKey(1f, 1f), + }; + + /// + /// DEPRECATED. Use hover = true; instead. + /// + [System.Obsolete] + public void On() + { + hover = true; + } + + /// + /// DEPRECATED. Use Hover(Color color) instead. + /// + [System.Obsolete] + public void On(Color color) + { + Hover(color); + } + + /// + /// DEPRECATED. Use Hover(new Color(1f, 0f, 0f, 1f)); instead. + /// + [System.Obsolete] + public void OnParams(Color color) + { + _hoverColor = color; + } + + /// + /// DEPRECATED. Use constantColor = new Color(0f, 1f, 1f, 1f); instead. + /// + [System.Obsolete] + public void ConstantParams(Color color) + { + _constantColor = color; + } + + /// + /// DEPRECATED. Use tweenGradient and tweenDuration instead. + /// + [System.Obsolete] + public void FlashingParams(Color color1, Color color2, float freq) + { + flashingColorKeys[0].color = color1; + flashingColorKeys[1].color = color2; + _tweenGradient.SetKeys(flashingColorKeys, flashingAlphaKeys); + _tweenDuration = 1f / freq; + } + + /// + /// DEPRECATED. Use TweenStart() instead. + /// + [System.Obsolete] + public void FlashingOn() + { + TweenSet(true); + } + + /// + /// DEPRECATED. Use tweenGradient instead. + /// + [System.Obsolete] + public void FlashingOn(Color color1, Color color2) + { + flashingColorKeys[0].color = color1; + flashingColorKeys[1].color = color2; + _tweenGradient.SetKeys(flashingColorKeys, flashingAlphaKeys); + TweenSet(true); + } + + /// + /// DEPRECATED. Use tweenGradient and tweenDuration instead. + /// + [System.Obsolete] + public void FlashingOn(Color color1, Color color2, float freq) + { + flashingColorKeys[0].color = color1; + flashingColorKeys[1].color = color2; + _tweenGradient.SetKeys(flashingColorKeys, flashingAlphaKeys); + _tweenDuration = 1f / freq; + TweenSet(true); + } + + /// + /// DEPRECATED. Use tweenDuration instead. + /// + [System.Obsolete] + public void FlashingOn(float freq) + { + _tweenDuration = 1f / freq; + TweenSet(true); + } + + /// + /// DEPRECATED. Use TweenStop() instead. + /// + [System.Obsolete] + public void FlashingOff() + { + TweenSet(false); + } + + /// + /// DEPRECATED. Use TweenStart() and TweenStop() instead. + /// + [System.Obsolete] + public void FlashingSwitch() + { + tween = !tween; + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs.meta new file mode 100644 index 00000000..48e3699c --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Highlighter.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67d4de287b46eb34e83a61e4f9115070 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs b/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs new file mode 100644 index 00000000..3d6295c3 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs @@ -0,0 +1,11 @@ +using UnityEngine; +using System.Collections; + +namespace HighlightingSystem +{ + [AddComponentMenu("Highlighting System/Highlighter Blocker", 1)] + public class HighlighterBlocker : MonoBehaviour + { + + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs.meta new file mode 100644 index 00000000..8ed9128c --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlighterBlocker.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fa287908d1b1c094189eb8515f1387ef +timeCreated: 1438594893 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs new file mode 100644 index 00000000..5c796eaa --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs @@ -0,0 +1,68 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace HighlightingSystem +{ + [RequireComponent(typeof(Camera))] + [AddComponentMenu("Highlighting System/Highlighting Blitter", 3)] + public class HighlightingBlitter : MonoBehaviour + { + protected List renderers = new List(); + + #region MonoBehaviour + // + protected virtual void OnRenderImage(RenderTexture src, RenderTexture dst) + { + bool oddEven = true; + for (int i = 0; i < renderers.Count; i++) + { + HighlightingBase renderer = renderers[i]; + if (oddEven) + { + renderer.Blit(src, dst); + } + else + { + renderer.Blit(dst, src); + } + + oddEven = !oddEven; + } + + // Additional blit because final result should be in dst RenderTexture + if (oddEven) + { + Graphics.Blit(src, dst); + } + } + #endregion + + #region Public Methods + // + [UnityEngine.Internal.ExcludeFromDocs] + public virtual void Register(HighlightingBase renderer) + { + if (!renderers.Contains(renderer)) + { + renderers.Add(renderer); + } + + enabled = renderers.Count > 0; + } + + // + [UnityEngine.Internal.ExcludeFromDocs] + public virtual void Unregister(HighlightingBase renderer) + { + int index = renderers.IndexOf(renderer); + if (index != -1) + { + renderers.RemoveAt(index); + } + + enabled = renderers.Count > 0; + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs.meta new file mode 100644 index 00000000..3973d0a5 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingBlitter.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 278a95e6bd76df347879c9b2b9f887f9 +timeCreated: 1445810792 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs new file mode 100644 index 00000000..684068c9 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs @@ -0,0 +1,129 @@ +using UnityEngine; +using System.Collections; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace HighlightingSystem +{ + [AddComponentMenu("Highlighting System/Highlighting Renderer", 2)] + public class HighlightingRenderer : HighlightingBase + { + #region Static Fields + static public readonly List defaultPresets = new List() + { + new HighlightingPreset() { name = "Default", fillAlpha = 0f, downsampleFactor = 4, iterations = 2, blurMinSpread = 0.65f, blurSpread = 0.25f, blurIntensity = 0.3f, blurDirections = BlurDirections.Diagonal }, + new HighlightingPreset() { name = "Wide", fillAlpha = 0f, downsampleFactor = 4, iterations = 4, blurMinSpread = 0.65f, blurSpread = 0.25f, blurIntensity = 0.3f, blurDirections = BlurDirections.Diagonal }, + new HighlightingPreset() { name = "Strong", fillAlpha = 0f, downsampleFactor = 4, iterations = 2, blurMinSpread = 0.5f, blurSpread = 0.15f, blurIntensity = 0.325f, blurDirections = BlurDirections.Diagonal }, + new HighlightingPreset() { name = "Speed", fillAlpha = 0f, downsampleFactor = 4, iterations = 1, blurMinSpread = 0.75f, blurSpread = 0f, blurIntensity = 0.35f, blurDirections = BlurDirections.Diagonal }, + new HighlightingPreset() { name = "Quality", fillAlpha = 0f, downsampleFactor = 2, iterations = 3, blurMinSpread = 0.5f, blurSpread = 0.5f, blurIntensity = 0.28f, blurDirections = BlurDirections.Diagonal }, + new HighlightingPreset() { name = "Solid 1px", fillAlpha = 0f, downsampleFactor = 1, iterations = 1, blurMinSpread = 1f, blurSpread = 0f, blurIntensity = 1f, blurDirections = BlurDirections.All }, + new HighlightingPreset() { name = "Solid 2px", fillAlpha = 0f, downsampleFactor = 1, iterations = 2, blurMinSpread = 1f, blurSpread = 0f, blurIntensity = 1f, blurDirections = BlurDirections.All } + }; + #endregion + + #region Public Fields + public ReadOnlyCollection presets + { + get + { + if (_presetsReadonly == null) + { + _presetsReadonly = _presets.AsReadOnly(); + } + return _presetsReadonly; + } + } + #endregion + + #region Private Fields + [SerializeField] + private List _presets = new List(defaultPresets); + + private ReadOnlyCollection _presetsReadonly; + #endregion + + #region Public Methods + // Get stored preset by name + public bool GetPreset(string name, out HighlightingPreset preset) + { + for (int i = 0; i < _presets.Count; i++) + { + HighlightingPreset p = _presets[i]; + if (p.name == name) + { + preset = p; + return true; + } + } + preset = new HighlightingPreset(); + return false; + } + + // Add (store) preset + public bool AddPreset(HighlightingPreset preset, bool overwrite) + { + for (int i = 0; i < _presets.Count; i++) + { + HighlightingPreset p = _presets[i]; + if (p.name == preset.name) + { + if (overwrite) + { + _presets[i] = preset; + return true; + } + else + { + return false; + } + } + } + _presets.Add(preset); + return true; + } + + // Find stored preset by name and remove it + public bool RemovePreset(string name) + { + for (int i = 0; i < _presets.Count; i++) + { + HighlightingPreset p = _presets[i]; + if (p.name == name) + { + _presets.RemoveAt(i); + return true; + } + } + return false; + } + + // Find stored preset by name and apply it's settings + public bool LoadPreset(string name) + { + HighlightingPreset preset; + if (GetPreset(name, out preset)) + { + ApplyPreset(preset); + } + return false; + } + + // Apply preset settings + public void ApplyPreset(HighlightingPreset preset) + { + downsampleFactor = preset.downsampleFactor; + iterations = preset.iterations; + blurMinSpread = preset.blurMinSpread; + blurSpread = preset.blurSpread; + blurIntensity = preset.blurIntensity; + blurDirections = preset.blurDirections; + } + + // + public void ClearPresets() + { + _presets.Clear(); + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs.meta new file mode 100644 index 00000000..d89dd3d4 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/HighlightingRenderer.cs.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 8b765e0b5af3bcf4a9deb5895e477da8 +labels: +- Glow +- Effect +- Outline +- Highlight +- Selection +- System +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal.meta new file mode 100644 index 00000000..9d57011f --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 3e2a98eec43f4f04788ccf35d4ae8ec4 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs new file mode 100644 index 00000000..51f3a047 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace HighlightingSystem +{ + [UnityEngine.Internal.ExcludeFromDocs] + public class EndOfFrame : MonoBehaviour + { + [UnityEngine.Internal.ExcludeFromDocs] + public delegate void OnEndOfFrame(); + + #region Static Fields + static private EndOfFrame _singleton; + static private EndOfFrame singleton + { + get + { + if (_singleton == null) + { + GameObject go = new GameObject("EndOfFrameHelper"); + go.hideFlags = HideFlags.HideAndDontSave; + _singleton = go.AddComponent(); + } + return _singleton; + } + } + #endregion + + #region Private Fields + private WaitForEndOfFrame waitForEndOfFrame = new WaitForEndOfFrame(); + private Coroutine coroutine; + private List listeners = new List(); + #endregion + + #region MonoBehaviour + // + void OnEnable() + { + coroutine = StartCoroutine(EndOfFrameRoutine()); + } + + // + void OnDisable() + { + if (coroutine != null) + { + StopCoroutine(coroutine); + } + } + #endregion + + #region Public Methods + // + static public void AddListener(OnEndOfFrame listener) + { + if (listener == null) { return; } + + singleton.listeners.Add(listener); + } + + // + static public void RemoveListener(OnEndOfFrame listener) + { + if (listener == null || _singleton == null) { return; } + + singleton.listeners.Remove(listener); + } + #endregion + + #region Private Methods + // + private IEnumerator EndOfFrameRoutine() + { + while (true) + { + yield return waitForEndOfFrame; + + for (int i = listeners.Count - 1; i >= 0; i--) + { + OnEndOfFrame listener = listeners[i]; + if (listener != null) + { + listener(); + } + else + { + listeners.RemoveAt(i); + } + } + } + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs.meta new file mode 100644 index 00000000..352d24a0 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/EndOfFrame.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3116e6cc88ed97b4d8eb4053f451aaf7 +timeCreated: 1505081746 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs new file mode 100644 index 00000000..57d0d031 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs @@ -0,0 +1,548 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace HighlightingSystem +{ + public enum HighlighterMode : int + { + Disabled = -1, + Default = 0, + Overlay = 1, + Occluder = 2, + } + + [DisallowMultipleComponent] + public class HighlighterCore : MonoBehaviour + { + [UnityEngine.Internal.ExcludeFromDocs] + private class RendererData + { + public Renderer renderer; + public List submeshIndices = new List(); + } + + // Constants (don't touch this!) + #region Constants + // + [UnityEngine.Internal.ExcludeFromDocs] + public const string keywordOverlay = "HIGHLIGHTING_OVERLAY"; + + // Occlusion color + private readonly Color occluderColor = new Color(0f, 0f, 0f, 0f); + + // Highlighting modes rendered in that order + static private readonly HighlighterMode[] renderingOrder = new HighlighterMode[] + { + HighlighterMode.Default, + HighlighterMode.Overlay, + HighlighterMode.Occluder + }; + + // Pool chunk size for sRendererDataPool expansion + private const int poolChunkSize = 4; + #endregion + + #region Static Fields + // Static collections to prevent unnecessary memory allocations for grabbing and filtering renderer components + static private readonly List sRenderers = new List(4); + static private readonly Stack sRendererDataPool = new Stack(); + static private readonly List sRendererData = new List(4); + static private readonly List sSubmeshIndices = new List(4); + static private readonly List sHighlighters = new List(); // Collection of all enabled highlighters + static private ReadOnlyCollection sHighlightersReadonly; + #endregion + + #region Public Accessors + static public ReadOnlyCollection highlighters + { + get + { + if (sHighlightersReadonly == null) + { + sHighlightersReadonly = sHighlighters.AsReadOnly(); + } + + return sHighlightersReadonly; + } + } + #endregion + + #region Public Fields + /// + /// Defines how this highlighter instance will be rendered. + /// + public HighlighterMode mode = HighlighterMode.Default; + + /// + /// Force-render this Highlighter. No culling is performed in this case (neither frustum nor occlusion culling) and renderers from all LOD levels will be always rendered. + /// Please be considerate in enabling this mode, or you may experience performance degradation. + /// + public bool forceRender; + + /// + /// Highlighting color. + /// + public Color color = Color.white; + #endregion + + #region Private Fields + // Cached transform component reference + private Transform tr; + + // Cached Renderers + private List highlightableRenderers = new List(); + + // Renderers dirty flag + private bool isDirty = true; + + // Cached highlighting mode + private bool cachedOverlay = false; + + // Cached highlighting color + private Color cachedColor = Color.clear; + + // Opaque shader cached reference + static private Shader _opaqueShader; + [UnityEngine.Internal.ExcludeFromDocs] + static public Shader opaqueShader + { + get + { + if (_opaqueShader == null) + { + _opaqueShader = Shader.Find("Hidden/Highlighted/Opaque"); + } + return _opaqueShader; + } + } + + // Transparent shader cached reference + static private Shader _transparentShader; + [UnityEngine.Internal.ExcludeFromDocs] + static public Shader transparentShader + { + get + { + if (_transparentShader == null) + { + _transparentShader = Shader.Find("Hidden/Highlighted/Transparent"); + } + return _transparentShader; + } + } + + // Shared (for this component) replacement material for opaque geometry highlighting + private Material _opaqueMaterial; + private Material opaqueMaterial + { + get + { + if (_opaqueMaterial == null) + { + _opaqueMaterial = new Material(opaqueShader); + + // Make sure that shader will have proper default values + _opaqueMaterial.SetKeyword(keywordOverlay, cachedOverlay); + _opaqueMaterial.SetColor(ShaderPropertyID._HighlightingColor, cachedColor); + } + return _opaqueMaterial; + } + } + #endregion + + #region Renderers Filtration + public delegate bool RendererFilter(Renderer renderer, List submeshIndices); + + static private RendererFilter _globalRendererFilter = null; + static public RendererFilter globalRendererFilter + { + get { return _globalRendererFilter; } + set + { + if (_globalRendererFilter != value) + { + _globalRendererFilter = value; + + for (int i = sHighlighters.Count - 1; i >= 0; i--) + { + var highlighter = sHighlighters[i]; + + // Cleanup null highlighters for extra safety + if (highlighter == null) + { + sHighlighters.RemoveAt(i); + continue; + } + + // Reinitialize all Highlighters without explicitly assigned rendererFilters + if (highlighter.rendererFilter == null) + { + highlighter.SetDirty(); + } + } + } + } + } + + private RendererFilter _rendererFilter = null; + public RendererFilter rendererFilter + { + get { return _rendererFilter; } + set + { + if (_rendererFilter != value) + { + _rendererFilter = value; + + SetDirty(); + } + } + } + + protected virtual RendererFilter rendererFilterToUse + { + get + { + if (_rendererFilter != null) + { + return _rendererFilter; + } + else if (_globalRendererFilter != null) + { + return _globalRendererFilter; + } + else + { + return DefaultRendererFilter; + } + } + } + + // + static public bool DefaultRendererFilter(Renderer renderer, List submeshIndices) + { + // Do not highlight this renderer if it has HighlighterBlocker in parent + if (renderer.GetComponentInParent() != null) { return false; } + + bool pass = false; + + if (renderer is MeshRenderer) { pass = true; } + else if (renderer is SkinnedMeshRenderer) { pass = true; } + else if (renderer is SpriteRenderer) { pass = true; } + else if (renderer is ParticleSystemRenderer) { pass = true; } + + if (pass) + { + // Highlight all submeshes + submeshIndices.Add(-1); + } + + return pass; + } + #endregion + + #region MonoBehaviour + // Override and use AwakeSafe instead of this method + private void Awake() + { + tr = GetComponent(); + AwakeSafe(); + } + + // Override and use OnEnableSafe instead of this method + private void OnEnable() + { + if (!sHighlighters.Contains(this)) { sHighlighters.Add(this); } + OnEnableSafe(); + } + + // Override and use OnDisableSafe instead of this method + private void OnDisable() + { + sHighlighters.Remove(this); + ClearRenderers(); + isDirty = true; + OnDisableSafe(); + } + + // + private void OnDestroy() + { + // Unity never garbage-collects unreferenced materials, so it is our responsibility to destroy them + if (_opaqueMaterial != null) + { + Destroy(_opaqueMaterial); + } + OnDestroySafe(); + } + #endregion + + #region MonoBehaviour Overrides + // + protected virtual void AwakeSafe() { } + + // + protected virtual void OnEnableSafe() { } + + // + protected virtual void OnDisableSafe() { } + + // + protected virtual void OnDestroySafe() { } + #endregion + + #region Public Methods + /// + /// Reinitialize renderers. + /// 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 SetDirty() + { + isDirty = true; + } + #endregion + + #region Protected Methods + // + protected virtual void UpdateHighlighting() + { + // Update highlighting mode and color here. + } + #endregion + + #region Private Methods + // Clear cached renderers + private void ClearRenderers() + { + for (int i = highlightableRenderers.Count - 1; i >= 0; i--) + { + HighlighterRenderer renderer = highlightableRenderers[i]; + renderer.isAlive = false; + } + highlightableRenderers.Clear(); + } + + // This method defines how renderers are initialized + private void UpdateRenderers() + { + if (isDirty) + { + isDirty = false; + + ClearRenderers(); + + // Find all renderers which should be highlighted with this HighlighterCore component instance + GrabRenderers(tr); + + // Cache found renderers + for (int i = 0, imax = sRendererData.Count; i < imax; i++) + { + RendererData rendererData = sRendererData[i]; + GameObject rg = rendererData.renderer.gameObject; + + HighlighterRenderer renderer = rg.GetComponent(); + if (renderer == null) { renderer = rg.AddComponent(); } + renderer.isAlive = true; + + renderer.Initialize(opaqueMaterial, transparentShader, rendererData.submeshIndices); + renderer.SetOverlay(cachedOverlay); + renderer.SetColor(cachedColor); + highlightableRenderers.Add(renderer); + } + + // Release RendererData instances + for (int i = 0; i < sRendererData.Count; i++) + { + ReleaseRendererDataInstance(sRendererData[i]); + } + sRendererData.Clear(); + } + } + + // Recursively follows hierarchy of objects from t, searches for Renderers and adds them to the list. + // Breaks if another Highlighter component found + private void GrabRenderers(Transform t) + { + GameObject g = t.gameObject; + + // Find all Renderers on the current GameObject g, filter them and add to the sRendererData list + g.GetComponents(sRenderers); + for (int i = 0, imax = sRenderers.Count; i < imax; i++) + { + Renderer renderer = sRenderers[i]; + if (rendererFilterToUse(renderer, sSubmeshIndices)) + { + RendererData rendererData = GetRendererDataInstance(); + rendererData.renderer = renderer; + List submeshIndices = rendererData.submeshIndices; + submeshIndices.Clear(); + submeshIndices.AddRange(sSubmeshIndices); + sRendererData.Add(rendererData); + } + sSubmeshIndices.Clear(); + } + sRenderers.Clear(); + + // Return if transform t doesn't have any children + int childCount = t.childCount; + if (childCount == 0) { return; } + + // Recursively cache renderers on all child GameObjects + for (int i = 0; i < childCount; i++) + { + Transform childTransform = t.GetChild(i); + + // Do not cache Renderers of this childTransform in case it has it's own Highlighter component + HighlighterCore h = childTransform.GetComponent(); + if (h != null) { continue; } + + GrabRenderers(childTransform); + } + } + + // + private void FillBufferInternal(CommandBuffer buffer) + { + // Set cachedOverlay if changed + bool overlayToUse = mode == HighlighterMode.Overlay || mode == HighlighterMode.Occluder; + if (cachedOverlay != overlayToUse) + { + cachedOverlay = overlayToUse; + + opaqueMaterial.SetKeyword(keywordOverlay, cachedOverlay); + for (int i = 0; i < highlightableRenderers.Count; i++) + { + highlightableRenderers[i].SetOverlay(cachedOverlay); + } + } + + // Set cachedColor if changed + Color colorToUse = mode != HighlighterMode.Occluder ? color : occluderColor; + if (cachedColor != colorToUse) + { + cachedColor = colorToUse; + + // Apply color + opaqueMaterial.SetColor(ShaderPropertyID._HighlightingColor, cachedColor); + for (int i = 0; i < highlightableRenderers.Count; i++) + { + highlightableRenderers[i].SetColor(cachedColor); + } + } + + // Fill CommandBuffer with this highlighter rendering commands + for (int i = highlightableRenderers.Count - 1; i >= 0; i--) + { + // To avoid null-reference exceptions when cached renderer has been removed but SetDirty() wasn't been called + HighlighterRenderer renderer = highlightableRenderers[i]; + if (renderer == null) + { + highlightableRenderers.RemoveAt(i); + } + else if (!renderer.IsValid()) + { + highlightableRenderers.RemoveAt(i); + renderer.isAlive = false; + } + else + { + // Check if renderer is visible for the currently rendering camera. + // (Last camera called OnWillRenderObject on HighlighterRenderer instance is the same camera for which we're currently filling CommandBuffer) + if (HighlightingBase.GetVisible(renderer) || forceRender) + { + renderer.FillBuffer(buffer); + } + } + } + } + #endregion + + #region Static Methods + // + static private void ExpandRendererDataPool(int count) + { + for (int i = 0; i < count; i++) + { + RendererData instance = new RendererData(); + sRendererDataPool.Push(instance); + } + } + + // + static private RendererData GetRendererDataInstance() + { + RendererData instance; + + if (sRendererDataPool.Count == 0) + { + ExpandRendererDataPool(poolChunkSize); + } + + instance = sRendererDataPool.Pop(); + + return instance; + } + + // + static private void ReleaseRendererDataInstance(RendererData instance) + { + if (instance == null || sRendererDataPool.Contains(instance)) { return; } + + instance.renderer = null; + instance.submeshIndices.Clear(); + + sRendererDataPool.Push(instance); + } + + // Fill CommandBuffer with highlighters rendering commands + [UnityEngine.Internal.ExcludeFromDocs] + static public void FillBuffer(CommandBuffer buffer) + { + // Update all highlighters + for (int i = sHighlighters.Count - 1; i >= 0; i--) + { + var highlighter = sHighlighters[i]; + + // Cleanup null highlighters for extra safety + if (highlighter == null) + { + sHighlighters.RemoveAt(i); + continue; + } + + // Update mode and color + highlighter.UpdateHighlighting(); + + // Cleanup again in case Highlighter has been destroyed in UpdateHighlighting() call + if (highlighter == null) + { + sHighlighters.RemoveAt(i); + continue; + } + + // Update Renderer's if dirty + highlighter.UpdateRenderers(); + } + + // Fill CommandBuffer with highlighters rendering commands + for (int i = 0; i < renderingOrder.Length; i++) + { + HighlighterMode renderMode = renderingOrder[i]; + + for (int j = sHighlighters.Count - 1; j >= 0; j--) + { + var highlighter = sHighlighters[j]; + if (highlighter.mode == renderMode) + { + highlighter.FillBufferInternal(buffer); + } + } + } + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs.meta new file mode 100644 index 00000000..26338ae2 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterCore.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 00769d7dc66ce2a49a2ad03dc19d205e +timeCreated: 1516141170 +licenseType: Store +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs new file mode 100644 index 00000000..c4d2f784 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs @@ -0,0 +1,215 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System.Collections; +using System.Collections.Generic; + +namespace HighlightingSystem +{ + [DisallowMultipleComponent] + [AddComponentMenu("")] // Hide in 'Add Component' menu + [UnityEngine.Internal.ExcludeFromDocs] + public class HighlighterRenderer : MonoBehaviour + { + [UnityEngine.Internal.ExcludeFromDocs] + private struct Data + { + public Material material; + public int submeshIndex; + public bool transparent; + } + + #region Constants + // Default transparency cutoff value (used for shaders without _Cutoff property) + static private float transparentCutoff = 0.5f; + + // Flags to hide and don't save this component in editor + private const HideFlags flags = HideFlags.HideInInspector | HideFlags.DontSaveInEditor | HideFlags.NotEditable | HideFlags.DontSaveInBuild; + + // Cull Off + private const int cullOff = (int)CullMode.Off; + #endregion + + #region Static Fields + static private readonly string sRenderType = "RenderType"; + static private readonly string sOpaque = "Opaque"; + static private readonly string sTransparent = "Transparent"; + static private readonly string sTransparentCutout = "TransparentCutout"; + static private readonly string sMainTex = "_MainTex"; + #endregion + + #region Public Fields + public bool isAlive = false; + #endregion + + #region Private Fields + private Renderer r; + private List data = new List(); + #endregion + + #region MonoBehaviour + // + void Awake() + { + this.hideFlags = flags; + } + + // + void OnEnable() + { + EndOfFrame.AddListener(OnEndOfFrame); + } + + // + void OnDisable() + { + EndOfFrame.RemoveListener(OnEndOfFrame); + } + + // Called once (before OnPreRender) for each camera if the object is visible. + // The function is called during the culling process just before rendering each culled object. + void OnWillRenderObject() + { + HighlightingBase.SetVisible(this); + } + + // + void OnDestroy() + { + // Data will be null if Undo / Redo was performed in Editor to delete / restore object with this component + if (data == null) { return; } + + for (int i = 0, imax = data.Count; i < imax; i++) + { + Data d = data[i]; + // Unity never garbage-collects unreferenced materials, so it is our responsibility to destroy them + if (d.transparent) + { + Destroy(d.material); + } + } + } + #endregion + + #region Public Methods + // + public void Initialize(Material sharedOpaqueMaterial, Shader transparentShader, List submeshIndices) + { + data.Clear(); + + r = GetComponent(); + Material[] materials = r.sharedMaterials; + int materialsLength = materials.Length; + + if (materials == null || materialsLength == 0) { return; } + + // Highlight all submeshes + if (submeshIndices.Count == 1 && submeshIndices[0] == -1) + { + submeshIndices.Clear(); + for (int i = 0; i < materialsLength; i++) + { + submeshIndices.Add(i); + } + } + + // Prepare specified submeshIndices + for (int i = 0, imax = submeshIndices.Count; i < imax; i++) + { + int submeshIndex = submeshIndices[i]; + + // Invalid submeshIndex + if (submeshIndex >= materialsLength) { continue; } + + Material sourceMat = materials[submeshIndex]; + + if (sourceMat == null) { continue; } + + Data d = new Data(); + + string tag = sourceMat.GetTag(sRenderType, true, sOpaque); + if (tag == sTransparent || tag == sTransparentCutout) + { + Material replacementMat = new Material(transparentShader); + + // To render both sides of the Sprite + if (r is SpriteRenderer) { replacementMat.SetInt(ShaderPropertyID._HighlightingCull, cullOff); } + + if (sourceMat.HasProperty(ShaderPropertyID._MainTex)) + { + replacementMat.SetTexture(ShaderPropertyID._MainTex, sourceMat.mainTexture); + replacementMat.SetTextureOffset(sMainTex, sourceMat.mainTextureOffset); + replacementMat.SetTextureScale(sMainTex, sourceMat.mainTextureScale); + } + + int cutoff = ShaderPropertyID._Cutoff; + replacementMat.SetFloat(cutoff, sourceMat.HasProperty(cutoff) ? sourceMat.GetFloat(cutoff) : transparentCutoff); + + d.material = replacementMat; + d.transparent = true; + } + else + { + d.material = sharedOpaqueMaterial; + d.transparent = false; + } + + d.submeshIndex = submeshIndex; + data.Add(d); + } + } + + // + public void SetOverlay(bool overlay) + { + for (int i = 0, imax = data.Count; i < imax; i++) + { + Data d = data[i]; + if (d.transparent) + { + d.material.SetKeyword(HighlighterCore.keywordOverlay, overlay); + } + } + } + + // Sets given color as highlighting color on all transparent materials of this renderer + public void SetColor(Color clr) + { + for (int i = 0, imax = data.Count; i < imax; i++) + { + Data d = data[i]; + if (d.transparent) + { + d.material.SetColor(ShaderPropertyID._HighlightingColor, clr); + } + } + } + + // + public void FillBuffer(CommandBuffer buffer) + { + for (int i = 0, imax = data.Count; i < imax; i++) + { + Data d = data[i]; + buffer.DrawRenderer(r, d.material, d.submeshIndex); + } + } + + // + public bool IsValid() + { + return r != null; + } + #endregion + + #region Private Methods + // + private void OnEndOfFrame() + { + if (!isAlive) + { + Destroy(this); + } + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs.meta new file mode 100644 index 00000000..a09a2ebd --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlighterRenderer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 23ffcf5db409ff94baada0048d38c89d +timeCreated: 1454246717 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs new file mode 100644 index 00000000..2fb3d96b --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs @@ -0,0 +1,634 @@ +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.Serialization; +using UnityEngine.XR; +using System.Collections; +using System.Collections.Generic; +#if UNITY_5_5_OR_NEWER +using UnityEngine.Profiling; +#endif + +namespace HighlightingSystem +{ + public enum BlurDirections : int + { + Diagonal, + Straight, + All + } + + public enum AntiAliasing : int + { + QualitySettings, + Disabled, + MSAA2x, + MSAA4x, + MSAA8x, + } + + [DisallowMultipleComponent] + [RequireComponent(typeof(Camera))] + public class HighlightingBase : MonoBehaviour + { + #region Static Fields and Constants + static protected readonly Color colorClear = new Color(0f, 0f, 0f, 0f); + static protected readonly string renderBufferName = "HighlightingSystem"; + static protected readonly Matrix4x4 identityMatrix = Matrix4x4.identity; + static protected readonly string keywordStraightDirections = "STRAIGHT_DIRECTIONS"; + static protected readonly string keywordAllDirections = "ALL_DIRECTIONS"; + static protected readonly string profileHighlightingSystem = "HighlightingSystem"; + protected const CameraEvent queue = CameraEvent.BeforeImageEffectsOpaque; + + static protected Camera currentCamera; + static protected HashSet visibleRenderers = new HashSet(); + #endregion + + #region Accessors + // True if supported on this platform + public bool isSupported + { + get + { + return CheckSupported(false); + } + } + + public float fillAlpha + { + get { return _fillAlpha; } + set + { + value = Mathf.Clamp01(value); + if (_fillAlpha != value) + { + if (Application.isPlaying) + { + cutMaterial.SetFloat(ShaderPropertyID._HighlightingFillAlpha, value); + } + + _fillAlpha = value; + } + } + } + + // Highlighting buffer size downsample factor + public int downsampleFactor + { + get { return _downsampleFactor; } + set + { + if (_downsampleFactor != value) + { + // Is power of two check + if ((value != 0) && ((value & (value - 1)) == 0)) + { + _downsampleFactor = value; + } + else + { + Debug.LogWarning("HighlightingSystem : Prevented attempt to set incorrect downsample factor value."); + } + } + } + } + + // Blur iterations + public int iterations + { + get { return _iterations; } + set + { + if (_iterations != value) + { + _iterations = value; + } + } + } + + // Blur minimal spread + public float blurMinSpread + { + get { return _blurMinSpread; } + set + { + if (_blurMinSpread != value) + { + _blurMinSpread = value; + } + } + } + + // Blur spread per iteration + public float blurSpread + { + get { return _blurSpread; } + set + { + if (_blurSpread != value) + { + _blurSpread = value; + } + } + } + + // Blurring intensity for the blur material + public float blurIntensity + { + get { return _blurIntensity; } + set + { + if (_blurIntensity != value) + { + _blurIntensity = value; + if (Application.isPlaying) + { + blurMaterial.SetFloat(ShaderPropertyID._HighlightingIntensity, _blurIntensity); + } + } + } + } + + public BlurDirections blurDirections + { + get { return _blurDirections; } + set + { + if (_blurDirections != value) + { + _blurDirections = value; + if (Application.isPlaying) + { + blurMaterial.SetKeyword(keywordStraightDirections, _blurDirections == BlurDirections.Straight); + blurMaterial.SetKeyword(keywordAllDirections, _blurDirections == BlurDirections.All); + } + } + } + } + + // Blitter component reference (optional) + public HighlightingBlitter blitter + { + get { return _blitter; } + set + { + if (_blitter != value) + { + if (_blitter != null) + { + _blitter.Unregister(this); + } + _blitter = value; + if (_blitter != null) + { + _blitter.Register(this); + } + } + } + } + + public AntiAliasing antiAliasing + { + get { return _antiAliasing; } + set + { + if (_antiAliasing != value) + { + _antiAliasing = value; + } + } + } + #endregion + + #region Protected Fields + protected CommandBuffer renderBuffer; + + protected RenderTextureDescriptor cachedDescriptor; + + [SerializeField] + protected float _fillAlpha = 0f; + + [FormerlySerializedAs("downsampleFactor")] + [SerializeField] + protected int _downsampleFactor = 4; + + [FormerlySerializedAs("iterations")] + [SerializeField] + protected int _iterations = 2; + + [FormerlySerializedAs("blurMinSpread")] + [SerializeField] + protected float _blurMinSpread = 0.65f; + + [FormerlySerializedAs("blurSpread")] + [SerializeField] + protected float _blurSpread = 0.25f; + + [SerializeField] + protected float _blurIntensity = 0.3f; + + [SerializeField] + protected BlurDirections _blurDirections = BlurDirections.Diagonal; + + [SerializeField] + protected HighlightingBlitter _blitter; + + [SerializeField] + protected AntiAliasing _antiAliasing = AntiAliasing.QualitySettings; + + // RenderTargetidentifier for the highlightingBuffer RenderTexture + protected RenderTargetIdentifier highlightingBufferID; + protected RenderTargetIdentifier blur1ID; + protected RenderTargetIdentifier blur2ID; + + // RenderTexture with highlighting buffer + protected RenderTexture highlightingBuffer = null; + + // Camera reference + protected Camera cam = null; + + // Material parameters + protected const int BLUR = 0; + protected const int CUT = 1; + protected const int COMP = 2; + static protected readonly string[] shaderPaths = new string[] + { + "Hidden/Highlighted/Blur", + "Hidden/Highlighted/Cut", + "Hidden/Highlighted/Composite", + }; + static protected Shader[] shaders; + static protected Material[] materials; + + // Dynamic materials + protected Material blurMaterial; + protected Material cutMaterial; + protected Material compMaterial; + + static protected bool initialized = false; + #endregion + + #region MonoBehaviour + // + protected virtual void OnEnable() + { + Initialize(); + + if (!CheckSupported(true)) + { + enabled = false; + Debug.LogError("HighlightingSystem : Highlighting System has been disabled due to unsupported Unity features on the current platform!"); + return; + } + + blur1ID = new RenderTargetIdentifier(ShaderPropertyID._HighlightingBlur1); + blur2ID = new RenderTargetIdentifier(ShaderPropertyID._HighlightingBlur2); + + blurMaterial = new Material(materials[BLUR]); + cutMaterial = new Material(materials[CUT]); + compMaterial = new Material(materials[COMP]); + + // Set initial material properties + blurMaterial.SetKeyword(keywordStraightDirections, _blurDirections == BlurDirections.Straight); + blurMaterial.SetKeyword(keywordAllDirections, _blurDirections == BlurDirections.All); + blurMaterial.SetFloat(ShaderPropertyID._HighlightingIntensity, _blurIntensity); + cutMaterial.SetFloat(ShaderPropertyID._HighlightingFillAlpha, _fillAlpha); + + renderBuffer = new CommandBuffer(); + renderBuffer.name = renderBufferName; + + cam = GetComponent(); + + cam.depthTextureMode |= DepthTextureMode.Depth; + + cam.AddCommandBuffer(queue, renderBuffer); + + if (_blitter != null) + { + _blitter.Register(this); + } + + EndOfFrame.AddListener(OnEndOfFrame); + } + + // + protected virtual void OnDisable() + { + if (renderBuffer != null) + { + cam.RemoveCommandBuffer(queue, renderBuffer); + renderBuffer = null; + } + + if (highlightingBuffer != null && highlightingBuffer.IsCreated()) + { + highlightingBuffer.Release(); + highlightingBuffer = null; + } + + if (_blitter != null) + { + _blitter.Unregister(this); + } + + EndOfFrame.RemoveListener(OnEndOfFrame); + } + + // + protected virtual void OnPreCull() + { + currentCamera = cam; + visibleRenderers.Clear(); + } + + // + protected virtual void OnPreRender() + { + Profiler.BeginSample("HighlightingSystem.OnPreRender"); + + var descriptor = GetDescriptor(); + + if (highlightingBuffer == null || !Equals(cachedDescriptor, descriptor)) + { + if (highlightingBuffer != null) + { + if (highlightingBuffer.IsCreated()) + { + highlightingBuffer.Release(); + } + highlightingBuffer = null; + } + + cachedDescriptor = descriptor; + + highlightingBuffer = new RenderTexture(cachedDescriptor); + highlightingBuffer.filterMode = FilterMode.Point; + highlightingBuffer.wrapMode = TextureWrapMode.Clamp; + + if (!highlightingBuffer.Create()) + { + Debug.LogError("HighlightingSystem : UpdateHighlightingBuffer() : Failed to create highlightingBuffer RenderTexture!"); + } + + highlightingBufferID = new RenderTargetIdentifier(highlightingBuffer); + compMaterial.SetTexture(ShaderPropertyID._HighlightingBuffer, highlightingBuffer); + } + + RebuildCommandBuffer(); + Profiler.EndSample(); + } + + // Do not remove! + // Having this method in this script is necessary to support multiple cameras with different clear flags even in case custom blitter is being used. + // Also, CommandBuffer is bound to CameraEvent.BeforeImageEffectsOpaque event, + // so Unity will spam 'depthSurface == NULL || rcolorZero->backBuffer == depthSurface->backBuffer' error even if MSAA is enabled + protected virtual void OnRenderImage(RenderTexture src, RenderTexture dst) + { + Profiler.BeginSample("HighlightingSystem.OnRenderImage"); + if (blitter == null) + { + Blit(src, dst); + } + else + { + Graphics.Blit(src, dst); + } + Profiler.EndSample(); + } + + // + protected virtual void OnEndOfFrame() + { + currentCamera = null; + visibleRenderers.Clear(); + } + #endregion + + #region Internal + // + [UnityEngine.Internal.ExcludeFromDocs] + static public void SetVisible(HighlighterRenderer renderer) + { + // Another camera may intercept rendering and send it's own OnWillRenderObject events (i.e. water rendering). + // Also, VR Camera with Multi Pass Stereo Rendering Method renders twice per frame (once for each eye), + // but OnWillRenderObject is called once so we have to check. + if (Camera.current != currentCamera) { return; } + + // Add to the list of renderers visible for the current Highlighting renderer + visibleRenderers.Add(renderer); + } + + // + [UnityEngine.Internal.ExcludeFromDocs] + static public bool GetVisible(HighlighterRenderer renderer) + { + return visibleRenderers.Contains(renderer); + } + + // + static protected void Initialize() + { + if (initialized) { return; } + + // Initialize shaders and materials + int l = shaderPaths.Length; + shaders = new Shader[l]; + materials = new Material[l]; + for (int i = 0; i < l; i++) + { + Shader shader = Shader.Find(shaderPaths[i]); + shaders[i] = shader; + + Material material = new Material(shader); + materials[i] = material; + } + + initialized = true; + } + + // + protected virtual RenderTextureDescriptor GetDescriptor() + { + RenderTextureDescriptor descriptor; + + // RTT + var targetTexture = cam.targetTexture; + if (targetTexture != null) + { + descriptor = targetTexture.descriptor; + } + // VR + else if (XRSettings.enabled) + { + descriptor = XRSettings.eyeTextureDesc; + } + // Normal + else + { + descriptor = new RenderTextureDescriptor(cam.pixelWidth, cam.pixelHeight, RenderTextureFormat.ARGB32, 24); + } + + // Overrides + descriptor.colorFormat = RenderTextureFormat.ARGB32; + descriptor.sRGB = QualitySettings.activeColorSpace == ColorSpace.Linear; + descriptor.useMipMap = false; + descriptor.msaaSamples = GetAA(targetTexture); + + return descriptor; + } + + // + protected virtual bool Equals(RenderTextureDescriptor x, RenderTextureDescriptor y) + { + return x.width == y.width && x.height == y.height && x.msaaSamples == y.msaaSamples; // TODO compare all fields? + } + + // + protected virtual int GetAA(RenderTexture targetTexture) + { + int aa = 1; + switch (_antiAliasing) + { + case AntiAliasing.QualitySettings: + // Set aa value to 1 in case camera is in DeferredLighting or DeferredShading Rendering Path + if (cam.actualRenderingPath == RenderingPath.DeferredLighting || cam.actualRenderingPath == RenderingPath.DeferredShading) + { + aa = 1; + } + else + { + if (targetTexture == null) + { + aa = QualitySettings.antiAliasing; + if (aa == 0) { aa = 1; } + } + else + { + aa = targetTexture.antiAliasing; + } + } + break; + case AntiAliasing.Disabled: + aa = 1; + break; + case AntiAliasing.MSAA2x: + aa = 2; + break; + case AntiAliasing.MSAA4x: + aa = 4; + break; + case AntiAliasing.MSAA8x: + aa = 8; + break; + } + return aa; + } + + // + protected virtual bool CheckSupported(bool verbose) + { + bool supported = true; + + // Image Effects supported? + if (!SystemInfo.supportsImageEffects) + { + if (verbose) { Debug.LogError("HighlightingSystem : Image effects is not supported on this platform!"); } + supported = false; + } + + // Required Render Texture Format supported? + if (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32)) + { + if (verbose) { Debug.LogError("HighlightingSystem : RenderTextureFormat.ARGB32 is not supported on this platform!"); } + supported = false; + } + + // HighlightingOpaque shader supported? + if (!HighlighterCore.opaqueShader.isSupported) + { + if (verbose) { Debug.LogError("HighlightingSystem : HighlightingOpaque shader is not supported on this platform!"); } + supported = false; + } + + // HighlightingTransparent shader supported? + if (!HighlighterCore.transparentShader.isSupported) + { + if (verbose) { Debug.LogError("HighlightingSystem : HighlightingTransparent shader is not supported on this platform!"); } + supported = false; + } + + // Highlighting shaders supported? + for (int i = 0; i < shaders.Length; i++) + { + Shader shader = shaders[i]; + if (!shader.isSupported) + { + if (verbose) { Debug.LogError("HighlightingSystem : Shader '" + shader.name + "' is not supported on this platform!"); } + supported = false; + } + } + + return supported; + } + + // + protected virtual void RebuildCommandBuffer() + { + renderBuffer.Clear(); + + renderBuffer.BeginSample(profileHighlightingSystem); + + // Prepare and clear render target + renderBuffer.SetRenderTarget(highlightingBufferID); + renderBuffer.ClearRenderTarget(true, true, colorClear); + + // Fill buffer with highlighters rendering commands + HighlighterCore.FillBuffer(renderBuffer); + + RenderTextureDescriptor desc = cachedDescriptor; + desc.width = highlightingBuffer.width / _downsampleFactor; + desc.height = highlightingBuffer.height / _downsampleFactor; + desc.depthBufferBits = 0; + + // Create two buffers for blurring the image + renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur1, desc, FilterMode.Bilinear); + renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur2, desc, FilterMode.Bilinear); + + renderBuffer.Blit(highlightingBufferID, blur1ID); + + // Blur the small texture + bool oddEven = true; + for (int i = 0; i < _iterations; i++) + { + float off = _blurMinSpread + _blurSpread * i; + renderBuffer.SetGlobalFloat(ShaderPropertyID._HighlightingBlurOffset, off); + + if (oddEven) + { + renderBuffer.Blit(blur1ID, blur2ID, blurMaterial); + } + else + { + renderBuffer.Blit(blur2ID, blur1ID, blurMaterial); + } + + oddEven = !oddEven; + } + + // Upscale blurred texture and cut stencil from it + renderBuffer.Blit(oddEven ? blur1ID : blur2ID, highlightingBufferID, cutMaterial); + + // Cleanup + renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur1); + renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur2); + + renderBuffer.EndSample(profileHighlightingSystem); + } + + // Blit highlighting result to the destination RenderTexture + public virtual void Blit(RenderTexture src, RenderTexture dst) + { + Graphics.Blit(src, dst, compMaterial); + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs.meta new file mode 100644 index 00000000..5b7e4357 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingBase.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c9a69acb2622340e39a2b84d908232e3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs new file mode 100644 index 00000000..508c69b6 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using System; + +namespace HighlightingSystem +{ + [Serializable] + public struct HighlightingPreset : IEquatable + { + public string name { get { return _name; } set { _name = value; } } + public float fillAlpha { get { return _fillAlpha; } set { _fillAlpha = value; } } + public int downsampleFactor { get { return _downsampleFactor; } set { _downsampleFactor = value; } } + public int iterations { get { return _iterations; } set { _iterations = value; } } + public float blurMinSpread { get { return _blurMinSpread; } set { _blurMinSpread = value; } } + public float blurSpread { get { return _blurSpread; } set { _blurSpread = value; } } + public float blurIntensity { get { return _blurIntensity; } set { _blurIntensity = value; } } + public BlurDirections blurDirections { get { return _blurDirections; } set { _blurDirections = value; } } + + [SerializeField] private string _name; + [SerializeField] private float _fillAlpha; + [SerializeField] private int _downsampleFactor; + [SerializeField] private int _iterations; + [SerializeField] private float _blurMinSpread; + [SerializeField] private float _blurSpread; + [SerializeField] private float _blurIntensity; + [SerializeField] private BlurDirections _blurDirections; + + #region IEquatable implementation + // + bool IEquatable.Equals(HighlightingPreset other) + { + return + _name == other._name && + _fillAlpha == other._fillAlpha && + _downsampleFactor == other._downsampleFactor && + _iterations == other._iterations && + _blurMinSpread == other._blurMinSpread && + _blurSpread == other._blurSpread && + _blurIntensity == other._blurIntensity && + _blurDirections == other._blurDirections; + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs.meta new file mode 100644 index 00000000..4357a1df --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/HighlightingPreset.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bf36fd3853ef7584bb8c13c22fff962e +timeCreated: 1480207882 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs new file mode 100644 index 00000000..4067542b --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs @@ -0,0 +1,16 @@ +using System; +using UnityEngine; + +namespace HighlightingSystem +{ + [UnityEngine.Internal.ExcludeFromDocs] + static public class MaterialExtensions + { + // Helper method to enable or disable keyword on material + static public void SetKeyword(this Material material, string keyword, bool state) + { + if (state) { material.EnableKeyword(keyword); } + else { material.DisableKeyword(keyword); } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs.meta new file mode 100644 index 00000000..eaab6165 --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/MaterialExtensions.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: f2b5d57c66061e548b250a8d44c4f43a +timeCreated: 1521664113 +licenseType: Store +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs b/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs new file mode 100644 index 00000000..133f2dbe --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs @@ -0,0 +1,24 @@ +using UnityEngine; +using System.Collections; + +namespace HighlightingSystem +{ + // Shader property ID cached constants + [UnityEngine.Internal.ExcludeFromDocs] + public class ShaderPropertyID + { + // Common + static public readonly int _MainTex = Shader.PropertyToID("_MainTex"); + static public readonly int _Cutoff = Shader.PropertyToID("_Cutoff"); + + static public readonly int _HighlightingIntensity = Shader.PropertyToID("_HighlightingIntensity"); + static public readonly int _HighlightingCull = Shader.PropertyToID("_HighlightingCull"); + static public readonly int _HighlightingColor = Shader.PropertyToID("_HighlightingColor"); + static public readonly int _HighlightingBlurOffset = Shader.PropertyToID("_HighlightingBlurOffset"); + static public readonly int _HighlightingFillAlpha = Shader.PropertyToID("_HighlightingFillAlpha"); + + static public readonly int _HighlightingBuffer = Shader.PropertyToID("_HighlightingBuffer"); + static public readonly int _HighlightingBlur1 = Shader.PropertyToID("_HighlightingBlur1"); + static public readonly int _HighlightingBlur2 = Shader.PropertyToID("_HighlightingBlur2"); + } +} \ No newline at end of file diff --git a/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs.meta b/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs.meta new file mode 100644 index 00000000..fcab021c --- /dev/null +++ b/Assets/Plugins/HighlightingSystem/Scripts/Internal/ShaderPropertyID.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bdf8fd90b69cf684cbbb8f6ec27bf953 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Zion/Scenes/AdamTraining_pilot_terminal_panl 1.unity b/Assets/Zion/Scenes/AdamTraining_pilot_terminal_panl 1.unity index ce3c71b0..20903e3a 100644 --- a/Assets/Zion/Scenes/AdamTraining_pilot_terminal_panl 1.unity +++ b/Assets/Zion/Scenes/AdamTraining_pilot_terminal_panl 1.unity @@ -930,6 +930,7 @@ GameObject: - component: {fileID: 90795400} - component: {fileID: 90795403} - component: {fileID: 90795404} + - component: {fileID: 90795405} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -980,7 +981,7 @@ Camera: m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 - m_TargetEye: 3 + m_TargetEye: 0 m_HDR: 1 m_AllowMSAA: 1 m_AllowDynamicResolution: 0 @@ -995,8 +996,8 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 90795399} - m_LocalRotation: {x: 0.19936788, y: 0, z: 0, w: 0.97992474} - m_LocalPosition: {x: -118, y: 163, z: -409} + m_LocalRotation: {x: 0.38686386, y: -0.10340534, z: 0.04370654, w: 0.91527784} + m_LocalPosition: {x: 114.28273, y: 305.18033, z: -95.789764} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1043,6 +1044,84 @@ MonoBehaviour: rotationLerpTime: 0.01 invertY: 0 --- !u!114 &90795404 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 90795399} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b765e0b5af3bcf4a9deb5895e477da8, type: 3} + m_Name: + m_EditorClassIdentifier: + _fillAlpha: 0 + _downsampleFactor: 4 + _iterations: 3 + _blurMinSpread: 0.65 + _blurSpread: 0.25 + _blurIntensity: 0.3 + _blurDirections: 0 + _blitter: {fileID: 0} + _antiAliasing: 0 + _presets: + - _name: Default + _fillAlpha: 0 + _downsampleFactor: 4 + _iterations: 2 + _blurMinSpread: 0.65 + _blurSpread: 0.25 + _blurIntensity: 0.3 + _blurDirections: 0 + - _name: Wide + _fillAlpha: 0 + _downsampleFactor: 4 + _iterations: 4 + _blurMinSpread: 0.65 + _blurSpread: 0.25 + _blurIntensity: 0.3 + _blurDirections: 0 + - _name: Strong + _fillAlpha: 0 + _downsampleFactor: 4 + _iterations: 2 + _blurMinSpread: 0.5 + _blurSpread: 0.15 + _blurIntensity: 0.325 + _blurDirections: 0 + - _name: Speed + _fillAlpha: 0 + _downsampleFactor: 4 + _iterations: 1 + _blurMinSpread: 0.75 + _blurSpread: 0 + _blurIntensity: 0.35 + _blurDirections: 0 + - _name: Quality + _fillAlpha: 0 + _downsampleFactor: 2 + _iterations: 3 + _blurMinSpread: 0.5 + _blurSpread: 0.5 + _blurIntensity: 0.28 + _blurDirections: 0 + - _name: Solid 1px + _fillAlpha: 0 + _downsampleFactor: 1 + _iterations: 1 + _blurMinSpread: 1 + _blurSpread: 0 + _blurIntensity: 1 + _blurDirections: 2 + - _name: Solid 2px + _fillAlpha: 0 + _downsampleFactor: 1 + _iterations: 2 + _blurMinSpread: 1 + _blurSpread: 0 + _blurIntensity: 1 + _blurDirections: 2 +--- !u!114 &90795405 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -1054,6 +1133,54 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3} m_Name: m_EditorClassIdentifier: + volumeTrigger: {fileID: 90795402} + volumeLayer: + serializedVersion: 2 + m_Bits: 256 + stopNaNPropagation: 1 + finalBlitToCameraTarget: 0 + antialiasingMode: 0 + temporalAntialiasing: + jitterSpread: 0.75 + sharpness: 0.25 + stationaryBlending: 0.95 + motionBlending: 0.85 + subpixelMorphologicalAntialiasing: + quality: 2 + fastApproximateAntialiasing: + fastMode: 0 + keepAlpha: 0 + fog: + enabled: 1 + excludeSkybox: 1 + debugLayer: + lightMeter: + width: 512 + height: 256 + showCurves: 1 + histogram: + width: 512 + height: 256 + channel: 3 + waveform: + exposure: 0.12 + height: 256 + vectorscope: + size: 256 + exposure: 0.12 + overlaySettings: + linearDepth: 0 + motionColorIntensity: 4 + motionGridSize: 64 + colorBlindnessType: 0 + colorBlindnessStrength: 1 + m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2} + m_ShowToolkit: 1 + m_ShowCustomSorter: 1 + breakBeforeColorGrading: 0 + m_BeforeTransparentBundles: [] + m_BeforeStackBundles: [] + m_AfterStackBundles: [] --- !u!1 &91360180 GameObject: m_ObjectHideFlags: 0 @@ -2265,7 +2392,9 @@ GameObject: - component: {fileID: 317830998} - component: {fileID: 317830999} - component: {fileID: 317831000} - m_Layer: 0 + - component: {fileID: 317831002} + - component: {fileID: 317831001} + m_Layer: 10 m_Name: "\u706B\u70AE (5)" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -2320,6 +2449,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 5.4, z: 2.93} m_Center: {x: 0, y: 2.74, z: 0} +--- !u!114 &317831001 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 317830997} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &317831002 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 317830997} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1 &335469898 GameObject: m_ObjectHideFlags: 0 @@ -2573,7 +2777,9 @@ GameObject: - component: {fileID: 354464464} - component: {fileID: 354464465} - component: {fileID: 354464466} - m_Layer: 0 + - component: {fileID: 354464468} + - component: {fileID: 354464467} + m_Layer: 10 m_Name: "\u706B\u70AE" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -2628,6 +2834,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 4.25, z: 2.93} m_Center: {x: 0, y: 3.1, z: 0} +--- !u!114 &354464467 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 354464463} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &354464468 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 354464463} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1 &386896060 GameObject: m_ObjectHideFlags: 0 @@ -2873,7 +3154,9 @@ GameObject: - component: {fileID: 468828551} - component: {fileID: 468828552} - component: {fileID: 468828553} - m_Layer: 0 + - component: {fileID: 468828555} + - component: {fileID: 468828554} + m_Layer: 10 m_Name: "\u706B\u70AE (3)" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -2928,6 +3211,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 5.23, z: 2.93} m_Center: {x: 0, y: 1.93, z: 0} +--- !u!114 &468828554 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 468828550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &468828555 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 468828550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1 &494165987 GameObject: m_ObjectHideFlags: 0 @@ -4120,7 +4478,7 @@ MonoBehaviour: m_PersistentCalls: m_Calls: - m_Target: {fileID: 1436809533} - m_MethodName: SetMove + m_MethodName: SetAttackTargetView m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -5681,7 +6039,9 @@ GameObject: - component: {fileID: 1089750760} - component: {fileID: 1089750761} - component: {fileID: 1089750762} - m_Layer: 0 + - component: {fileID: 1089750764} + - component: {fileID: 1089750763} + m_Layer: 10 m_Name: "\u706B\u70AE (1)" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -5736,6 +6096,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 5.34, z: 2.93} m_Center: {x: 0, y: 2.24, z: 0} +--- !u!114 &1089750763 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1089750759} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &1089750764 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1089750759} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!4 &1091286425 stripped Transform: m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 5072bfb20a3d05f43b9c99152a5860ad, @@ -5753,7 +6188,9 @@ GameObject: - component: {fileID: 1095573349} - component: {fileID: 1095573350} - component: {fileID: 1095573351} - m_Layer: 0 + - component: {fileID: 1095573353} + - component: {fileID: 1095573352} + m_Layer: 10 m_Name: "\u706B\u70AE (4)" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -5808,6 +6245,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 4.99, z: 2.93} m_Center: {x: 0, y: 1.97, z: 0} +--- !u!114 &1095573352 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1095573348} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &1095573353 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1095573348} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1 &1113159740 GameObject: m_ObjectHideFlags: 0 @@ -6742,6 +7254,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b94a2969b398cb44cb3031e8cdf455e1, type: 3} m_Name: m_EditorClassIdentifier: + wRJControllers: [] currentWRJ: {fileID: 0} wrjMenuSetPanel: {fileID: 1703180990} canvasRect: {fileID: 147647011} @@ -6795,7 +7308,7 @@ MonoBehaviour: simpleCameraController: {fileID: 90795403} wrjManager: {fileID: 1436809531} buleInstruct: {fileID: 125837377} - lines: [] + instructs: [] isDistance: 1 --- !u!1 &1444599844 GameObject: @@ -10575,7 +11088,9 @@ GameObject: - component: {fileID: 2101056906} - component: {fileID: 2101056907} - component: {fileID: 2101056908} - m_Layer: 0 + - component: {fileID: 2101056910} + - component: {fileID: 2101056909} + m_Layer: 10 m_Name: "\u706B\u70AE (2)" m_TagString: Untagged m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} @@ -10630,6 +11145,81 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 3.64, y: 6.44, z: 2.93} m_Center: {x: 0, y: 3.1, z: 0} +--- !u!114 &2101056909 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2101056905} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67d4de287b46eb34e83a61e4f9115070, type: 3} + m_Name: + m_EditorClassIdentifier: + mode: 0 + forceRender: 0 + color: {r: 1, g: 1, b: 1, a: 1} + _overlay: 0 + _occluder: 0 + _tween: 0 + _tweenGradient: + serializedVersion: 2 + key0: {r: 0, g: 1, b: 1, a: 0} + key1: {r: 0, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + _tweenDuration: 1 + _tweenReverse: 0 + _tweenLoop: 2 + _tweenEasing: 0 + _tweenDelay: 0 + _tweenRepeatCount: -1 + _tweenUseUnscaledTime: 0 + _constant: 0 + _constantColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1} + _constantFadeInTime: 0.1 + _constantFadeOutTime: 0.25 + _constantEasing: 0 + _constantUseUnscaledTime: 0 + _filterMode: 0 + _filterList: [] +--- !u!114 &2101056910 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2101056905} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e7de33601c65ad84eac6d63477030d3d, type: 3} + m_Name: + m_EditorClassIdentifier: + selfHighlight: {fileID: 0} --- !u!1 &2128163974 GameObject: m_ObjectHideFlags: 0 @@ -10880,7 +11470,7 @@ GameObject: m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 - m_StaticEditorFlags: 4294967295 + m_StaticEditorFlags: 0 m_IsActive: 1 --- !u!4 &4900298106786792354 Transform: @@ -11098,6 +11688,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3} m_Name: m_EditorClassIdentifier: + sharedProfile: {fileID: 11400000, guid: f7cb712597617514a8ed7f910f4d495d, type: 2} + isGlobal: 1 + blendDistance: 0 + weight: 1 + priority: 0 --- !u!1 &4900298107543512938 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Zion/Scripts/Adam/Components/BulletController.cs b/Assets/Zion/Scripts/Adam/Components/BulletController.cs index f53f6862..b23ac9f9 100644 --- a/Assets/Zion/Scripts/Adam/Components/BulletController.cs +++ b/Assets/Zion/Scripts/Adam/Components/BulletController.cs @@ -7,6 +7,7 @@ public class BulletController : MonoBehaviour public bool isMove = false; public bool isWRJFire = false; public GameObject boom; + public HuoPaoController huoPaoController; // Start is called before the first frame update void Start() { @@ -17,7 +18,7 @@ public class BulletController : MonoBehaviour void Update() { if (isMove) - transform.Translate(transform.forward * Time.deltaTime * 30f, Space.World); + transform.Translate(transform.forward * Time.deltaTime * 70f, Space.World); } public void SetBoolIsMove() { @@ -47,6 +48,9 @@ public class BulletController : MonoBehaviour } else { + huoPaoController.wrjs.Remove(other.collider.gameObject); + Destroy(other.collider.gameObject); + Debug.Log("无人机被消灭干净"); } Destroy(gameObject); diff --git a/Assets/Zion/Scripts/Adam/Components/On3DClick.cs b/Assets/Zion/Scripts/Adam/Components/On3DClick.cs new file mode 100644 index 00000000..decf5eca --- /dev/null +++ b/Assets/Zion/Scripts/Adam/Components/On3DClick.cs @@ -0,0 +1,31 @@ +using HighlightingSystem; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class On3DClick : MonoBehaviour +{ + public Highlighter selfHighlight; + // Start is called before the first frame update + void Start() + { + selfHighlight = GetComponent(); + } + + // Update is called once per frame + void Update() + { + + } + private void OnMouseEnter() + { + selfHighlight.ConstantOn(Color.green); + Debug.Log("OnMouseEnter"); + } + + private void OnMouseExit() + { + selfHighlight.ConstantOff(); + Debug.Log("OnMouseExit"); + } +} diff --git a/Assets/Zion/Scripts/Adam/Components/On3DClick.cs.meta b/Assets/Zion/Scripts/Adam/Components/On3DClick.cs.meta new file mode 100644 index 00000000..5e5d471d --- /dev/null +++ b/Assets/Zion/Scripts/Adam/Components/On3DClick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7de33601c65ad84eac6d63477030d3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Zion/Scripts/Adam/FiniteStateMachines/DrawingState.cs b/Assets/Zion/Scripts/Adam/FiniteStateMachines/DrawingState.cs index 2c72ecb7..de4f49d5 100644 --- a/Assets/Zion/Scripts/Adam/FiniteStateMachines/DrawingState.cs +++ b/Assets/Zion/Scripts/Adam/FiniteStateMachines/DrawingState.cs @@ -38,6 +38,7 @@ namespace Umawerse.FiniteStateMachines { OnDoubleTap(); }); + root.tapGesture.SetLayerMask(1<<8); Init(); } @@ -71,7 +72,7 @@ namespace Umawerse.FiniteStateMachines { vertices = new List(); target = new GameObject($"{name}_{Time.frameCount:D5}"); - root.lines.Add(target); + root.instructs.Add(target); } public abstract void Complete(); diff --git a/Assets/Zion/Scripts/Adam/HuoPaoController.cs b/Assets/Zion/Scripts/Adam/HuoPaoController.cs index e0f3ea59..64c3a6e2 100644 --- a/Assets/Zion/Scripts/Adam/HuoPaoController.cs +++ b/Assets/Zion/Scripts/Adam/HuoPaoController.cs @@ -21,26 +21,30 @@ public class HuoPaoController : MonoBehaviour { for (int i = 0; i < wrjs.Count; i++) { - dis = Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition); - if (Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition) < limitDis) + if (wrjs[i] != null) { - if (wrj == null) - wrj = wrjs[i]; - return; - } - else - { - wrj = null; + dis = Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition); + if (Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition) < limitDis) + { + if (wrj == null) + { + wrj = wrjs[i]; + } + return; + } + else + { + wrj = null; + } } } } private void OnFire() { - if (wrj != null) { - if (wrj.transform.childCount == 0) + if (wrjs.Count == 0) { CancelInvoke("OnFire"); return; @@ -49,6 +53,7 @@ public class HuoPaoController : MonoBehaviour GameObject fire = Instantiate(firePrefab); fire.transform.eulerAngles = firePos.eulerAngles; fire.transform.position = firePos.position; + fire.GetComponent().huoPaoController = this; fire.GetComponent().SetBoolIsMove(); //fire.transform.LookAt(wrj.transform.localPosition); } diff --git a/Assets/Zion/Scripts/Adam/ToolsBootstrap.cs b/Assets/Zion/Scripts/Adam/ToolsBootstrap.cs index ba14657a..b8657133 100644 --- a/Assets/Zion/Scripts/Adam/ToolsBootstrap.cs +++ b/Assets/Zion/Scripts/Adam/ToolsBootstrap.cs @@ -21,7 +21,7 @@ public class ToolsBootstrap : MonoBehaviour public WRJManager wrjManager; public GameObject buleInstruct; - public List lines = new List(); + public List instructs = new List(); public bool isDistance = true; @@ -70,27 +70,41 @@ public class ToolsBootstrap : MonoBehaviour public void Switch2DModel(bool isActive) { - if (lines.Count == 0) return; - for (int i = 0; i < lines.Count; i++) + if (instructs.Count == 0) return; + for (int i = 0; i < instructs.Count; i++) { - if (lines[i].gameObject) - lines[i].gameObject.SetActive(isActive); + if (instructs[i].gameObject) + instructs[i].gameObject.SetActive(isActive); } } - public void SetMove() + public void SetAttackTargetView() { - for (int i = 0; i < wrjManager.wRJControllers.Count; i++) - { - wrjManager.wRJControllers[i].isMove = true; - } - //wrjManager.currentWRJ.isMove = true; + simpleCameraController.enabled = false; + mCamera.transform.position = new Vector3(114.282f, 305.2f, -95.7f); + mCamera.transform.eulerAngles = new Vector3(45.8f, -13f, 0f); + mCamera.orthographic = false; + tapGesture.SetLayerMask(1 << 10); + wrjManager.currentWRJ.isAuto = false; wrjManager.wrjMenuSetPanel.gameObject.SetActive(false); + simpleCameraController.enabled = true; } private void Update() { _fsm.Update(); + + if (Input.GetMouseButtonDown(0)) + { + if (tapGesture.HitTest().collider != null) + { + if (tapGesture.HitTest().collider.gameObject.layer == 10) + { + + wrjManager.currentWRJ.SetAttackTarget(tapGesture.HitTest().collider.gameObject.GetComponent()); + } + } + } } public void SwitchState(int indexState) @@ -118,6 +132,7 @@ public class ToolsBootstrap : MonoBehaviour isDistance = false; _fsm.SetState(StateName.line); SwitchSet2DMap(2); + wrjManager.currentWRJ.isAuto = true; wrjManager.wrjMenuSetPanel.gameObject.SetActive(false); } @@ -129,7 +144,7 @@ public class ToolsBootstrap : MonoBehaviour //wrjManager.currentWRJ.isMove = true; for (int i = 0; i < wrjManager.wRJControllers.Count; i++) { - wrjManager.wRJControllers[i].isMove = true; + wrjManager.wRJControllers[i].SetMove(); } } diff --git a/Assets/Zion/Scripts/Adam/WRJController.cs b/Assets/Zion/Scripts/Adam/WRJController.cs index 54a917cd..4ff17977 100644 --- a/Assets/Zion/Scripts/Adam/WRJController.cs +++ b/Assets/Zion/Scripts/Adam/WRJController.cs @@ -8,12 +8,15 @@ public class WRJController : MonoBehaviour public int index1 = 0; public float speed; public HuoPaoController[] huoPaoControllerList; + public List attackTarget = new List(); public bool isMove = false; public float dis; public float limitDis; public Transform firePos; public GameObject firePrefab; public bool isGoToPlace = false; + public bool isAuto = false; + public int fireCount; // Start is called before the first frame update void Start() { @@ -23,7 +26,7 @@ public class WRJController : MonoBehaviour // Update is called once per frame void Update() { - if (wayPoints.Count == 0) return; + if (isMove) { MoveToway1(); @@ -38,6 +41,9 @@ public class WRJController : MonoBehaviour public void MoveToway1() { + //if (isAuto) + //{ + if (wayPoints.Count == 0) return; if (index1 > wayPoints.Count - 1) { return; } transform.localPosition = Vector3.MoveTowards(transform.localPosition, wayPoints[index1], speed * Time.deltaTime); if (Vector3.Distance(wayPoints[index1], transform.localPosition) < 0.01f) @@ -51,34 +57,96 @@ public class WRJController : MonoBehaviour isMove = false; } } + //} + //else + //{ + // if (index1 > attackTarget.Count - 1) { return; } + // transform.localPosition = Vector3.MoveTowards(transform.localPosition, new Vector3(attackTarget[index1].transform.localPosition.x, attackTarget[index1].transform.localPosition.y + 180f, attackTarget[index1].transform.localPosition.z), speed * Time.deltaTime); + // if (Vector3.Distance(attackTarget[index1].transform.localPosition, transform.localPosition) < 0.01f) + // { + // index1++; + // if (index1 == attackTarget.Count) + // { + // transform.localPosition = attackTarget[index1 - 1].transform.localPosition; + // isGoToPlace = true; + // isMove = false; + // } + // } + //} } + + public void SetAttackTarget(HuoPaoController target) + { + if (!attackTarget.Contains(target)) + attackTarget.Add(target); + + } + + public void SetMove() + { + isMove = true; + if (!isAuto) + { + wayPoints.Clear(); + wayPoints.Add(new Vector3(-132.7299f, 149.0329f, -309.2459f)); + wayPoints.Add(new Vector3(-98.94415f, 188.4612f, -219.9548f)); + wayPoints.Add(new Vector3(-69.9848f, 212.5105f, -145.1433f)); + wayPoints.Add(new Vector3(-2.413391f, 201.8178f, -24.47968f)); + wayPoints.Add(new Vector3(48f, 191.4619f, 47f)); + } + } + public int currentHuoPaoIndex = 0; private void OnFire() { //for (int i = 0; i < huoPaoControllerList.Length; i++) //{ - if (currentHuoPaoIndex > huoPaoControllerList.Length - 1) + if (fireCount <= 0) return; + if (isAuto) { - CancelInvoke("OnFire"); - return; - } + if (currentHuoPaoIndex >= huoPaoControllerList.Length - 1) + { + CancelInvoke("OnFire"); + return; + } - if (huoPaoControllerList[currentHuoPaoIndex] == null) + if (huoPaoControllerList[currentHuoPaoIndex] == null) + { + currentHuoPaoIndex++; + } + + if (firePos != null) + { + firePos.LookAt(huoPaoControllerList[currentHuoPaoIndex].transform.position); + GameObject fire = Instantiate(firePrefab); + fire.transform.eulerAngles = firePos.eulerAngles; + fire.transform.position = firePos.position; + fire.GetComponent().SetBoolIsMove(); + } + } + else { - currentHuoPaoIndex++; - } + if (currentHuoPaoIndex >= attackTarget.Count - 1) + { + CancelInvoke("OnFire"); + return; + } - if (firePos != null) - { - firePos.LookAt(huoPaoControllerList[currentHuoPaoIndex].transform.position); - GameObject fire = Instantiate(firePrefab); - fire.transform.eulerAngles = firePos.eulerAngles; - fire.transform.position = firePos.position; - fire.GetComponent().SetBoolIsMove(); - } + if (attackTarget[currentHuoPaoIndex] == null) + { + currentHuoPaoIndex++; + } - //} - //fire.transform.LookAt(wrj.transform.localPosition); + if (firePos != null) + { + firePos.LookAt(attackTarget[currentHuoPaoIndex].transform.position); + GameObject fire = Instantiate(firePrefab); + fire.transform.eulerAngles = firePos.eulerAngles; + fire.transform.position = firePos.position; + fire.GetComponent().SetBoolIsMove(); + } + } + fireCount--; } } diff --git a/Assets/Zion/Scripts/Adam/WRJManager.cs b/Assets/Zion/Scripts/Adam/WRJManager.cs index 2ae7c2f3..cd3d12d9 100644 --- a/Assets/Zion/Scripts/Adam/WRJManager.cs +++ b/Assets/Zion/Scripts/Adam/WRJManager.cs @@ -13,6 +13,7 @@ namespace Assets.Zion.Scripts.Adam public WRJController currentWRJ; public RectTransform wrjMenuSetPanel; public RectTransform canvasRect; + private void Start() { wrjMenuSetPanel.gameObject.SetActive(false); @@ -28,7 +29,8 @@ namespace Assets.Zion.Scripts.Adam { Debug.Log("daadad"); currentWRJ = hitInfo.collider.GetComponent(); - wRJControllers.Add(currentWRJ); + if (!wRJControllers.Contains(currentWRJ)) + wRJControllers.Add(currentWRJ); wrjMenuSetPanel.gameObject.SetActive(true); Vector3 posItem = GetScreenPosition(hitInfo.collider.gameObject); wrjMenuSetPanel.anchoredPosition = new Vector3(posItem.x + 100f, posItem.y, posItem.z); @@ -38,6 +40,7 @@ namespace Assets.Zion.Scripts.Adam wrjMenuSetPanel.gameObject.SetActive(false); } } + } public Vector3 GetScreenPosition(GameObject target) diff --git a/Packages/manifest.json b/Packages/manifest.json index bf562352..0535134f 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,6 +3,7 @@ "com.unity.collab-proxy": "1.2.16", "com.unity.ide.rider": "1.1.4", "com.unity.ide.vscode": "1.2.1", + "com.unity.postprocessing": "2.3.0", "com.unity.test-framework": "1.1.16", "com.unity.textmeshpro": "2.1.1", "com.unity.timeline": "1.2.16", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 529ef347..cf0d9e13 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -30,6 +30,13 @@ "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.postprocessing": { + "version": "2.3.0", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, "com.unity.test-framework": { "version": "1.1.16", "depth": 0, diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index b295e1e8..d6af72ea 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -573,7 +573,19 @@ PlayerSettings: webGLLinkerTarget: 1 webGLThreadsSupport: 0 webGLWasmStreaming: 0 - scriptingDefineSymbols: {} + scriptingDefineSymbols: + 1: UNITY_POST_PROCESSING_STACK_V2 + 4: UNITY_POST_PROCESSING_STACK_V2 + 7: UNITY_POST_PROCESSING_STACK_V2 + 13: UNITY_POST_PROCESSING_STACK_V2 + 14: UNITY_POST_PROCESSING_STACK_V2 + 19: UNITY_POST_PROCESSING_STACK_V2 + 21: UNITY_POST_PROCESSING_STACK_V2 + 25: UNITY_POST_PROCESSING_STACK_V2 + 27: UNITY_POST_PROCESSING_STACK_V2 + 28: UNITY_POST_PROCESSING_STACK_V2 + 29: UNITY_POST_PROCESSING_STACK_V2 + 30: UNITY_POST_PROCESSING_STACK_V2 platformArchitecture: {} scriptingBackend: {} il2cppCompilerConfiguration: {} diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index b38e404e..d7947941 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -202,7 +202,7 @@ QualitySettings: textureQuality: 0 anisotropicTextures: 2 antiAliasing: 0 - softParticles: 1 + softParticles: 0 softVegetation: 1 realtimeReflectionProbes: 1 billboardsFaceCameraPosition: 1 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index a6305dbb..4b55f94e 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -14,9 +14,9 @@ TagManager: - UI - - - - - - - - + - Ground + - WRJ + - HuoPao - - -