From 0bc8289d53f9402c482b88bd1de35e260967b0d4 Mon Sep 17 00:00:00 2001 From: colourfulspring Date: Fri, 23 Feb 2024 17:33:01 +0800 Subject: [PATCH] add: lineRender at NavMeshTest --- .../Examples/NavMeshTest/Scenes/Floor.prefab | 4 +- .../Examples/NavMeshTest/Scenes/Player.prefab | 122 +++++++++++++++++- .../NavMeshTest/Scripts/LineRender.cs | 35 +++++ .../NavMeshTest/Scripts/LineRender.cs.meta | 11 ++ .../SharedAssets/Materials/Orange.mat | 77 +++-------- .../SharedAssets/Materials/SpiritBlue.mat | 91 +++++++++++++ .../Materials/SpiritBlue.mat.meta | 8 ++ 7 files changed, 284 insertions(+), 64 deletions(-) create mode 100644 Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs create mode 100644 Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs.meta create mode 100644 Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat create mode 100644 Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat.meta diff --git a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Floor.prefab b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Floor.prefab index b1b8308e0..968d684ba 100644 --- a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Floor.prefab +++ b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Floor.prefab @@ -34,7 +34,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: -1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!33 &718127299357063990 MeshFilter: @@ -64,7 +64,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 2100000, guid: 5c59bd36def9a4684be49a21cf201a2d, type: 2} + - {fileID: 2100000, guid: 52eab8ab5010f438fab93da85735ba1d, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 diff --git a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Player.prefab b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Player.prefab index 80e7cea8c..69ddd183c 100644 --- a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Player.prefab +++ b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scenes/Player.prefab @@ -14,6 +14,8 @@ GameObject: - component: {fileID: 3574178317657103668} - component: {fileID: 8978271535513676955} - component: {fileID: 6164998309250235139} + - component: {fileID: 3590493939797189399} + - component: {fileID: 9018135760294820871} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -34,7 +36,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 4 + m_RootOrder: -1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!33 &3916307199209388056 MeshFilter: @@ -144,3 +146,121 @@ NavMeshAgent: m_BaseOffset: 1 m_WalkableMask: 4294967295 m_ObstacleAvoidanceType: 4 +--- !u!120 &3590493939797189399 +LineRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3986384243846796372} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + 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: af274938e390bf241a2ec6dff21f7b4a, 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} + - {x: 0, y: 0, z: 1} + m_Parameters: + serializedVersion: 3 + widthMultiplier: 1 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + serializedVersion: 2 + key0: {r: 0, g: 0, b: 0, a: 1} + key1: {r: 0, g: 0, b: 0, a: 1} + key2: {r: 1, g: 0.10272626, 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: 1542 + 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: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + numCornerVertices: 0 + numCapVertices: 0 + alignment: 0 + textureMode: 0 + textureScale: {x: 1, y: 1} + shadowBias: 0.5 + generateLightingData: 0 + m_MaskInteraction: 0 + m_UseWorldSpace: 1 + m_Loop: 0 + m_ApplyActiveColorSpace: 1 +--- !u!114 &9018135760294820871 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3986384243846796372} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: de79dcaa17358444fa44202c1787e270, type: 3} + m_Name: + m_EditorClassIdentifier: + minDistance: 0.1 + width: 2 diff --git a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs new file mode 100644 index 000000000..05538d7c1 --- /dev/null +++ b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using UnityEngine; + +public class LineRender : MonoBehaviour +{ + private LineRenderer line; + private Vector3 previousPosition; + [SerializeField] private float minDistance = 0.1f; + [SerializeField, Range(0f, 20f)] private float width = 2f; + + private void Start() + { + line = GetComponent(); + line.positionCount = 1; + previousPosition = transform.position; + line.SetPosition(0, previousPosition); + line.startWidth = line.endWidth = width; + } + + private void Update() + { + Vector3 currentPosition = transform.position; + currentPosition.y = 0f; + + if (Vector3.Distance(currentPosition, previousPosition) > minDistance) + { + line.positionCount++; + line.SetPosition(line.positionCount - 1, currentPosition); + previousPosition = currentPosition; + } + } +} diff --git a/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs.meta b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs.meta new file mode 100644 index 000000000..54abfdbba --- /dev/null +++ b/Project/Assets/ML-Agents/Examples/NavMeshTest/Scripts/LineRender.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de79dcaa17358444fa44202c1787e270 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/Orange.mat b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/Orange.mat index d6865f082..d3ca2f375 100644 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/Orange.mat +++ b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/Orange.mat @@ -2,75 +2,30 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_Name: Orange m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF + m_Parent: {fileID: 2100000, guid: eaad04b0e0dec42229c9cb00a981d7ac, type: 2} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: + - _GLOSSYREFLECTIONS_OFF + - _SPECULARHIGHLIGHTS_OFF + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} disabledShaderPasses: [] + m_LockedProperties: m_SavedProperties: serializedVersion: 3 - m_TexEnvs: - - _BumpMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailAlbedoMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailMask: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _DetailNormalMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _EmissionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MainTex: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MetallicGlossMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _OcclusionMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _ParallaxMap: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - - _BumpScale: 1 - - _Cutoff: 0.5 - - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _GlossMapScale: 1 - - _Glossiness: 0.5 - - _GlossyReflections: 0 - - _Metallic: 0 - - _Mode: 0 - - _OcclusionStrength: 1 - - _Parallax: 0.02 - - _SmoothnessTextureChannel: 0 - - _SpecularHighlights: 0 - - _SrcBlend: 1 - - _UVSec: 0 - - _ZWrite: 1 - m_Colors: - - _Color: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} - - _EmissionColor: {r: 0.98039216, g: 0.6509804, b: 0.16078432, a: 1} + m_TexEnvs: [] + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat new file mode 100644 index 000000000..4edfc182e --- /dev/null +++ b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat @@ -0,0 +1,91 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: SpiritBlue + m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AlphaTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - PixelSnap: 0 + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _EnableExternalAlpha: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 0, g: 0, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _Flip: {r: 1, g: 1, b: 1, a: 1} + - _RendererColor: {r: 1, g: 1, b: 1, a: 1} + m_BuildTextureStacks: [] diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat.meta b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat.meta new file mode 100644 index 000000000..ead3cc989 --- /dev/null +++ b/Project/Assets/ML-Agents/Examples/SharedAssets/Materials/SpiritBlue.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af274938e390bf241a2ec6dff21f7b4a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: