diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 6093596..222de1b 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -262,6 +262,67 @@ Transform: m_CorrespondingSourceObject: {fileID: 4626647624635935874, guid: 52253a366fba6644b8983c5cf7fbfc9f, type: 3} m_PrefabInstance: {fileID: 27502696} m_PrefabAsset: {fileID: 0} +--- !u!1001 &54662197 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalPosition.x + value: -5.343111 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalPosition.y + value: 0.625 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalPosition.z + value: 5.7854557 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 270648843518875621, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3486484010427172590, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: m_Name + value: Produced E + objectReference: {fileID: 0} + - target: {fileID: 4275785426082247918, guid: 14d16caaceafb634f87449e796c4543a, type: 3} + propertyPath: Defect + value: 2048 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 14d16caaceafb634f87449e796c4543a, type: 3} --- !u!1001 &169426980 PrefabInstance: m_ObjectHideFlags: 0 @@ -1142,6 +1203,10 @@ PrefabInstance: propertyPath: ProductionPhases.Array.data[0].TotalSpawnCount value: 15 objectReference: {fileID: 0} + - target: {fileID: 6695070873418123376, guid: a3cb7267f99421c4b9912896d1eb7a41, type: 3} + propertyPath: ProductionPhases.Array.data[0].ProductType + value: + objectReference: {fileID: 11400000, guid: 42240b227563f074aa0dd8fee3c0cb35, type: 2} - target: {fileID: 9072778288000056937, guid: a3cb7267f99421c4b9912896d1eb7a41, type: 3} propertyPath: m_LocalPosition.x value: 9.5 @@ -2809,7 +2874,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8361960510235702639, guid: cdb590802e3f6bd4db6d5eddce994501, type: 3} propertyPath: m_LocalPosition.z - value: 4.5982304 + value: -3.1517696 objectReference: {fileID: 0} - target: {fileID: 8361960510235702639, guid: cdb590802e3f6bd4db6d5eddce994501, type: 3} propertyPath: m_LocalRotation.w @@ -4249,7 +4314,7 @@ PrefabInstance: - target: {fileID: 7838576090119534409, guid: ae50320a2d4c84c4391086045d06a9c9, type: 3} propertyPath: conversionProduct value: - objectReference: {fileID: 11400000, guid: 1e626f6e0e642b44aaeb77b6628c8be7, type: 2} + objectReference: {fileID: 11400000, guid: 6f11438f5cec6a24cb2a32fccc6244d1, type: 2} m_RemovedComponents: - {fileID: 7530552424279411822, guid: ae50320a2d4c84c4391086045d06a9c9, type: 3} m_RemovedGameObjects: [] @@ -4284,3 +4349,4 @@ SceneRoots: - {fileID: 721670239} - {fileID: 1382857590} - {fileID: 447484957} + - {fileID: 54662197} diff --git a/Assets/Scripts/Interactable/HammerableRigidbody.cs b/Assets/Scripts/Interactable/HammerableRigidbody.cs index bbd5edb..421c57a 100644 --- a/Assets/Scripts/Interactable/HammerableRigidbody.cs +++ b/Assets/Scripts/Interactable/HammerableRigidbody.cs @@ -22,6 +22,8 @@ public class HammerableRigidbody: RigidbodyInteractable } var clip = product.Type.SelectClip(product.Defect != DefectType.None); - NAudio.Play(clip, transform.position); + clip.Play( + transform.position, + Random.Range(0.8f, 1.2f)); } } \ No newline at end of file diff --git a/Assets/Scripts/Machines/Converter.cs b/Assets/Scripts/Machines/Converter.cs index 8e773ef..0f3345e 100644 --- a/Assets/Scripts/Machines/Converter.cs +++ b/Assets/Scripts/Machines/Converter.cs @@ -62,7 +62,7 @@ public class Converter: MonoBehaviour, IResetable if (inputProducts[0].Type == expectedReagent) { - Spawner.SpawnProduct(conversionProduct); + Spawner.SpawnProduct(conversionProduct, currentProduct.Defect); inputProducts.RemoveAt(0); Destroy(currentProduct); } diff --git a/Assets/Scripts/Machines/DoubleConverter.cs b/Assets/Scripts/Machines/DoubleConverter.cs index 2c5adc1..cb8cdbf 100644 --- a/Assets/Scripts/Machines/DoubleConverter.cs +++ b/Assets/Scripts/Machines/DoubleConverter.cs @@ -1,14 +1,17 @@ using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Serialization; public class DoubleConverter: MonoBehaviour, IResetable { public ProductSpawner Spawner; - public List inputProducts; + public List inputTypeOne; + public List inputTypeTwo; + public List refuse; - public ProductType expectedReagent; - public Transform outputPoint; + public ProductType expectedReagentA; + public ProductType expectedReagentB; public ProductType conversionProduct; public int CurrentHealth; @@ -18,16 +21,25 @@ public class DoubleConverter: MonoBehaviour, IResetable private float _conversionTimer; public Transform refuseLauncher; - public float launchPower = 10f; + public float launchPower = 5f; public void OnTriggerEnter(Collider other) { var product = other.GetComponentInParent(); - if (product) + product.gameObject.SetActive(false); + + if (product.Type == expectedReagentA) { - product.gameObject.SetActive(false); - inputProducts.Add(product); + inputTypeOne.Add(product); + } + else if (product.Type == expectedReagentB) + { + inputTypeTwo.Add(product); + } + else + { + refuse.Add(product); } } @@ -41,7 +53,9 @@ public class DoubleConverter: MonoBehaviour, IResetable _conversionTimer = conversionDuration; CurrentHealth = MaxHealth; - inputProducts.Clear(); + inputTypeOne.Clear(); + inputTypeTwo.Clear(); + refuse.Clear(); } public void Update() @@ -51,25 +65,30 @@ public class DoubleConverter: MonoBehaviour, IResetable return; } - if (inputProducts.Count == 0) + if (refuse.Count == 0 && inputTypeOne.Count == 0 && inputTypeTwo.Count == 0) { return; } if (_conversionTimer <= 0f) { - var currentProduct = inputProducts[0]; - - if (inputProducts[0].Type == expectedReagent) + if (refuse.Count > 0) { - Spawner.SpawnProduct(conversionProduct); - inputProducts.RemoveAt(0); - Destroy(currentProduct); + Expel(refuse[0]); + refuse.RemoveAt(0); + _conversionTimer = conversionDuration; + return; } - else + + if (inputTypeOne.Count > 0 && inputTypeTwo.Count > 0) { - Expel(inputProducts[0]); - inputProducts.RemoveAt(0); + DefectType defectType = inputTypeOne[0].Defect & inputTypeTwo[0].Defect; + + inputTypeOne.RemoveAt(0); + inputTypeTwo.RemoveAt(0); + + Spawner.SpawnProduct(conversionProduct, defectType); + return; } _conversionTimer = conversionDuration; diff --git a/Assets/Scripts/Machines/ProductSpawner.cs b/Assets/Scripts/Machines/ProductSpawner.cs index e488f15..a181369 100644 --- a/Assets/Scripts/Machines/ProductSpawner.cs +++ b/Assets/Scripts/Machines/ProductSpawner.cs @@ -16,4 +16,15 @@ public class ProductSpawner: MonoBehaviour ProductType.SpawnProduct(type, transform, randomOrientation.position, rotation); } + + public void SpawnProduct(ProductType type, DefectType defect) + { + var randomIndex = Random.Range(0, PossibleOrientations.Count); + var randomOrientation = PossibleOrientations[randomIndex]; + + var rotation = Quaternion.AngleAxis(Random.Range(yRotation.x, yRotation.y), Vector3.up) * + randomOrientation.rotation; + + ProductType.SpawnProduct(type, defect, transform, randomOrientation.position, rotation); + } } \ No newline at end of file diff --git a/Assets/Scripts/Products/ProductType.cs b/Assets/Scripts/Products/ProductType.cs index 6251ea5..b3321a2 100644 --- a/Assets/Scripts/Products/ProductType.cs +++ b/Assets/Scripts/Products/ProductType.cs @@ -27,6 +27,13 @@ public class ProductType : ScriptableObject newProduct.ApplyDefect(type.SelectDefect()); } + public static void SpawnProduct(ProductType type, DefectType defect, Transform parent, Vector3 position, Quaternion rotation) + { + var newProduct = Instantiate(type.Prefab, position, rotation, parent); + newProduct.Type = type; + newProduct.ApplyDefect(defect); + } + public DefectType SelectDefect() { float randomValue = Random.Range(0, 100);