From ac1b5dccfab6fd4b906486d7b6cb3d28136b2cbc Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sat, 20 Apr 2024 19:33:01 +0200 Subject: [PATCH 1/2] Move tower aim to projectile tower --- Assets/Scenes/TowerTest.unity | 197 +++++++++++++++--------- Assets/Scripts/Tower/ProjectileTower.cs | 15 ++ Assets/Scripts/Tower/Tower.cs | 14 -- Assets/Scripts/Tower/TowerEditor.cs | 2 +- 4 files changed, 144 insertions(+), 84 deletions(-) diff --git a/Assets/Scenes/TowerTest.unity b/Assets/Scenes/TowerTest.unity index ccddcc5..f46d0c5 100644 --- a/Assets/Scenes/TowerTest.unity +++ b/Assets/Scenes/TowerTest.unity @@ -451,6 +451,133 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &770231297 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalPosition.x + value: 3.2174833 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalPosition.y + value: 1.0573871 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalPosition.z + value: -0.8372203 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3798190417997420117, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611178744751000815, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + propertyPath: m_Name + value: BlackHole + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 4611178744751000815, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + insertIndex: -1 + addedObject: {fileID: 770231300} + m_SourcePrefab: {fileID: 100100000, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, type: 3} +--- !u!1 &770231298 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4611178744751000815, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + m_PrefabInstance: {fileID: 770231297} + m_PrefabAsset: {fileID: 0} +--- !u!4 &770231299 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 6791947043022790992, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, + type: 3} + m_PrefabInstance: {fileID: 770231297} + m_PrefabAsset: {fileID: 0} +--- !u!114 &770231300 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 770231298} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4fb850aad740b9b418ade5f74fff1818, type: 3} + m_Name: + m_EditorClassIdentifier: + horizontalArc: {fileID: 0} + verticalArc: {fileID: 0} + radius: 1 + orb: {fileID: 770231299} + affectedBodies: + serializedVersion: 2 + m_Bits: 64 + distToAcceleration: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: -0.5 + outSlope: -0.5 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0.5 + inSlope: -0.5 + outSlope: -0.5 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &832575517 GameObject: m_ObjectHideFlags: 0 @@ -500,74 +627,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &841514572 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalPosition.x - value: 1.3662028 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalPosition.y - value: 0.10441658 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalPosition.z - value: -1.0829077 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: -8679921383154817045, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 919132149155446097, guid: 81c113ab4fb3e22748b1f98217139f12, - type: 3} - propertyPath: m_Name - value: BlackHole - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 81c113ab4fb3e22748b1f98217139f12, type: 3} --- !u!1001 &891862850 PrefabInstance: m_ObjectHideFlags: 0 @@ -1493,6 +1552,6 @@ SceneRoots: - {fileID: 1621186633} - {fileID: 1797347352} - {fileID: 1732242001} - - {fileID: 841514572} - {fileID: 1932692269} - {fileID: 1671091699} + - {fileID: 770231297} diff --git a/Assets/Scripts/Tower/ProjectileTower.cs b/Assets/Scripts/Tower/ProjectileTower.cs index bf2b48d..3a1d227 100644 --- a/Assets/Scripts/Tower/ProjectileTower.cs +++ b/Assets/Scripts/Tower/ProjectileTower.cs @@ -6,6 +6,9 @@ using UnityEngine.Assertions; public class ProjectileTower : Tower { + [SerializeField] protected EditableArc horizontalArc; + [SerializeField] protected EditableArc verticalArc; + [SerializeField, Range(0.01f, 20f)] private float attackSecondsDelay = 1f; [SerializeField] private ProjectilePattern[] projectileSequence; [SerializeField] private Barrel barrel; @@ -16,6 +19,10 @@ public class ProjectileTower : Tower private ProjectileSpawner projectileSpawner; public Vector3 AimDirection => barrel.transform.forward; + public Vector2 HorizontalRotationMinMax => horizontalArc.RotationMinMax; + public Vector2 VerticalRotationMinMax => verticalArc.RotationMinMax; + public float HorizontalRotation => horizontalArc.Value; + public float VerticalRotation => verticalArc.Value; protected override void Awake() { @@ -30,11 +37,18 @@ public class ProjectileTower : Tower horizontalArc.Value.AddListener(UpdateTrajectory); verticalArc.Value.AddListener(UpdateTrajectory); + horizontalArc.Value.AddListener(SnapVerticalToHorizontal); + UpdateBarrelRotation(); UpdateTrajectory(); StartCoroutine(AttackLoop()); } + private void SnapVerticalToHorizontal(float horizontalAngle) + { + verticalArc.transform.rotation = Quaternion.Euler(verticalArc.transform.rotation.eulerAngles.x, horizontalAngle, verticalArc.transform.rotation.eulerAngles.z); + } + private void UpdateTrajectory(float unused) => UpdateTrajectory(); private void UpdateTrajectory() @@ -65,6 +79,7 @@ public class ProjectileTower : Tower { horizontalArc.Value.RemoveListener(UpdateBarrelRotation); verticalArc.Value.RemoveListener(UpdateBarrelRotation); + horizontalArc.Value.RemoveListener(SnapVerticalToHorizontal); } private IEnumerator AttackLoop() diff --git a/Assets/Scripts/Tower/Tower.cs b/Assets/Scripts/Tower/Tower.cs index dbb6e66..f8f3a4f 100644 --- a/Assets/Scripts/Tower/Tower.cs +++ b/Assets/Scripts/Tower/Tower.cs @@ -5,33 +5,19 @@ public abstract class Tower : MonoBehaviour { public bool towerSelected { get; set; } = true; - [SerializeField] protected EditableArc horizontalArc; - [SerializeField] protected EditableArc verticalArc; - protected HealthComponent healthComp; // Getters - public Vector2 HorizontalRotationMinMax => horizontalArc.RotationMinMax; - public Vector2 VerticalRotationMinMax => verticalArc.RotationMinMax; - public float HorizontalRotation => horizontalArc.Value; - public float VerticalRotation => verticalArc.Value; protected virtual void Awake() { healthComp = GetComponent(); Assert.IsNotNull(healthComp); - - horizontalArc.Value.AddListener(SnapVerticalToHorizontal); } - private void SnapVerticalToHorizontal(float horizontalAngle) - { - verticalArc.transform.rotation = Quaternion.Euler(verticalArc.transform.rotation.eulerAngles.x, horizontalAngle, verticalArc.transform.rotation.eulerAngles.z); - } protected virtual void OnDestroy() { - horizontalArc.Value.RemoveListener(SnapVerticalToHorizontal); } protected virtual void Update() diff --git a/Assets/Scripts/Tower/TowerEditor.cs b/Assets/Scripts/Tower/TowerEditor.cs index 903aefd..6520c65 100644 --- a/Assets/Scripts/Tower/TowerEditor.cs +++ b/Assets/Scripts/Tower/TowerEditor.cs @@ -9,7 +9,7 @@ public class TowerEditor : Editor public void OnSceneGUI() { - var tower = (serializedObject.targetObject as Component).gameObject.GetComponent(); + var tower = (serializedObject.targetObject as Component).gameObject.GetComponent(); // Draw horizontal angle Handles.color = Color.red; From 3b804215bc2cbcb785a99aec3f3e161c6f26cbd5 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sat, 20 Apr 2024 19:38:01 +0200 Subject: [PATCH 2/2] Black hole --- Assets/Prefabs/Towers/BlackHole.prefab | 59 +++++++++++++++++++++-- Assets/Scenes/TowerTest.unity | 65 ++------------------------ 2 files changed, 58 insertions(+), 66 deletions(-) diff --git a/Assets/Prefabs/Towers/BlackHole.prefab b/Assets/Prefabs/Towers/BlackHole.prefab index e28e6c5..8974ea4 100644 --- a/Assets/Prefabs/Towers/BlackHole.prefab +++ b/Assets/Prefabs/Towers/BlackHole.prefab @@ -179,17 +179,17 @@ PrefabInstance: - target: {fileID: 527409087646353271, guid: f54a14318952c90c5b47a300aedb0d15, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: 3.2174833 objectReference: {fileID: 0} - target: {fileID: 527409087646353271, guid: f54a14318952c90c5b47a300aedb0d15, type: 3} propertyPath: m_LocalPosition.y - value: 0 + value: 1.0573871 objectReference: {fileID: 0} - target: {fileID: 527409087646353271, guid: f54a14318952c90c5b47a300aedb0d15, type: 3} propertyPath: m_LocalPosition.z - value: 0 + value: -0.8372203 objectReference: {fileID: 0} - target: {fileID: 527409087646353271, guid: f54a14318952c90c5b47a300aedb0d15, type: 3} @@ -242,7 +242,11 @@ PrefabInstance: type: 3} insertIndex: -1 addedObject: {fileID: 6791947043022790992} - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 872127579833310669, guid: f54a14318952c90c5b47a300aedb0d15, + type: 3} + insertIndex: -1 + addedObject: {fileID: 36692134324172431} m_SourcePrefab: {fileID: 100100000, guid: f54a14318952c90c5b47a300aedb0d15, type: 3} --- !u!4 &3798190417997420117 stripped Transform: @@ -250,3 +254,50 @@ Transform: type: 3} m_PrefabInstance: {fileID: 3739212318609641762} m_PrefabAsset: {fileID: 0} +--- !u!1 &4611178744751000815 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 872127579833310669, guid: f54a14318952c90c5b47a300aedb0d15, + type: 3} + m_PrefabInstance: {fileID: 3739212318609641762} + m_PrefabAsset: {fileID: 0} +--- !u!114 &36692134324172431 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4611178744751000815} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4fb850aad740b9b418ade5f74fff1818, type: 3} + m_Name: + m_EditorClassIdentifier: + radius: 1.5 + orb: {fileID: 6791947043022790992} + affectedBodies: + serializedVersion: 2 + m_Bits: 64 + distToAcceleration: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 20 + inSlope: -12.5 + outSlope: -12.5 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 7.5 + inSlope: -12.5 + outSlope: -12.5 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Assets/Scenes/TowerTest.unity b/Assets/Scenes/TowerTest.unity index f46d0c5..2e466c7 100644 --- a/Assets/Scenes/TowerTest.unity +++ b/Assets/Scenes/TowerTest.unity @@ -517,67 +517,8 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 4611178744751000815, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, - type: 3} - insertIndex: -1 - addedObject: {fileID: 770231300} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, type: 3} ---- !u!1 &770231298 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 4611178744751000815, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, - type: 3} - m_PrefabInstance: {fileID: 770231297} - m_PrefabAsset: {fileID: 0} ---- !u!4 &770231299 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 6791947043022790992, guid: 1d7949721a9f0bc9ba1a8c49ca5fd099, - type: 3} - m_PrefabInstance: {fileID: 770231297} - m_PrefabAsset: {fileID: 0} ---- !u!114 &770231300 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 770231298} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4fb850aad740b9b418ade5f74fff1818, type: 3} - m_Name: - m_EditorClassIdentifier: - horizontalArc: {fileID: 0} - verticalArc: {fileID: 0} - radius: 1 - orb: {fileID: 770231299} - affectedBodies: - serializedVersion: 2 - m_Bits: 64 - distToAcceleration: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: -0.5 - outSlope: -0.5 - tangentMode: 34 - weightedMode: 0 - inWeight: 0 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0.5 - inSlope: -0.5 - outSlope: -0.5 - tangentMode: 34 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 --- !u!1 &832575517 GameObject: m_ObjectHideFlags: 0 @@ -1224,7 +1165,7 @@ PrefabInstance: - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalRotation.w - value: -0.1380528 + value: -0.13805284 objectReference: {fileID: 0} - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} @@ -1239,7 +1180,7 @@ PrefabInstance: - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalRotation.z - value: -0.13815574 + value: -0.13815573 objectReference: {fileID: 0} - target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3}