From faa5d9e22ca9bbba107bba244d426ec0a39ea20a Mon Sep 17 00:00:00 2001 From: Nikita Kruglickiy Date: Sat, 16 Mar 2024 23:54:50 +0300 Subject: [PATCH] =?UTF-8?q?#13=20=D0=97=D0=B2=D1=83=D0=BA=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D1=8F=20=D0=B4=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_Prefabs/Door Single.prefab | 2 ++ .../3D Free Modular Kit/_Prefabs/Door.prefab | 4 ++- Assets/Resources/Audio/Env.meta | 8 ++++++ Assets/Resources/Audio/Env/door-close.mp3 | 3 +++ .../Resources/Audio/Env/door-close.mp3.meta | 22 ++++++++++++++++ Assets/Resources/Audio/Env/door-close2.mp3 | 3 +++ .../Resources/Audio/Env/door-close2.mp3.meta | 22 ++++++++++++++++ Assets/Resources/Audio/Env/door-open.mp3 | 3 +++ Assets/Resources/Audio/Env/door-open.mp3.meta | 22 ++++++++++++++++ Assets/Resources/Audio/Env/door-open2.mp3 | 3 +++ .../Resources/Audio/Env/door-open2.mp3.meta | 22 ++++++++++++++++ Assets/Scenes/Space.unity | 20 ++++++++------ .../Environment/Interactive/SciFiDoor.cs | 26 ++++++++++++++++++- 13 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 Assets/Resources/Audio/Env.meta create mode 100644 Assets/Resources/Audio/Env/door-close.mp3 create mode 100644 Assets/Resources/Audio/Env/door-close.mp3.meta create mode 100644 Assets/Resources/Audio/Env/door-close2.mp3 create mode 100644 Assets/Resources/Audio/Env/door-close2.mp3.meta create mode 100644 Assets/Resources/Audio/Env/door-open.mp3 create mode 100644 Assets/Resources/Audio/Env/door-open.mp3.meta create mode 100644 Assets/Resources/Audio/Env/door-open2.mp3 create mode 100644 Assets/Resources/Audio/Env/door-open2.mp3.meta diff --git a/Assets/Environment/3D Free Modular Kit/_Prefabs/Door Single.prefab b/Assets/Environment/3D Free Modular Kit/_Prefabs/Door Single.prefab index 8cc1cb4..b2a737d 100644 --- a/Assets/Environment/3D Free Modular Kit/_Prefabs/Door Single.prefab +++ b/Assets/Environment/3D Free Modular Kit/_Prefabs/Door Single.prefab @@ -165,6 +165,8 @@ MonoBehaviour: syncMode: 0 syncInterval: 0.1 state: 0 + openClip: {fileID: 8300000, guid: 9c008e5df09e6a9468f26639dc43fb1c, type: 3} + closeClip: {fileID: 8300000, guid: de03bb61d997f68419fe5c9c7eb6a3d6, type: 3} duration: 2 offset: 2.5 oCurva: diff --git a/Assets/Environment/3D Free Modular Kit/_Prefabs/Door.prefab b/Assets/Environment/3D Free Modular Kit/_Prefabs/Door.prefab index cbc08ce..e94bc8a 100644 --- a/Assets/Environment/3D Free Modular Kit/_Prefabs/Door.prefab +++ b/Assets/Environment/3D Free Modular Kit/_Prefabs/Door.prefab @@ -530,7 +530,7 @@ AudioSource: OutputAudioMixerGroup: {fileID: 0} m_audioClip: {fileID: 8300000, guid: 089ede39b7c6649a881da9b3834212c9, type: 3} m_PlayOnAwake: 0 - m_Volume: 1 + m_Volume: 0.5 m_Pitch: 1 Loop: 0 Mute: 0 @@ -646,6 +646,8 @@ MonoBehaviour: syncMode: 0 syncInterval: 0.1 state: 0 + openClip: {fileID: 8300000, guid: 9c008e5df09e6a9468f26639dc43fb1c, type: 3} + closeClip: {fileID: 8300000, guid: de03bb61d997f68419fe5c9c7eb6a3d6, type: 3} duration: 2 offset: 2.5 oCurva: diff --git a/Assets/Resources/Audio/Env.meta b/Assets/Resources/Audio/Env.meta new file mode 100644 index 0000000..1603fa3 --- /dev/null +++ b/Assets/Resources/Audio/Env.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eeb6f6857c4a4b0439a759086260ce48 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/Env/door-close.mp3 b/Assets/Resources/Audio/Env/door-close.mp3 new file mode 100644 index 0000000..7d0f499 --- /dev/null +++ b/Assets/Resources/Audio/Env/door-close.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc0b44f20c1917979490cd21fe7a3648e46cf4b8659346801b4bf777c1d66cdf +size 25912 diff --git a/Assets/Resources/Audio/Env/door-close.mp3.meta b/Assets/Resources/Audio/Env/door-close.mp3.meta new file mode 100644 index 0000000..ddb1e0e --- /dev/null +++ b/Assets/Resources/Audio/Env/door-close.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 39e43d5108f3a1246b562f102863e60f +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/Env/door-close2.mp3 b/Assets/Resources/Audio/Env/door-close2.mp3 new file mode 100644 index 0000000..e4a1083 --- /dev/null +++ b/Assets/Resources/Audio/Env/door-close2.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a4ccc424495938beca69ee15582660aa9a9cc92c98eab6f2df9db8f794b8d0d +size 27375 diff --git a/Assets/Resources/Audio/Env/door-close2.mp3.meta b/Assets/Resources/Audio/Env/door-close2.mp3.meta new file mode 100644 index 0000000..f43800e --- /dev/null +++ b/Assets/Resources/Audio/Env/door-close2.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: de03bb61d997f68419fe5c9c7eb6a3d6 +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/Env/door-open.mp3 b/Assets/Resources/Audio/Env/door-open.mp3 new file mode 100644 index 0000000..fff0709 --- /dev/null +++ b/Assets/Resources/Audio/Env/door-open.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:962c57d5822b4af558f46fcae1e7fd610de2456deff76c7524d4c19ca1c0b630 +size 20688 diff --git a/Assets/Resources/Audio/Env/door-open.mp3.meta b/Assets/Resources/Audio/Env/door-open.mp3.meta new file mode 100644 index 0000000..2a8e440 --- /dev/null +++ b/Assets/Resources/Audio/Env/door-open.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 36f2743cdc7732b479c91ebb0220c2bc +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/Env/door-open2.mp3 b/Assets/Resources/Audio/Env/door-open2.mp3 new file mode 100644 index 0000000..7c06eda --- /dev/null +++ b/Assets/Resources/Audio/Env/door-open2.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3ebdaa820e6e81a653a1b34c46df5f9719bec12af6e71b5d1b279b416175a5a +size 21105 diff --git a/Assets/Resources/Audio/Env/door-open2.mp3.meta b/Assets/Resources/Audio/Env/door-open2.mp3.meta new file mode 100644 index 0000000..9eae1e9 --- /dev/null +++ b/Assets/Resources/Audio/Env/door-open2.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 9c008e5df09e6a9468f26639dc43fb1c +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Space.unity b/Assets/Scenes/Space.unity index 30a7566..a4c2f08 100644 --- a/Assets/Scenes/Space.unity +++ b/Assets/Scenes/Space.unity @@ -149,8 +149,8 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2719641} - m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068} - m_LocalPosition: {x: -3.0000353, y: 0.000001136496, z: 11.999991} + m_LocalRotation: {x: 0.22161405, y: 0.6785788, z: -0.22698912, w: 0.6624908} + m_LocalPosition: {x: -309.30713, y: 209.22267, z: 24.826782} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -7371,7 +7371,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_RootOrder - value: 5 + value: 4 objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_LocalPosition.x @@ -20502,7 +20502,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_RootOrder - value: 2 + value: 1 objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_LocalPosition.x @@ -23785,7 +23785,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_RootOrder - value: 4 + value: 3 objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_LocalPosition.x @@ -77915,7 +77915,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 13385339066235970, guid: 66df3c5eb0b75424582840a6f8405e9b, type: 3} propertyPath: m_RootOrder - value: 7 + value: 6 objectReference: {fileID: 0} - target: {fileID: 13385339066235970, guid: 66df3c5eb0b75424582840a6f8405e9b, type: 3} propertyPath: m_LocalPosition.x @@ -144879,7 +144879,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_RootOrder - value: 3 + value: 2 objectReference: {fileID: 0} - target: {fileID: 6573182459455165619, guid: 41cf1eab2df798c4788c87b706a519d1, type: 3} propertyPath: m_LocalPosition.x @@ -144943,9 +144943,13 @@ PrefabInstance: propertyPath: sceneId value: 2022339728 objectReference: {fileID: 0} + - target: {fileID: 3933189198333053099, guid: 089b20c70699d924f8f39ed04504fe64, type: 3} + propertyPath: m_Volume + value: 0.5 + objectReference: {fileID: 0} - target: {fileID: 3933189198339639135, guid: 089b20c70699d924f8f39ed04504fe64, type: 3} propertyPath: m_RootOrder - value: 6 + value: 5 objectReference: {fileID: 0} - target: {fileID: 3933189198339639135, guid: 089b20c70699d924f8f39ed04504fe64, type: 3} propertyPath: m_LocalPosition.x diff --git a/Assets/Scripts/Environment/Interactive/SciFiDoor.cs b/Assets/Scripts/Environment/Interactive/SciFiDoor.cs index 500ed33..e178584 100644 --- a/Assets/Scripts/Environment/Interactive/SciFiDoor.cs +++ b/Assets/Scripts/Environment/Interactive/SciFiDoor.cs @@ -3,11 +3,15 @@ using System.Collections.Generic; using UnityEngine; using Mirror; +[RequireComponent(typeof(AudioSource))] public class SciFiDoor : NetworkBehaviour, IInteractable { [SyncVar] public bool state = false; + public AudioClip openClip; + public AudioClip closeClip; + public float duration = 2f, offset; public AnimationCurve oCurva; public List doorList; @@ -15,10 +19,12 @@ public class SciFiDoor : NetworkBehaviour, IInteractable private float _posX, _originX; private float _timeElapsed; + private AudioSource _audioSource; void Start() { _originX = doorList[0].localPosition.x; + _audioSource = GetComponent(); } public void Interact() { @@ -29,6 +35,10 @@ public class SciFiDoor : NetworkBehaviour, IInteractable private void CmdInteract(NetworkConnectionToClient sender = null) { state = !state; + + _audioSource.clip = state ? openClip : closeClip; + _audioSource.pitch = duration / _audioSource.clip.length; + _audioSource.Play(); } void Update() @@ -38,8 +48,22 @@ public class SciFiDoor : NetworkBehaviour, IInteractable float progress = _timeElapsed / duration; - _posX = Mathf.Lerp(_originX, _originX + offset, oCurva.Evaluate(progress)); + if (progress >= 1f) + { + _audioSource.Stop(); + + return; + } + + var t = oCurva.Evaluate(progress); + + _posX = Mathf.Lerp(_originX, _originX + offset, t); // _posX = Mathf.Lerp(_originX, _originX + offset, Mathf.SmoothStep(0, 1, progress)); + + if (_audioSource.clip) + { + _audioSource.timeSamples = Mathf.FloorToInt(Mathf.Abs(_audioSource.clip.samples * t)); + } for (int i = 1; i <= doorList.Count; i++) {