From 0d1c168736f40645294ef8f9b6833dca819f1eeb Mon Sep 17 00:00:00 2001 From: nothke Date: Sat, 17 Aug 2024 13:38:26 +0200 Subject: [PATCH] Sliding crane --- Assets/Materials/box.mat | 4 +- Assets/Materials/box_black.mat | 83 ++ Assets/Materials/box_black.mat.meta | 8 + .../Scenes/test_conveyor_belt_character.unity | 987 ++++++++++++++++++ Assets/Scripts/SlidingCrane.cs | 32 + Assets/Scripts/SlidingCrane.cs.meta | 11 + Assets/Scripts/Utils.meta | 8 + Assets/Scripts/Utils/Interpolator.cs | 406 +++++++ Assets/Scripts/Utils/Interpolator.cs.meta | 11 + 9 files changed, 1548 insertions(+), 2 deletions(-) create mode 100644 Assets/Materials/box_black.mat create mode 100644 Assets/Materials/box_black.mat.meta create mode 100644 Assets/Scripts/SlidingCrane.cs create mode 100644 Assets/Scripts/SlidingCrane.cs.meta create mode 100644 Assets/Scripts/Utils.meta create mode 100644 Assets/Scripts/Utils/Interpolator.cs create mode 100644 Assets/Scripts/Utils/Interpolator.cs.meta diff --git a/Assets/Materials/box.mat b/Assets/Materials/box.mat index 24d96dc..f35b08e 100644 --- a/Assets/Materials/box.mat +++ b/Assets/Materials/box.mat @@ -66,7 +66,7 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 0 - _GlossMapScale: 1 - - _Glossiness: 0.5 + - _Glossiness: 0 - _GlossyReflections: 1 - _Metallic: 0 - _Mode: 0 @@ -78,6 +78,6 @@ Material: - _UVSec: 0 - _ZWrite: 1 m_Colors: - - _Color: {r: 0.988124, g: 1, b: 0, a: 1} + - _Color: {r: 1, g: 0.8835205, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Materials/box_black.mat b/Assets/Materials/box_black.mat new file mode 100644 index 0000000..23b1b56 --- /dev/null +++ b/Assets/Materials/box_black.mat @@ -0,0 +1,83 @@ +%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: box_black + m_Shader: {fileID: 46, 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: + - _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: 0.061, y: 0.061} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: 4e76002f02c7e8c4290fb7bf8cb0fdc1, type: 3} + m_Scale: {x: 0.061, y: 0.061} + 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: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0 + - _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.33962262, g: 0.33962262, b: 0.33962262, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Materials/box_black.mat.meta b/Assets/Materials/box_black.mat.meta new file mode 100644 index 0000000..839af1f --- /dev/null +++ b/Assets/Materials/box_black.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 54361f89cfee8b94d810c14a6beb11b5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/test_conveyor_belt_character.unity b/Assets/Scenes/test_conveyor_belt_character.unity index c085bb5..4f26162 100644 --- a/Assets/Scenes/test_conveyor_belt_character.unity +++ b/Assets/Scenes/test_conveyor_belt_character.unity @@ -122,6 +122,111 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &11161646 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 11161647} + - component: {fileID: 11161650} + - component: {fileID: 11161649} + - component: {fileID: 11161648} + m_Layer: 0 + m_Name: Cube (2) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &11161647 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 11161646} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -6, y: 3.36, z: 0} + m_LocalScale: {x: 1, y: 8.088, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2110680922} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &11161648 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 11161646} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &11161649 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 11161646} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: bef232e221fa62047b268fcc0f75629a, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &11161650 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 11161646} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &52343521 GameObject: m_ObjectHideFlags: 0 @@ -388,6 +493,38 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 86.608, y: 0, z: 19.775} +--- !u!1 &206961843 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 206961844} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &206961844 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 206961843} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 6.64, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 2091815368} + m_Father: {fileID: 2110680922} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &236143043 PrefabInstance: m_ObjectHideFlags: 0 @@ -912,6 +1049,111 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 24092a40b02616e479baeb940325e339, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &439680959 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 439680960} + - component: {fileID: 439680963} + - component: {fileID: 439680962} + - component: {fileID: 439680961} + m_Layer: 0 + m_Name: Cube (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &439680960 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 439680959} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 7.17, z: 0} + m_LocalScale: {x: 13.487551, y: 0.8552252, z: 0.85805} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2110680922} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &439680961 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 439680959} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &439680962 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 439680959} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: bef232e221fa62047b268fcc0f75629a, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &439680963 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 439680959} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1001 &444488768 PrefabInstance: m_ObjectHideFlags: 0 @@ -1368,6 +1610,111 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 86.608, y: 0, z: 19.775} +--- !u!1 &571825759 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 571825760} + - component: {fileID: 571825763} + - component: {fileID: 571825762} + - component: {fileID: 571825761} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &571825760 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 571825759} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 5.87, y: -0.35, z: 18.81} + m_LocalScale: {x: 0.27687, y: 0.41315, z: 40} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 861608891} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &571825761 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 571825759} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &571825762 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 571825759} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 54361f89cfee8b94d810c14a6beb11b5, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &571825763 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 571825759} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &593760053 GameObject: m_ObjectHideFlags: 0 @@ -1994,6 +2341,111 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 86.608, y: 0, z: 19.775} +--- !u!1 &826892522 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 826892526} + - component: {fileID: 826892525} + - component: {fileID: 826892524} + - component: {fileID: 826892523} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &826892523 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 826892522} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &826892524 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 826892522} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &826892525 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 826892522} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &826892526 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 826892522} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 21.567997, y: 0.16, z: 24.309193} + 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!1 &838017853 GameObject: m_ObjectHideFlags: 0 @@ -2127,6 +2579,73 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 86.608, y: 0, z: 19.775} +--- !u!1 &861608890 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 861608891} + - component: {fileID: 861608892} + m_Layer: 0 + m_Name: crane_root + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &861608891 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 861608890} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 20.26, y: 0, z: 28.17} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 2110680922} + - {fileID: 571825760} + - {fileID: 1110140477} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &861608892 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 861608890} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: da3ed29216d73fb43be6448aea116576, type: 3} + m_Name: + m_EditorClassIdentifier: + xMotion: + maxSpeed: 0.5 + acceleration: 0.5 + brakingAcceleration: 0.5 + progress: 0 + velocity: 0 + accel: 0 + braking: 0 + yMotion: + maxSpeed: 0.07 + acceleration: 0.5 + brakingAcceleration: 0.5 + progress: 0 + velocity: 0 + accel: 0 + braking: 0 + xTransform: {fileID: 2091815368} + yTransform: {fileID: 2110680922} + yRange: 40 + xRange: 4.5 --- !u!114 &992787539 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 114565867274256808, guid: d295472d4ce25404e9aed2627c34801f, type: 3} @@ -2404,6 +2923,111 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 86.608, y: 0, z: 19.775} +--- !u!1 &1110140476 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1110140477} + - component: {fileID: 1110140480} + - component: {fileID: 1110140479} + - component: {fileID: 1110140478} + m_Layer: 0 + m_Name: Cube (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1110140477 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1110140476} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -6.1, y: -0.35, z: 18.81} + m_LocalScale: {x: 0.27687, y: 0.41315, z: 40} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 861608891} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &1110140478 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1110140476} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1110140479 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1110140476} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 54361f89cfee8b94d810c14a6beb11b5, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1110140480 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1110140476} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1001 &1111469476 PrefabInstance: m_ObjectHideFlags: 0 @@ -2461,6 +3085,89 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 0fb5ec34d66e2824c92ed0b720ca13df, type: 3} +--- !u!1 &1263390226 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1263390227} + - component: {fileID: 1263390229} + - component: {fileID: 1263390228} + m_Layer: 0 + m_Name: Cube (4) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1263390227 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1263390226} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: -3.12, z: 0} + m_LocalScale: {x: 0.18936521, y: 6.540553, z: 0.16858572} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2091815368} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &1263390228 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1263390226} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 54361f89cfee8b94d810c14a6beb11b5, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1263390229 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1263390226} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &1564899495 GameObject: m_ObjectHideFlags: 0 @@ -3072,6 +3779,284 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 0fb5ec34d66e2824c92ed0b720ca13df, type: 3} +--- !u!1 &1942585600 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1942585601} + - component: {fileID: 1942585604} + - component: {fileID: 1942585603} + - component: {fileID: 1942585602} + m_Layer: 0 + m_Name: Cube (3) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1942585601 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1942585600} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0.26000023, z: 0} + m_LocalScale: {x: 1.8217084, y: 0.66555333, z: 1.2053028} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2091815368} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &1942585602 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1942585600} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1942585603 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1942585600} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 54361f89cfee8b94d810c14a6beb11b5, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1942585604 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1942585600} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &2054939181 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2054939182} + - component: {fileID: 2054939185} + - component: {fileID: 2054939184} + - component: {fileID: 2054939183} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2054939182 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054939181} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 6, y: 3.36, z: 0} + m_LocalScale: {x: 1, y: 8.088, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2110680922} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!65 &2054939183 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054939181} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &2054939184 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054939181} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: bef232e221fa62047b268fcc0f75629a, 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_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &2054939185 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054939181} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &2091815367 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2091815368} + m_Layer: 0 + m_Name: crane_overhead + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2091815368 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2091815367} + 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: + - {fileID: 1942585601} + - {fileID: 1263390227} + m_Father: {fileID: 206961844} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2110680920 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2110680922} + m_Layer: 0 + m_Name: crane_frame + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2110680922 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2110680920} + 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: + - {fileID: 206961844} + - {fileID: 2054939182} + - {fileID: 439680960} + - {fileID: 11161647} + m_Father: {fileID: 861608891} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &6217297023818049519 PrefabInstance: m_ObjectHideFlags: 0 @@ -3160,3 +4145,5 @@ SceneRoots: - {fileID: 444488768} - {fileID: 236143043} - {fileID: 1793071885} + - {fileID: 826892526} + - {fileID: 861608891} diff --git a/Assets/Scripts/SlidingCrane.cs b/Assets/Scripts/SlidingCrane.cs new file mode 100644 index 0000000..5c0d786 --- /dev/null +++ b/Assets/Scripts/SlidingCrane.cs @@ -0,0 +1,32 @@ +using Nothke.Utils; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SlidingCrane : MonoBehaviour +{ + public InertialInterpolator xMotion = InertialInterpolator.Default(); + public InertialInterpolator yMotion = InertialInterpolator.Default(); + + public Transform xTransform; + public Transform yTransform; + + public float yRange = 10; + public float xRange = 5; + + void Start() + { + yMotion.AccelerateTo(1); + xMotion.AccelerateTo(1); + } + + // Update is called once per frame + void Update() + { + xMotion.Update(Time.deltaTime); + yMotion.Update(Time.deltaTime); + + yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange); + xTransform.localPosition = new Vector3(xMotion.progress * xRange, 0, 0); + } +} diff --git a/Assets/Scripts/SlidingCrane.cs.meta b/Assets/Scripts/SlidingCrane.cs.meta new file mode 100644 index 0000000..afb879c --- /dev/null +++ b/Assets/Scripts/SlidingCrane.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: da3ed29216d73fb43be6448aea116576 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils.meta b/Assets/Scripts/Utils.meta new file mode 100644 index 0000000..26122b4 --- /dev/null +++ b/Assets/Scripts/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6c0aa3bf4c555da4db98db8126dbda0c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/Interpolator.cs b/Assets/Scripts/Utils/Interpolator.cs new file mode 100644 index 0000000..8d1ef0f --- /dev/null +++ b/Assets/Scripts/Utils/Interpolator.cs @@ -0,0 +1,406 @@ +/// +/// Interpolator and InertialInterpolator by Nothke +/// +/// A utility struct for when a value needs to smoothly transition between 2 states. +/// +/// Call Regress() to make the state advance towards 0, +/// or Progress() to make it advance towards 1. +/// Alternatively use Toggle(). +/// SetTo(value) will set it to a state immediately. +/// +/// Call Update() every frame or fixed frame for the transition to progress. +/// +/// An Interpolator is a version that transits at fixed speed. +/// +/// An InertialInterpolator is a version that uses inertia, it will accelerate from one state, +/// and slow down when approaching the end state. +/// InertialInterpolator can also advance to arbitrary point with AccelerateTo(value). +/// It can also "emergency-stop" by calling StartBraking(). +/// +/// It doesn't matter if you call the functions repeatedly or once. +/// +/// Make sure to have a maxSpeed parameter higher than 0, otherwise they won't move. +/// +/// To initialize the struct correctly in inspector (with maxSpeed > 0) use: +/// public Interpolator interpolator = Interpolator.Default(); +/// +/// ============================================================================ +/// +/// MIT License +/// +/// Copyright(c) 2021 Ivan Notaroš +/// +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in all +/// copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +/// SOFTWARE. +/// +/// ============================================================================ +/// + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; + +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace Nothke.Utils +{ + public enum ProgressionState + { + AtStart, + Progressing, + AtEnd, + Regressing + }; + + public interface IInterpolator + { + void Update(float dt); + ProgressionState State { get; } + + /// + /// Advance value towards 1. + /// + void Progress(); + /// + /// Advance value towards 0. + /// + void Regress(); + + void SetTo(float value); + + /// + /// Toggle progression between progressing or regressing. + /// + void Toggle(); + } + + [System.Serializable] + public struct Interpolator : IInterpolator + { + public float maxSpeed; + + [HideInInspector] + public float progress, velocity; + + ProgressionState state; + + public ProgressionState State => state; + //public bool ProgressingOrAtEnd => state == DeploymentState.Progressing || state == DeploymentState.AtEnd; + + public static Interpolator Default() + { + return new Interpolator() + { + maxSpeed = 1 + }; + } + + public void Progress() + { + velocity = maxSpeed; + + state = ProgressionState.Progressing; + } + + public void Regress() + { + velocity = -maxSpeed; + + state = ProgressionState.Regressing; + } + + public void Toggle() + { + if (state == ProgressionState.AtEnd || state == ProgressionState.Progressing) + Regress(); + else + Progress(); + } + + public void SetTo(float value) + { + value = Mathf.Clamp01(value); + + progress = value; + velocity = 0; + + if (value == 1) + state = ProgressionState.AtEnd; + else if (value == 0) + state = ProgressionState.AtStart; + else + state = ProgressionState.Progressing; + } + + public void Update(float dt) + { + if (maxSpeed == 0) + return; + + progress += velocity * dt; + + if (velocity < 0 && progress < 0) + { + progress = 0; + + if (state == ProgressionState.Regressing) + { + velocity = 0; + state = ProgressionState.AtStart; + } + } + else if (velocity > 0 && progress > 1) + { + progress = 1; + + if (state == ProgressionState.Progressing) + { + velocity = 0; + state = ProgressionState.AtEnd; + } + } + } + } + + [System.Serializable] + public struct InertialInterpolator : IInterpolator + { + public float maxSpeed; + public float acceleration; + public float brakingAcceleration; + + [HideInInspector] public float progress; + [HideInInspector] public float velocity; + + [HideInInspector] public float accel; + private ProgressionState state; + [HideInInspector] public bool braking; + + private float endTarget; + private float beginTarget; + + public ProgressionState State => state; + public bool Stopped => velocity == 0; + + public static InertialInterpolator Default() + { + return new InertialInterpolator() + { + maxSpeed = 1f, + acceleration = 1f, + + endTarget = 1f + }; + } + + public void Toggle() + { + if (state == ProgressionState.AtEnd || state == ProgressionState.Progressing) + Regress(); + else + Progress(); + } + + private void ProgressTo(float to) + { + endTarget = to; + + accel = acceleration; + + state = ProgressionState.Progressing; + + braking = velocity < 0; + + if (braking) + accel = brakingAcceleration > 0 ? brakingAcceleration : acceleration; + } + + public void Progress() + { + ProgressTo(1); + } + + private void RegressTo(float to) + { + beginTarget = to; + + accel = -acceleration; + + state = ProgressionState.Regressing; + + braking = velocity > 0; + + if (braking) + accel = brakingAcceleration > 0 ? -brakingAcceleration : -acceleration; + } + + public void Regress() + { + RegressTo(0); + } + + /// + /// Sets the target to start accelerating to. Note, the input should always be 0-1 + /// + /// + public void AccelerateTo(float to) + { + if (progress < to) + ProgressTo(to); + else + RegressTo(to); + } + + /// + /// The interpolator will start decelerating with brakingAcceleration eventually slowly coming to a stop, + /// overriding any progression status. + /// + public void StartBraking() + { + if (braking) + return; + + braking = true; + + switch (velocity) + { + case > 0: + ProgressTo(Mathf.Min(progress + StoppingDistance(velocity, -brakingAcceleration), 1)); + return; + case < 0: + RegressTo(Mathf.Max(progress - -StoppingDistance(velocity, brakingAcceleration), 0)); + return; + } + } + + static float StoppingDistance(float curVelo, float accel) + { + return curVelo * curVelo / (2 * -accel); + } + + public void Update(float dt) + { + if (maxSpeed == 0) + Debug.Log("MaxSpeed of a Deployer is 0, there will be no movement. Please set it before using"); + + // Limit velocity + if (velocity < -maxSpeed) + { + accel = 0; + velocity = -maxSpeed + Mathf.Epsilon; + } + else if (velocity > maxSpeed) + { + accel = 0; + velocity = maxSpeed - Mathf.Epsilon; + } + + if (brakingAcceleration > 0 && !braking) + { + // TODO: Handle the case where braking force is so big that it immediately reverses the direction + // In that case we should skip braking state entirely + + if (velocity > 0 && state == ProgressionState.Progressing) + { + float stopDist = StoppingDistance(velocity, -brakingAcceleration); + + if (progress > endTarget - stopDist) + { + accel = -brakingAcceleration; + braking = true; + } + } + else if (velocity < 0 && state == ProgressionState.Regressing) + { + float stopDist = -StoppingDistance(velocity, brakingAcceleration); + + if (progress < beginTarget + stopDist) + { + accel = brakingAcceleration; + braking = true; + } + } + } + + + if (braking) + { + if (accel < 0 && velocity < 0) + { + if (state == ProgressionState.Progressing) + SetTo(endTarget); + else + { + braking = false; + accel = -acceleration; + } + } + else if (accel > 0 && velocity > 0) + { + if (state == ProgressionState.Regressing) + SetTo(beginTarget); + else + { + braking = false; + accel = acceleration; + } + } + } + + velocity += accel * dt; + progress += velocity * dt; + + // Clamp between 0-1 + if (velocity < 0 && progress < 0) + { + progress = 0; + velocity = 0; + + if (state == ProgressionState.Regressing) + SetTo(0); + } + else if (velocity > 0 && progress > 1) + { + progress = 1; + velocity = 0; + + if (state == ProgressionState.Progressing) + SetTo(1); + } + } + + public void SetTo(float value) + { + value = Mathf.Clamp01(value); + progress = value; + velocity = 0; + accel = 0; + braking = false; + + if (value == 1) + state = ProgressionState.AtEnd; + else if (value == 0) + state = ProgressionState.AtStart; + else + state = ProgressionState.Progressing; + } + } +} diff --git a/Assets/Scripts/Utils/Interpolator.cs.meta b/Assets/Scripts/Utils/Interpolator.cs.meta new file mode 100644 index 0000000..4edaf92 --- /dev/null +++ b/Assets/Scripts/Utils/Interpolator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9eeaa9ab61b55044a81d9d7221b8a153 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: