From f9ba807cea1f5423ac628c384fe96f4c095fdc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Thu, 20 Jun 2024 14:45:14 +0200 Subject: [PATCH] Introduce IInteractorVisualizer and implement foundation for separating visualization from interactor logic (#132) * Define IInteractorVisualizer * Define BaseInteractorVisualizer * Begin setup of line interactor visualizer * Extract far interactor visualizer --- .../Interactors/FarInteractor.prefab | 515 +++++------------- .../LineInteractorVisualizer.prefab | 405 ++++++++++++++ .../LineInteractorVisualizer.prefab.meta | 7 + .../Interactors/BaseControllerInteractor.cs | 39 +- .../Interactors/BaseInteractorVisualizer.cs | 19 + .../BaseInteractorVisualizer.cs.meta | 11 + Runtime/Input/Interactors/FarInteractor.cs | 194 +------ Runtime/Input/Interactors/GenericPointer.cs | 3 + Runtime/Input/Interactors/IInteractor.cs | 5 + .../Interactors/IInteractorVisualizer.cs | 23 + .../Interactors/IInteractorVisualizer.cs.meta | 11 + .../Interactors/LineInteractorVisualizer.cs | 201 +++++++ .../LineInteractorVisualizer.cs.meta | 11 + .../Icons/Icon_Toolkit_Component.png | Bin 3218 -> 1435 bytes .../Lines/Modules/BaseLineDataProvider.cs | 3 +- ...{LineRenderer.cs => SimpleLineRenderer.cs} | 2 +- ...rer.cs.meta => SimpleLineRenderer.cs.meta} | 0 17 files changed, 889 insertions(+), 560 deletions(-) create mode 100644 Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab create mode 100644 Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab.meta create mode 100644 Runtime/Input/Interactors/BaseInteractorVisualizer.cs create mode 100644 Runtime/Input/Interactors/BaseInteractorVisualizer.cs.meta create mode 100644 Runtime/Input/Interactors/IInteractorVisualizer.cs create mode 100644 Runtime/Input/Interactors/IInteractorVisualizer.cs.meta create mode 100644 Runtime/Input/Interactors/LineInteractorVisualizer.cs create mode 100644 Runtime/Input/Interactors/LineInteractorVisualizer.cs.meta rename Runtime/Utilities/Lines/Renderers/{LineRenderer.cs => SimpleLineRenderer.cs} (98%) rename Runtime/Utilities/Lines/Renderers/{LineRenderer.cs.meta => SimpleLineRenderer.cs.meta} (100%) diff --git a/Assets~/StandardAssets/Interactors/FarInteractor.prefab b/Assets~/StandardAssets/Interactors/FarInteractor.prefab index f17e876de..2493a3c29 100644 --- a/Assets~/StandardAssets/Interactors/FarInteractor.prefab +++ b/Assets~/StandardAssets/Interactors/FarInteractor.prefab @@ -9,11 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 4215223911988956} - - component: {fileID: 6863193991115524521} - - component: {fileID: 1307499967629831868} - component: {fileID: 2507312044101632756} - - component: {fileID: 3080660041806603478} - - component: {fileID: 1526809385130449531} m_Layer: 0 m_Name: FarInteractor m_TagString: Untagged @@ -33,116 +29,10 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: [] + m_Children: + - {fileID: 6171776694493889091} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &6863193991115524521 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1247086986094436} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c85a4527bbdd25647a62ec06e8d2daf3, type: 3} - m_Name: - m_EditorClassIdentifier: - lineStartClamp: 0.0001 - lineEndClamp: 0.9999 - customLineTransform: {fileID: 0} - loops: 0 - transformMode: 1 - rotationMode: 1 - flipUpVector: 0 - originOffset: {x: 0, y: 0, z: 0} - manualUpVectorBlend: 0 - manualUpVectors: - - {x: 0, y: 1, z: 0} - - {x: 0, y: 1, z: 0} - - {x: 0, y: 1, z: 0} - velocitySearchRange: 0.02 - distorters: - - {fileID: 1307499967629831868} - distortionMode: 0 - distortionStrength: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - - serializedVersion: 3 - time: 1 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - uniformDistortionStrength: 1 - inertia: - inertia: 10 - dampen: 6 - seekTargetStrength: 1.5 - p1Target: {x: 0, y: 0, z: 0.33} - p2Target: {x: 0, y: 0, z: 0.66} - controlPoints: - Point1: {x: 0, y: 0, z: 0} - Point2: {x: 0, y: 0, z: 0.33} - Point3: {x: 0, y: 0, z: 0.66} - Point4: {x: 0, y: 0, z: 1} - useLocalTangentPoints: 0 ---- !u!114 &1307499967629831868 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1247086986094436} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 61988acbae5840069797ec6d990d8f50, type: 3} - m_Name: - m_EditorClassIdentifier: - distortOrder: 0 - distortStrength: 1 - localCenterOfGravity: {x: 0, y: 0, z: 0} - axisStrength: {x: 1, y: 1, z: 1} - radius: 0.5 - gravityStrength: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - - serializedVersion: 3 - time: 1 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 --- !u!114 &2507312044101632756 MonoBehaviour: m_ObjectHideFlags: 0 @@ -184,12 +74,12 @@ MonoBehaviour: axisConstraint: 2 requiresHoldAction: 0 enablePointerOnStart: 0 - defaultPointerExtent: 10 - overrideGlobalPointerExtent: 0 + defaultExtent: 10 pointerOrientation: 0 cursorPrefab: {fileID: 1000012072213228, guid: 79f96834fcc44889b558cc13518979a0, type: 3} disableCursorOnStart: 0 setCursorVisibilityOnSourceDetected: 0 + visualizer: {fileID: 3439845260210020345} defaultLineColor: serializedVersion: 2 key0: {r: 1, g: 1, b: 1, a: 1} @@ -250,266 +140,157 @@ MonoBehaviour: m_ColorSpace: -1 m_NumColorKeys: 2 m_NumAlphaKeys: 4 - lineColorLockFocus: - serializedVersion: 2 - key0: {r: 0, g: 0.9806142, b: 1, a: 0} - key1: {r: 0, g: 0.9806142, b: 1, a: 1} - key2: {r: 0, g: 0, b: 0, a: 1} - 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: 3277 - atime2: 49151 - atime3: 65535 - atime4: 0 - atime5: 0 - atime6: 0 - atime7: 0 - m_Mode: 0 - m_ColorSpace: -1 - m_NumColorKeys: 2 - m_NumAlphaKeys: 4 lineCastResolution: 2 - lineBase: {fileID: 6863193991115524521} + lineBase: {fileID: 0} lineRenderers: - - {fileID: 1526809385130449531} ---- !u!120 &3080660041806603478 -LineRenderer: - serializedVersion: 2 + - {fileID: 0} +--- !u!1001 &5787600513285177455 +PrefabInstance: m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1247086986094436} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 0 - m_StaticShadowCaster: 0 - m_MotionVectors: 0 - m_LightProbeUsage: 0 - m_ReflectionProbeUsage: 0 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 49bbec7a7ebd47c786bf06ad0977ec1c, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Positions: - - {x: 0, y: 0, z: 0.00009899999} - - {x: 0, y: 0, z: 0.06608878} - - {x: 0, y: 0, z: 0.13209635} - - {x: 0, y: 0, z: 0.19813946} - - {x: 0, y: 0, z: 0.26423594} - - {x: 0, y: 0, z: 0.3304035} - - {x: 0, y: 0, z: 0.3966599} - - {x: 0, y: 0, z: 0.46302295} - - {x: 0, y: 0, z: 0.52951044} - - {x: 0, y: 0, z: 0.59614} - - {x: 0, y: 0, z: 0.66292953} - - {x: 0, y: 0, z: 0.7298968} - - {x: 0, y: 0, z: 0.7970595} - - {x: 0, y: 0, z: 0.8644354} - - {x: 0, y: 0, z: 0.93204236} - - {x: 0, y: 0, z: 0.999898} - m_Parameters: + serializedVersion: 2 + m_Modification: serializedVersion: 3 - widthMultiplier: 0.01 - widthCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0.2 - inSlope: 0 - outSlope: 0 - tangentMode: 34 - weightedMode: 0 - inWeight: 0 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0.2 - inSlope: 0 - outSlope: 0 - tangentMode: 34 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - colorGradient: - serializedVersion: 2 - key0: {r: 1, g: 1, b: 1, a: 0} - key1: {r: 0.4716981, g: 0.4716981, b: 0.4716981, a: 1} - key2: {r: 0, g: 0, b: 0, a: 1} - key3: {r: 0, g: 0, b: 0, a: 0} - key4: {r: 0, g: 0, b: 0, a: 1} - 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: 9638 - atime2: 53970 - atime3: 65535 - atime4: 65535 - atime5: 0 - atime6: 0 - atime7: 0 - m_Mode: 0 - m_ColorSpace: -1 - m_NumColorKeys: 2 - m_NumAlphaKeys: 4 - numCornerVertices: 8 - numCapVertices: 8 - alignment: 0 - textureMode: 3 - textureScale: {x: 1, y: 1} - shadowBias: 0 - generateLightingData: 0 - m_MaskInteraction: 0 - m_UseWorldSpace: 1 - m_Loop: 0 - m_ApplyActiveColorSpace: 0 ---- !u!114 &1526809385130449531 + m_TransformParent: {fileID: 4215223911988956} + m_Modifications: + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[0].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[1].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[2].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[3].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[4].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[5].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[6].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[7].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[8].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[9].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[10].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[11].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[12].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[13].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[14].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Positions.Array.data[15].x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1916914663512385553, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: lineRenderer + value: + objectReference: {fileID: 5891292137490381271} + - target: {fileID: 7427600337792499737, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + propertyPath: m_Name + value: LineInteractorVisualizer + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} +--- !u!114 &3439845260210020345 stripped MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} + m_CorrespondingSourceObject: {fileID: 9218157099259420566, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + m_PrefabInstance: {fileID: 5787600513285177455} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1247086986094436} + m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 01f6e868e3234547a04741fe2c20bd0d, type: 3} + m_Script: {fileID: 11500000, guid: a0c2a07ed1df1094ba9ac469febef61e, type: 3} m_Name: m_EditorClassIdentifier: - lineDataSource: {fileID: 6863193991115524521} - lineColor: - serializedVersion: 2 - key0: {r: 1, g: 1, b: 1, a: 0} - key1: {r: 0.4716981, g: 0.4716981, b: 0.4716981, a: 1} - key2: {r: 0, g: 0, b: 0, a: 1} - key3: {r: 0, g: 0, b: 0, a: 0} - key4: {r: 0, g: 0, b: 0, a: 1} - 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: 9638 - atime2: 53970 - atime3: 65535 - atime4: 65535 - atime5: 0 - atime6: 0 - atime7: 0 - m_Mode: 0 - m_ColorSpace: -1 - m_NumColorKeys: 2 - m_NumAlphaKeys: 4 - lineWidth: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0.2 - inSlope: 0 - outSlope: 0 - tangentMode: 34 - weightedMode: 0 - inWeight: 0 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0.2 - inSlope: 0 - outSlope: 0 - tangentMode: 34 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - widthMultiplier: 0.01 - colorOffset: 0 - widthOffset: 0 - stepMode: 0 - lineStepCount: 16 - pointDistributionMode: 1 - customPointDistributionLength: 0.1 - customPointDistributionCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 1 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - - serializedVersion: 3 - time: 1 - value: 1 - inSlope: 1 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - lineMaterial: {fileID: 2100000, guid: 49bbec7a7ebd47c786bf06ad0977ec1c, type: 2} - roundedEdges: 1 - roundedCaps: 1 - lineRenderer: {fileID: 3080660041806603478} +--- !u!120 &5891292137490381271 stripped +LineRenderer: + m_CorrespondingSourceObject: {fileID: 113613622773627320, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + m_PrefabInstance: {fileID: 5787600513285177455} + m_PrefabAsset: {fileID: 0} +--- !u!4 &6171776694493889091 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 429880686731362860, guid: e3c48e7e7941d6040a48334d313ce0c2, type: 3} + m_PrefabInstance: {fileID: 5787600513285177455} + m_PrefabAsset: {fileID: 0} diff --git a/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab b/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab new file mode 100644 index 000000000..5e9bddb8f --- /dev/null +++ b/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab @@ -0,0 +1,405 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7427600337792499737 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 429880686731362860} + - component: {fileID: 9218157099259420566} + - component: {fileID: 4233110557611249510} + - component: {fileID: 113613622773627320} + - component: {fileID: 1916914663512385553} + m_Layer: 0 + m_Name: LineInteractorVisualizer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &429880686731362860 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7427600337792499737} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &9218157099259420566 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7427600337792499737} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a0c2a07ed1df1094ba9ac469febef61e, type: 3} + m_Name: + m_EditorClassIdentifier: + lineBase: {fileID: 4233110557611249510} + defaultLineColor: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 1} + key1: {r: 1, 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_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + lineColorInputDown: + serializedVersion: 2 + key0: {r: 0, g: 0.9806142, b: 1, a: 0} + key1: {r: 0, g: 0.9806142, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 1} + 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: 3277 + atime2: 49151 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 4 + lineCastResolution: 2 +--- !u!114 &4233110557611249510 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7427600337792499737} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c85a4527bbdd25647a62ec06e8d2daf3, type: 3} + m_Name: + m_EditorClassIdentifier: + lineStartClamp: 0.0001 + lineEndClamp: 0.9999 + customLineTransform: {fileID: 0} + loops: 0 + transformMode: 1 + rotationMode: 1 + flipUpVector: 0 + originOffset: {x: 0, y: 0, z: 0} + manualUpVectorBlend: 0 + manualUpVectors: + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + velocitySearchRange: 0.02 + distorters: [] + distortionMode: 0 + distortionStrength: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + uniformDistortionStrength: 1 + inertia: + inertia: 10 + dampen: 6 + seekTargetStrength: 1.5 + p1Target: {x: 0, y: 0, z: 0.33} + p2Target: {x: 0, y: 0, z: 0.66} + controlPoints: + Point1: {x: 0, y: 0, z: 0} + Point2: {x: 0, y: 0, z: 0.33} + Point3: {x: 0, y: 0, z: 0.66} + Point4: {x: 0, y: 0, z: 1} + useLocalTangentPoints: 0 +--- !u!120 &113613622773627320 +LineRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7427600337792499737} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 0 + m_StaticShadowCaster: 0 + m_MotionVectors: 0 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 49bbec7a7ebd47c786bf06ad0977ec1c, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Positions: + - {x: 0, y: 0, z: 0.00009899999} + - {x: 0, y: 0, z: 0.06608878} + - {x: 0, y: 0, z: 0.13209635} + - {x: 0, y: 0, z: 0.19813946} + - {x: 0, y: 0, z: 0.26423594} + - {x: 0, y: 0, z: 0.3304035} + - {x: 0, y: 0, z: 0.3966599} + - {x: 0, y: 0, z: 0.46302295} + - {x: 0, y: 0, z: 0.52951044} + - {x: 0, y: 0, z: 0.59614} + - {x: 0, y: 0, z: 0.66292953} + - {x: 0, y: 0, z: 0.7298968} + - {x: 0, y: 0, z: 0.7970595} + - {x: 0, y: 0, z: 0.8644354} + - {x: 0, y: 0, z: 0.93204236} + - {x: 0, y: 0, z: 0.999898} + m_Parameters: + serializedVersion: 3 + widthMultiplier: 0.01 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0.2 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0.2 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 0} + key1: {r: 0.4716981, g: 0.4716981, b: 0.4716981, a: 1} + key2: {r: 0, g: 0, b: 0, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 1} + 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: 9638 + atime2: 53970 + atime3: 65535 + atime4: 65535 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 4 + numCornerVertices: 8 + numCapVertices: 8 + alignment: 0 + textureMode: 3 + textureScale: {x: 1, y: 1} + shadowBias: 0 + generateLightingData: 0 + m_MaskInteraction: 0 + m_UseWorldSpace: 1 + m_Loop: 0 + m_ApplyActiveColorSpace: 0 +--- !u!114 &1916914663512385553 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7427600337792499737} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 01f6e868e3234547a04741fe2c20bd0d, type: 3} + m_Name: + m_EditorClassIdentifier: + lineDataSource: {fileID: 4233110557611249510} + lineColor: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 0} + key1: {r: 0.4716981, g: 0.4716981, b: 0.4716981, a: 1} + key2: {r: 0, g: 0, b: 0, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 1} + 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: 9638 + atime2: 53970 + atime3: 65535 + atime4: 65535 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 4 + lineWidth: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0.2 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0.2 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + widthMultiplier: 0.01 + colorOffset: 0 + widthOffset: 0 + stepMode: 0 + lineStepCount: 16 + pointDistributionMode: 1 + customPointDistributionLength: 0.1 + customPointDistributionCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 1 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 1 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + lineMaterial: {fileID: 2100000, guid: 49bbec7a7ebd47c786bf06ad0977ec1c, type: 2} + roundedEdges: 1 + roundedCaps: 1 + lineRenderer: {fileID: 113613622773627320} diff --git a/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab.meta b/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab.meta new file mode 100644 index 000000000..09d13b37a --- /dev/null +++ b/Assets~/StandardAssets/Interactors/LineInteractorVisualizer.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e3c48e7e7941d6040a48334d313ce0c2 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Input/Interactors/BaseControllerInteractor.cs b/Runtime/Input/Interactors/BaseControllerInteractor.cs index c0f7170a6..07791a6f4 100644 --- a/Runtime/Input/Interactors/BaseControllerInteractor.cs +++ b/Runtime/Input/Interactors/BaseControllerInteractor.cs @@ -70,6 +70,9 @@ public abstract class BaseControllerInteractor : ControllerPoseSynchronizer, ICo [SerializeField] private bool setCursorVisibilityOnSourceDetected = false; + [SerializeField] + private BaseInteractorVisualizer visualizer = null; + private GameObject cursorInstance = null; private Vector3 lastPointerPosition = Vector3.zero; private readonly List inputDownActions = new List(); @@ -91,10 +94,8 @@ public abstract class BaseControllerInteractor : ControllerPoseSynchronizer, ICo /// protected bool IsSelectPressed { get; set; } = false; - /// - /// true, if any is down on this . - /// - protected bool IsInputDown => inputDownActions.Count > 0; + /// + public bool IsInputDown => inputDownActions.Count > 0; /// /// True if select has been pressed once since this component was enabled @@ -384,6 +385,11 @@ protected override void Start() { base.Start(); SetCursor(); + + if (visualizer.IsNotNull()) + { + visualizer.Interactor = this; + } } /// @@ -419,12 +425,34 @@ protected override void OnDisable() } } + /// + protected override void OnDestroy() + { + if (visualizer.IsNotNull()) + { + visualizer.gameObject.Destroy(); + } + + base.OnDestroy(); + } + /// - public virtual void OnPreRaycast() { } + public virtual void OnPreRaycast() + { + if (visualizer.IsNotNull()) + { + visualizer.OnPreRaycast(); + } + } /// public virtual void OnPostRaycast() { + if (visualizer.IsNotNull()) + { + visualizer.OnPostRaycast(); + } + if (grabAction != InputAction.None) { if (IsGrabPressed) @@ -437,7 +465,6 @@ public virtual void OnPostRaycast() if (IsSelectPressed) { DragHandler(pointerAction); - } } } diff --git a/Runtime/Input/Interactors/BaseInteractorVisualizer.cs b/Runtime/Input/Interactors/BaseInteractorVisualizer.cs new file mode 100644 index 000000000..ba954fe7d --- /dev/null +++ b/Runtime/Input/Interactors/BaseInteractorVisualizer.cs @@ -0,0 +1,19 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace RealityToolkit.Input.Interactors +{ + public abstract class BaseInteractorVisualizer : MonoBehaviour, IInteractorVisualizer + { + /// + public virtual IInteractor Interactor { get; set; } + + /// + public virtual void OnPreRaycast() { } + + /// + public virtual void OnPostRaycast() { } + } +} diff --git a/Runtime/Input/Interactors/BaseInteractorVisualizer.cs.meta b/Runtime/Input/Interactors/BaseInteractorVisualizer.cs.meta new file mode 100644 index 000000000..0d0c07fdc --- /dev/null +++ b/Runtime/Input/Interactors/BaseInteractorVisualizer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e18166d6b36f9c4caed1956439f73cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 08c0fd91bdca45afa09ec64323cf3848, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Input/Interactors/FarInteractor.cs b/Runtime/Input/Interactors/FarInteractor.cs index cd2d14366..7401a97d4 100644 --- a/Runtime/Input/Interactors/FarInteractor.cs +++ b/Runtime/Input/Interactors/FarInteractor.cs @@ -2,167 +2,45 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using RealityToolkit.Definitions.Physics; -using RealityToolkit.Utilities.Lines.DataProviders; -using RealityToolkit.Utilities.Lines.Renderers; using UnityEngine; -using UnityEngine.Serialization; namespace RealityToolkit.Input.Interactors { /// /// A simple line pointer for drawing lines from the input source origin to the current pointer position. /// + [AddComponentMenu("")] public class FarInteractor : BaseControllerInteractor { - [SerializeField] - private Gradient defaultLineColor = new Gradient(); - - protected Gradient DefaultLineColor - { - get => defaultLineColor; - set => defaultLineColor = value; - } - - [SerializeField] - private Gradient lineColorInputDown = new Gradient(); - - protected Gradient LineColorInputDown - { - get => lineColorInputDown; - set => lineColorInputDown = value; - } - [Range(2, 50)] [SerializeField] - [FormerlySerializedAs("LineCastResolution")] [Tooltip("This setting has a high performance cost. Values above 20 are not recommended.")] - private int lineCastResolution = 10; - - protected int LineCastResolution - { - get => lineCastResolution; - set => lineCastResolution = value; - } - - [SerializeField] - private BaseLineDataProvider lineBase; - - /// - /// The Line Data Provider driving this pointer. - /// - public BaseLineDataProvider LineBase => lineBase; - - [SerializeField] - [Tooltip("If no line renderers are specified, this array will be auto-populated on startup.")] - private BaseLineRenderer[] lineRenderers; + private int lineCastResolution = 2; /// - /// The current line renderers that this pointer is utilizing. + /// The amount of rays to cast. /// /// - /// If no line renderers are specified, this array will be auto-populated on startup. + /// This setting has a high performance cost. Values above 20 are not recommended. /// - public BaseLineRenderer[] LineRenderers + public int LineCastResolution { - get => lineRenderers; - set => lineRenderers = value; + get => lineCastResolution; + set => lineCastResolution = value; } /// public override bool IsFarInteractor => true; - private void CheckInitialization() - { - if (lineBase == null) - { - lineBase = GetComponent(); - } - - if (lineBase == null) - { - Debug.LogError($"No Mixed Reality Line Data Provider found on {gameObject.name}. Did you forget to add a Line Data provider?"); - } - - if (lineBase != null && (lineRenderers == null || lineRenderers.Length == 0)) - { - lineRenderers = lineBase.GetComponentsInChildren(); - } - - if (lineRenderers == null || lineRenderers.Length == 0) - { - Debug.LogError($"No Mixed Reality Line Renderers found on {gameObject.name}. Did you forget to add a Mixed Reality Line Renderer?"); - } - } - - #region MonoBehaviour Implementation - - protected virtual void OnValidate() - { - CheckInitialization(); - } - - protected override void OnEnable() - { - base.OnEnable(); - CheckInitialization(); - } - - #endregion MonoBehaviour Implementation - - #region IPointer Implementation - - /// public override void OnPreRaycast() { - Debug.Assert(lineBase != null); - - lineBase.UpdateMatrix(); - - if (RayStabilizer != null) - { - RayStabilizer.UpdateStability(Rays[0].Origin, Rays[0].Direction); - Rays[0].CopyRay(RayStabilizer.StableRay, Extent); - } - - TryGetPointerPosition(out var pointerPosition); - TryGetPointerRotation(out var pointerRotation); - - // Set our first and last points - lineBase.FirstPoint = pointerPosition; - - if (IsFocusLocked && Result.CurrentTarget != null) - { - if (SyncedTarget != null) - { - // Now raycast out like nothing happened so we can get an updated pointer position. - lineBase.LastPoint = pointerPosition + pointerRotation * (Vector3.forward * Extent); - } - else - { - // Set the line to the locked position. - lineBase.LastPoint = Result.EndPoint; - } - } - else - { - lineBase.LastPoint = pointerPosition + pointerRotation * (Vector3.forward * Extent); - } - // Make sure our array will hold if (Rays == null || Rays.Length != lineCastResolution) { Rays = new RayStep[lineCastResolution]; } - var stepSize = 1f / Rays.Length; - var lastPoint = lineBase.GetUnClampedPoint(0f); - - for (int i = 0; i < Rays.Length; i++) - { - var currentPoint = lineBase.GetUnClampedPoint(stepSize * (i + 1)); - Rays[i].UpdateRayStep(ref lastPoint, ref currentPoint); - lastPoint = currentPoint; - } + base.OnPreRaycast(); } /// @@ -170,8 +48,6 @@ public override void OnPostRaycast() { if (!IsInteractionEnabled) { - lineBase.enabled = false; - if (BaseCursor != null) { BaseCursor.IsVisible = false; @@ -180,64 +56,12 @@ public override void OnPostRaycast() return; } - base.OnPostRaycast(); - - Gradient lineColor; - - lineBase.enabled = true; - if (BaseCursor != null) { BaseCursor.IsVisible = true; } - // Used to ensure the line doesn't extend beyond the cursor - float cursorOffsetWorldLength = BaseCursor?.SurfaceCursorDistance ?? 0f; - - // The distance the ray travels through the world before it hits something. - // Measured in world-units (as opposed to normalized distance). - var clearWorldLength = (Result?.CurrentTarget != null) ? Result.RayDistance : Extent; - - lineColor = IsInputDown ? LineColorInputDown : DefaultLineColor; - - int maxClampLineSteps = lineCastResolution; - - for (var i = 0; i < lineRenderers.Length; i++) - { - var lineRenderer = lineRenderers[i]; - // Renderers are enabled by default if line is enabled - lineRenderer.enabled = true; - maxClampLineSteps = Mathf.Max(maxClampLineSteps, lineRenderer.LineStepCount); - lineRenderer.LineColor = lineColor; - } - - // If focus is locked, we're sticking to the target - // So don't clamp the world length - if (IsFocusLocked && Result.CurrentTarget != null) - { - if (SyncedTarget != null) - { - if (Result.GrabPoint == Vector3.zero) - { - LineBase.LastPoint = Result.EndPoint; - } - else - { - LineBase.LastPoint = Result.GrabPoint; - } - } - - float cursorOffsetLocalLength = LineBase.GetNormalizedLengthFromWorldLength(cursorOffsetWorldLength); - LineBase.LineEndClamp = 1 - cursorOffsetLocalLength; - } - else - { - // Otherwise clamp the line end by the clear distance - float clearLocalLength = lineBase.GetNormalizedLengthFromWorldLength(clearWorldLength - cursorOffsetWorldLength, maxClampLineSteps); - lineBase.LineEndClamp = clearLocalLength; - } + base.OnPostRaycast(); } - - #endregion IPointer Implementation } } \ No newline at end of file diff --git a/Runtime/Input/Interactors/GenericPointer.cs b/Runtime/Input/Interactors/GenericPointer.cs index 448a6473c..7f23ef5de 100644 --- a/Runtime/Input/Interactors/GenericPointer.cs +++ b/Runtime/Input/Interactors/GenericPointer.cs @@ -63,6 +63,9 @@ public virtual IController Controller /// public bool IsOverUI { get; } = false; + /// + public bool IsInputDown { get; private set; } + /// public virtual IInputSource InputSource { diff --git a/Runtime/Input/Interactors/IInteractor.cs b/Runtime/Input/Interactors/IInteractor.cs index fbc2ca9bb..e72225915 100644 --- a/Runtime/Input/Interactors/IInteractor.cs +++ b/Runtime/Input/Interactors/IInteractor.cs @@ -36,6 +36,11 @@ public interface IInteractor : IEqualityComparer /// bool IsFarInteractor { get; } + /// + /// true, if any is down on this . + /// + bool IsInputDown { get; } + /// /// This pointer's input source parent. /// diff --git a/Runtime/Input/Interactors/IInteractorVisualizer.cs b/Runtime/Input/Interactors/IInteractorVisualizer.cs new file mode 100644 index 000000000..d66cd6d5a --- /dev/null +++ b/Runtime/Input/Interactors/IInteractorVisualizer.cs @@ -0,0 +1,23 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace RealityToolkit.Input.Interactors +{ + public interface IInteractorVisualizer + { + /// + /// The visualized. + /// + IInteractor Interactor { get; } + + /// + /// Called before all rays have casted on the . + /// + void OnPreRaycast(); + + /// + /// Called after all rays have casted on the . + /// + void OnPostRaycast(); + } +} diff --git a/Runtime/Input/Interactors/IInteractorVisualizer.cs.meta b/Runtime/Input/Interactors/IInteractorVisualizer.cs.meta new file mode 100644 index 000000000..3b142ec1a --- /dev/null +++ b/Runtime/Input/Interactors/IInteractorVisualizer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2aeb3dbfa6dcc604ebdf5d641d8f657a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Input/Interactors/LineInteractorVisualizer.cs b/Runtime/Input/Interactors/LineInteractorVisualizer.cs new file mode 100644 index 000000000..b53d10fc6 --- /dev/null +++ b/Runtime/Input/Interactors/LineInteractorVisualizer.cs @@ -0,0 +1,201 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.Utilities.Extensions; +using RealityToolkit.Utilities.Lines.DataProviders; +using RealityToolkit.Utilities.Lines.Renderers; +using UnityEngine; + +namespace RealityToolkit.Input.Interactors +{ + public class LineInteractorVisualizer : BaseInteractorVisualizer + { + [SerializeField] + private BaseLineDataProvider lineBase = null; + + [SerializeField] + [Tooltip("If no line renderers are specified, this array will be auto-populated on startup.")] + private BaseLineRenderer[] lineRenderers = null; + + [SerializeField] + private Gradient defaultLineColor = new Gradient(); + + public Gradient DefaultLineColor + { + get => defaultLineColor; + set => defaultLineColor = value; + } + + [SerializeField] + private Gradient lineColorInputDown = new Gradient(); + + public Gradient LineColorInputDown + { + get => lineColorInputDown; + set => lineColorInputDown = value; + } + + private FarInteractor farInteractor; + /// + public override IInteractor Interactor + { + get => farInteractor; + set + { + if (value is FarInteractor farInteractor) + { + this.farInteractor = farInteractor; + return; + } + + Debug.LogError($"{nameof(LineInteractorVisualizer)} is only meant to be used with {nameof(FarInteractor)}s."); + } + } + + protected virtual void OnValidate() + { + CheckInitialization(); + } + + protected virtual void OnEnable() + { + CheckInitialization(); + } + + private void CheckInitialization() + { + if (lineBase.IsNull()) + { + lineBase = GetComponent(); + } + + if (lineBase.IsNull()) + { + Debug.LogError($"No {nameof(BaseLineDataProvider)} found on {gameObject.name}."); + } + + if (lineBase.IsNotNull() && (lineRenderers == null || lineRenderers.Length == 0)) + { + lineRenderers = lineBase.GetComponentsInChildren(); + } + + if (lineRenderers == null || lineRenderers.Length == 0) + { + Debug.LogError($"No {nameof(BaseLineRenderer)}s found on {gameObject.name}."); + } + } + + /// + public override void OnPreRaycast() + { + Debug.Assert(lineBase.IsNotNull()); + + lineBase.UpdateMatrix(); + + if (Interactor == null || !Interactor.IsInteractionEnabled) + { + lineBase.enabled = false; + return; + } + + if (Interactor.RayStabilizer != null) + { + Interactor.RayStabilizer.UpdateStability(Interactor.Rays[0].Origin, Interactor.Rays[0].Direction); + Interactor.Rays[0].CopyRay(Interactor.RayStabilizer.StableRay, Interactor.Extent); + } + + Interactor.TryGetPointerPosition(out var pointerPosition); + Interactor.TryGetPointerRotation(out var pointerRotation); + + // Set our first and last points + lineBase.FirstPoint = pointerPosition; + + if (Interactor.IsFocusLocked && Interactor.Result.CurrentTarget != null) + { + if (Interactor.SyncedTarget != null) + { + // Now raycast out like nothing happened so we can get an updated pointer position. + lineBase.LastPoint = pointerPosition + pointerRotation * (Vector3.forward * Interactor.Extent); + } + else + { + // Set the line to the locked position. + lineBase.LastPoint = Interactor.Result.EndPoint; + } + } + else + { + lineBase.LastPoint = pointerPosition + pointerRotation * (Vector3.forward * Interactor.Extent); + } + + var stepSize = 1f / Interactor.Rays.Length; + var lastPoint = lineBase.GetUnClampedPoint(0f); + + for (int i = 0; i < Interactor.Rays.Length; i++) + { + var currentPoint = lineBase.GetUnClampedPoint(stepSize * (i + 1)); + Interactor.Rays[i].UpdateRayStep(ref lastPoint, ref currentPoint); + lastPoint = currentPoint; + } + } + + /// + public override void OnPostRaycast() + { + if (!Interactor.IsInteractionEnabled) + { + lineBase.enabled = false; + return; + } + + lineBase.enabled = true; + + Gradient lineColor; + + lineColor = Interactor.IsInputDown ? LineColorInputDown : DefaultLineColor; + var maxClampLineSteps = farInteractor.LineCastResolution; + + // Used to ensure the line doesn't extend beyond the cursor + float cursorOffsetWorldLength = Interactor.BaseCursor?.SurfaceCursorDistance ?? 0f; + + // The distance the ray travels through the world before it hits something. + // Measured in world-units (as opposed to normalized distance). + var clearWorldLength = (Interactor.Result?.CurrentTarget != null) ? Interactor.Result.RayDistance : Interactor.Extent; + + for (var i = 0; i < lineRenderers.Length; i++) + { + var lineRenderer = lineRenderers[i]; + // Renderers are enabled by default if line is enabled + lineRenderer.enabled = true; + maxClampLineSteps = Mathf.Max(maxClampLineSteps, lineRenderer.LineStepCount); + lineRenderer.LineColor = lineColor; + } + + // If focus is locked, we're sticking to the target + // So don't clamp the world length + if (Interactor.IsFocusLocked && Interactor.Result.CurrentTarget != null) + { + if (Interactor.SyncedTarget != null) + { + if (Interactor.Result.GrabPoint == Vector3.zero) + { + lineBase.LastPoint = Interactor.Result.EndPoint; + } + else + { + lineBase.LastPoint = Interactor.Result.GrabPoint; + } + } + + var cursorOffsetLocalLength = lineBase.GetNormalizedLengthFromWorldLength(cursorOffsetWorldLength); + lineBase.LineEndClamp = 1 - cursorOffsetLocalLength; + } + else + { + // Otherwise clamp the line end by the clear distance + float clearLocalLength = lineBase.GetNormalizedLengthFromWorldLength(clearWorldLength - cursorOffsetWorldLength, maxClampLineSteps); + lineBase.LineEndClamp = clearLocalLength; + } + } + } +} diff --git a/Runtime/Input/Interactors/LineInteractorVisualizer.cs.meta b/Runtime/Input/Interactors/LineInteractorVisualizer.cs.meta new file mode 100644 index 000000000..56514553a --- /dev/null +++ b/Runtime/Input/Interactors/LineInteractorVisualizer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a0c2a07ed1df1094ba9ac469febef61e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 08c0fd91bdca45afa09ec64323cf3848, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit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0mjfnB37@ diff --git a/Runtime/Utilities/Lines/Modules/BaseLineDataProvider.cs b/Runtime/Utilities/Lines/Modules/BaseLineDataProvider.cs index 61422f739..9a4079311 100644 --- a/Runtime/Utilities/Lines/Modules/BaseLineDataProvider.cs +++ b/Runtime/Utilities/Lines/Modules/BaseLineDataProvider.cs @@ -1,6 +1,7 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using RealityCollective.Utilities.Extensions; using RealityToolkit.Definitions.Lines; using RealityToolkit.Utilities.Physics.Distorters; using System.Collections.Generic; @@ -60,7 +61,7 @@ public float LineEndClamp /// public Transform LineTransform { - get => customLineTransform != null ? customLineTransform : transform; + get => customLineTransform.IsNotNull() ? customLineTransform : transform; set => customLineTransform = value; } diff --git a/Runtime/Utilities/Lines/Renderers/LineRenderer.cs b/Runtime/Utilities/Lines/Renderers/SimpleLineRenderer.cs similarity index 98% rename from Runtime/Utilities/Lines/Renderers/LineRenderer.cs rename to Runtime/Utilities/Lines/Renderers/SimpleLineRenderer.cs index f8b399e65..06b847b4c 100644 --- a/Runtime/Utilities/Lines/Renderers/LineRenderer.cs +++ b/Runtime/Utilities/Lines/Renderers/SimpleLineRenderer.cs @@ -13,7 +13,7 @@ namespace RealityToolkit.Utilities.Lines.Renderers /// [RequireComponent(typeof(UnityEngine.LineRenderer))] [RequireComponent(typeof(BaseLineDataProvider))] - public class LineRenderer : BaseLineRenderer + public class SimpleLineRenderer : BaseLineRenderer { [Header("Reality Toolkit Line Renderer Settings")] diff --git a/Runtime/Utilities/Lines/Renderers/LineRenderer.cs.meta b/Runtime/Utilities/Lines/Renderers/SimpleLineRenderer.cs.meta similarity index 100% rename from Runtime/Utilities/Lines/Renderers/LineRenderer.cs.meta rename to Runtime/Utilities/Lines/Renderers/SimpleLineRenderer.cs.meta