Move tower aim to projectile tower

This commit is contained in:
Sveske Juice 2024-04-20 19:33:01 +02:00
parent e67416be15
commit ac1b5dccfa
4 changed files with 144 additions and 84 deletions

View File

@ -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}

View File

@ -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()

View File

@ -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<HealthComponent>();
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()

View File

@ -9,7 +9,7 @@ public class TowerEditor : Editor
public void OnSceneGUI()
{
var tower = (serializedObject.targetObject as Component).gameObject.GetComponent<Tower>();
var tower = (serializedObject.targetObject as Component).gameObject.GetComponent<ProjectileTower>();
// Draw horizontal angle
Handles.color = Color.red;