select unselect tower

This commit is contained in:
Sveske Juice 2024-04-20 22:42:06 +02:00
parent 9ad8d6ee3e
commit 0ac1402616
8 changed files with 146 additions and 38 deletions

View File

@ -102,7 +102,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &3688593234855359137 --- !u!4 &3688593234855359137
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -624,7 +624,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &4508182228569071021 --- !u!4 &4508182228569071021
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -777,7 +777,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &2141594701022449211 --- !u!4 &2141594701022449211
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1076,6 +1076,9 @@ MonoBehaviour:
type: 3} type: 3}
trajectoryLine: {fileID: 3987931586699850031} trajectoryLine: {fileID: 3987931586699850031}
trajectoryObjectPoolSize: 25 trajectoryObjectPoolSize: 25
wallMask:
serializedVersion: 2
m_Bits: 257
attackSecondsDelay: 1 attackSecondsDelay: 1
projectileSequence: projectileSequence:
- Arc: 0 - Arc: 0

View File

@ -929,6 +929,51 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1395991985
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1395991987}
- component: {fileID: 1395991986}
m_Layer: 0
m_Name: gm
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1395991986
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1395991985}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 00e1f7ea5be7c564faf42d035aec7f53, type: 3}
m_Name:
m_EditorClassIdentifier:
IsBuildMode: 0
--- !u!4 &1395991987
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1395991985}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.1557862, y: 2.294486, z: 1.574348}
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 &1621186629 --- !u!1 &1621186629
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1185,6 +1230,11 @@ PrefabInstance:
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 11.533513 value: 11.533513
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
propertyPath: stopAfterTime
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
@ -1243,7 +1293,7 @@ PrefabInstance:
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3} type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: -0.1380528 value: -0.13805284
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3} type: 3}
@ -1258,7 +1308,7 @@ PrefabInstance:
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3} type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.13815574 value: -0.13815573
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3} type: 3}
@ -1313,7 +1363,11 @@ PrefabInstance:
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 6163557566655415017, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
insertIndex: -1
addedObject: {fileID: 1970787077}
m_SourcePrefab: {fileID: 100100000, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} m_SourcePrefab: {fileID: 100100000, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3}
--- !u!1 &1797347348 --- !u!1 &1797347348
GameObject: GameObject:
@ -1488,6 +1542,37 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 48ecac7381f19af3bab6fef54e6dbadc, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 48ecac7381f19af3bab6fef54e6dbadc, type: 3}
--- !u!1 &1970787075 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6163557566655415017, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
m_PrefabInstance: {fileID: 1732242001}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1970787077
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1970787075}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c2d4e884ed2ba0944bfe55454353bc2d, type: 3}
m_Name:
m_EditorClassIdentifier:
mainCamera: {fileID: 1970787082}
layerMask:
serializedVersion: 2
m_Bits: 1024
selectLayer:
serializedVersion: 2
m_Bits: 256
--- !u!20 &1970787082 stripped
Camera:
m_CorrespondingSourceObject: {fileID: 3255403189825384754, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
m_PrefabInstance: {fileID: 1732242001}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &667212637924654954 --- !u!1001 &667212637924654954
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1575,3 +1660,4 @@ SceneRoots:
- {fileID: 1671091699} - {fileID: 1671091699}
- {fileID: 770231297} - {fileID: 770231297}
- {fileID: 504816165} - {fileID: 504816165}
- {fileID: 1395991987}

View File

@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
@ -7,7 +5,15 @@ public class GameManager : MonoBehaviour
public static GameManager Instance; public static GameManager Instance;
public bool IsBuildMode = false; public bool IsBuildMode = false;
public Tower SelectedTower; private Tower selectedTower;
public Tower SelectedTower { get { return selectedTower; } set {
if (selectedTower != null)
selectedTower.TowerSelected(false);
selectedTower = value;
selectedTower.TowerSelected(true);
Debug.Log($"Selected: {selectedTower}");
}}
private void Awake() private void Awake()
{ {

View File

@ -30,12 +30,13 @@ public class CameraSlotClickDetect : MonoBehaviour
{ {
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>(); var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
slotInfo.OnClick(); slotInfo.OnClick();
GameManager.Instance.SelectedTower = null;
} }
RaycastHit selectHit; RaycastHit selectHit;
if (Physics.Raycast(ray, out selectHit, Mathf.Infinity, selectLayer)) if (Physics.Raycast(ray, out selectHit, Mathf.Infinity, selectLayer) && !GameManager.Instance.IsBuildMode)
{ {
var obj = selectHit.collider.gameObject.GetComponentInChildren<Tower>(); var tower = selectHit.collider.gameObject.GetComponentInChildren<Tower>();
obj.TowerSelected.Value = true; GameManager.Instance.SelectedTower = tower;
} }
} }

View File

@ -17,6 +17,7 @@ public class AimTower : Tower
[SerializeField] private GameObject ghostPrefab; [SerializeField] private GameObject ghostPrefab;
[SerializeField] private LineRenderer trajectoryLine; [SerializeField] private LineRenderer trajectoryLine;
[SerializeField] private int trajectoryObjectPoolSize = 25; [SerializeField] private int trajectoryObjectPoolSize = 25;
[SerializeField] private LayerMask wallMask;
private int poolIdx = 0; private int poolIdx = 0;
public Vector3 AimDirection => barrel.transform.forward; public Vector3 AimDirection => barrel.transform.forward;
@ -35,18 +36,18 @@ public class AimTower : Tower
horizontalArc.Value.AddListener(SnapVerticalToHorizontal); horizontalArc.Value.AddListener(SnapVerticalToHorizontal);
TowerSelected.AddListener(OnTowerSelected);
UpdateBarrelRotation(); UpdateBarrelRotation();
UpdateTrajectory(); UpdateTrajectory();
OnTowerSelected(TowerSelected);
} }
private void OnTowerSelected(bool selected) public override void TowerSelected(bool selected)
{ {
horizontalArc.enabled = selected; base.TowerSelected(selected);
verticalArc.enabled = selected;
trajectoryLine.enabled = selected; horizontalArc.gameObject.SetActive(selected);
verticalArc.gameObject.SetActive(selected);
trajectoryLine.gameObject.SetActive(selected);
UpdateTrajectory();
} }
protected override void OnDestroy() protected override void OnDestroy()
@ -77,9 +78,9 @@ public class AimTower : Tower
{ {
ghost.SetActive(false); ghost.SetActive(false);
} }
if (!this.selected) return;
if (!TowerSelected.Value) return; Debug.Log("UPAD");
Vector3 origin = barrel.Tip.position; Vector3 origin = barrel.Tip.position;
Vector3 dir = barrel.transform.forward; Vector3 dir = barrel.transform.forward;
List<Vector3> pointsInTrajectory = new(); List<Vector3> pointsInTrajectory = new();
@ -88,7 +89,7 @@ public class AimTower : Tower
{ {
Debug.DrawRay(origin, dir.normalized * k_trajectory_maxdist, Color.red, 5f); Debug.DrawRay(origin, dir.normalized * k_trajectory_maxdist, Color.red, 5f);
RaycastHit hit; RaycastHit hit;
if (!Physics.Raycast(origin, dir, out hit, k_trajectory_maxdist)) if (!Physics.Raycast(origin, dir, out hit, k_trajectory_maxdist, wallMask))
break; break;
pointsInTrajectory.Add(hit.point); pointsInTrajectory.Add(hit.point);

View File

@ -14,6 +14,16 @@ public class GravityTower : Tower
[SerializeField] [SerializeField]
private AnimationCurve distToAcceleration; private AnimationCurve distToAcceleration;
public override void TowerSelected(bool selected)
{
}
protected override void Awake()
{
base.Awake();
}
protected override void FixedUpdate() protected override void FixedUpdate()
{ {
Collider[] projectilesInRadius = Physics.OverlapSphere(orb.position, radius, affectedBodies); Collider[] projectilesInRadius = Physics.OverlapSphere(orb.position, radius, affectedBodies);
@ -25,4 +35,14 @@ public class GravityTower : Tower
projectileBody.AddForce(projToOrb.normalized * distToAcceleration.Evaluate(dist)); projectileBody.AddForce(projToOrb.normalized * distToAcceleration.Evaluate(dist));
} }
} }
protected override void OnDestroy()
{
base.OnDestroy();
}
protected override void Update()
{
base.Update();
}
} }

View File

@ -4,29 +4,20 @@ using UnityEngine.Assertions;
public abstract class Tower : MonoBehaviour public abstract class Tower : MonoBehaviour
{ {
public Observer<bool> TowerSelected { get; set; } = new(false); protected bool selected = false;
protected HealthComponent healthComp; protected HealthComponent healthComp;
// Getters // Getters
public virtual void TowerSelected(bool selected)
{
this.selected = selected;
}
protected virtual void Awake() protected virtual void Awake()
{ {
healthComp = GetComponent<HealthComponent>(); healthComp = GetComponent<HealthComponent>();
Assert.IsNotNull(healthComp); Assert.IsNotNull(healthComp);
TowerSelected.AddListener(DeselectTowers);
}
public static void DeselectTowers(bool selected)
{
if (selected)
{
foreach (var tower in GameObject.FindObjectsByType<Tower>(FindObjectsSortMode.None))
{
tower.TowerSelected.Value = false;
}
}
} }
protected virtual void OnDestroy() protected virtual void OnDestroy()

View File

@ -14,9 +14,9 @@ TagManager:
- UI - UI
- Projectile - Projectile
- -
- Tower
- -
- - Cell
-
- -
- -
- -