This commit is contained in:
Sveske Juice 2024-04-20 22:19:23 +02:00
parent 73e2459342
commit ac03089c25
7 changed files with 50 additions and 49 deletions

View File

@ -63,6 +63,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: BaseTower value: BaseTower
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: eb5e13df78999ef878da1db5c63224e2,
type: 3}
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: m_RemovedGameObjects:
- {fileID: -3133498875991405556, guid: eb5e13df78999ef878da1db5c63224e2, type: 3} - {fileID: -3133498875991405556, guid: eb5e13df78999ef878da1db5c63224e2, type: 3}

View File

@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 6791947043022790992} - component: {fileID: 6791947043022790992}
- component: {fileID: 283773815913351468} - component: {fileID: 283773815913351468}
- component: {fileID: 7403195583508196174} - component: {fileID: 7403195583508196174}
m_Layer: 0 m_Layer: 8
m_Name: Sphere m_Name: Sphere
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -94,7 +94,7 @@ GameObject:
- component: {fileID: 5119260969314287638} - component: {fileID: 5119260969314287638}
- component: {fileID: 6992152662476368078} - component: {fileID: 6992152662476368078}
- component: {fileID: 8324639096253395440} - component: {fileID: 8324639096253395440}
m_Layer: 0 m_Layer: 8
m_Name: Cylinder.002 m_Name: Cylinder.002
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}

View File

@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 7260327517591084354} - component: {fileID: 7260327517591084354}
- component: {fileID: 5566712258885047037} - component: {fileID: 5566712258885047037}
- component: {fileID: 3451839468339987846} - component: {fileID: 3451839468339987846}
m_Layer: 0 m_Layer: 8
m_Name: Base m_Name: Base
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -96,7 +96,7 @@ GameObject:
- component: {fileID: 3688593234855359137} - component: {fileID: 3688593234855359137}
- component: {fileID: 7215452495559205732} - component: {fileID: 7215452495559205732}
- component: {fileID: 8981486734084153558} - component: {fileID: 8981486734084153558}
m_Layer: 0 m_Layer: 8
m_Name: HorizontalArc m_Name: HorizontalArc
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -252,7 +252,7 @@ GameObject:
- component: {fileID: 432796252682377629} - component: {fileID: 432796252682377629}
- component: {fileID: 3370533879401949812} - component: {fileID: 3370533879401949812}
- component: {fileID: 1398471167256814047} - component: {fileID: 1398471167256814047}
m_Layer: 0 m_Layer: 8
m_Name: SliderKnob m_Name: SliderKnob
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -367,7 +367,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 3410229124093629554} - component: {fileID: 3410229124093629554}
m_Layer: 0 m_Layer: 8
m_Name: Tip m_Name: Tip
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -402,7 +402,7 @@ GameObject:
- component: {fileID: 271800776993535811} - component: {fileID: 271800776993535811}
- component: {fileID: 1616640625290415239} - component: {fileID: 1616640625290415239}
- component: {fileID: 8756968480882234867} - component: {fileID: 8756968480882234867}
m_Layer: 0 m_Layer: 8
m_Name: SliderKnob m_Name: SliderKnob
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -508,37 +508,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9998882d4b72010a9b0ca2d8bd35835e, type: 3} m_Script: {fileID: 11500000, guid: 9998882d4b72010a9b0ca2d8bd35835e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1 &3857615556319596175
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2164222606230954140}
m_Layer: 0
m_Name: Tip
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2164222606230954140
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3857615556319596175}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0, y: 0, z: 0.00771}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 9116936080776508834}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &7405500333329299342 --- !u!1 &7405500333329299342
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -551,7 +520,7 @@ GameObject:
- component: {fileID: 1325528991062417693} - component: {fileID: 1325528991062417693}
- component: {fileID: 7013367250967747671} - component: {fileID: 7013367250967747671}
- component: {fileID: 2740722787380423134} - component: {fileID: 2740722787380423134}
m_Layer: 0 m_Layer: 8
m_Name: Barrel m_Name: Barrel
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -649,7 +618,7 @@ GameObject:
- component: {fileID: 4508182228569071021} - component: {fileID: 4508182228569071021}
- component: {fileID: 1366289561210151836} - component: {fileID: 1366289561210151836}
- component: {fileID: 5247639431516572416} - component: {fileID: 5247639431516572416}
m_Layer: 0 m_Layer: 8
m_Name: VerticalArc m_Name: VerticalArc
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -802,7 +771,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 2141594701022449211} - component: {fileID: 2141594701022449211}
- component: {fileID: 3987931586699850031} - component: {fileID: 3987931586699850031}
m_Layer: 0 m_Layer: 8
m_Name: TrajectoryLine m_Name: TrajectoryLine
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -1057,10 +1026,6 @@ PrefabInstance:
type: 3} type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 3688593234855359137} addedObject: {fileID: 3688593234855359137}
- targetCorrespondingSourceObject: {fileID: 527409087646353271, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
insertIndex: -1
addedObject: {fileID: 2164222606230954140}
m_AddedComponents: m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 872127579833310669, guid: f54a14318952c90c5b47a300aedb0d15, - targetCorrespondingSourceObject: {fileID: 872127579833310669, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3} type: 3}

View File

@ -7,6 +7,7 @@ public class CameraSlotClickDetect : MonoBehaviour
{ {
public Camera mainCamera; public Camera mainCamera;
public LayerMask layerMask; public LayerMask layerMask;
public LayerMask selectLayer;
private SlotManager PrevHoveredSlot; private SlotManager PrevHoveredSlot;
@ -30,6 +31,12 @@ public class CameraSlotClickDetect : MonoBehaviour
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>(); var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
slotInfo.OnClick(); slotInfo.OnClick();
} }
RaycastHit selectHit;
if (Physics.Raycast(ray, out selectHit, Mathf.Infinity, selectLayer))
{
var obj = selectHit.collider.gameObject.GetComponentInChildren<Tower>();
obj.TowerSelected.Value = true;
}
} }
void ShootHoverRay() void ShootHoverRay()

View File

@ -1,3 +1,4 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -24,7 +25,6 @@ public class AimTower : Tower
public float HorizontalRotation => horizontalArc.Value; public float HorizontalRotation => horizontalArc.Value;
public float VerticalRotation => verticalArc.Value; public float VerticalRotation => verticalArc.Value;
protected override void Awake() protected override void Awake()
{ {
horizontalArc.Value.AddListener(UpdateBarrelRotation); horizontalArc.Value.AddListener(UpdateBarrelRotation);
@ -35,8 +35,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)
{
horizontalArc.enabled = selected;
verticalArc.enabled = selected;
trajectoryLine.enabled = selected;
} }
protected override void OnDestroy() protected override void OnDestroy()
@ -68,6 +78,8 @@ public class AimTower : Tower
ghost.SetActive(false); ghost.SetActive(false);
} }
if (!TowerSelected.Value) return;
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();
@ -84,7 +96,6 @@ public class AimTower : Tower
origin = hit.point; origin = hit.point;
} }
trajectoryLine.positionCount = pointsInTrajectory.Count; trajectoryLine.positionCount = pointsInTrajectory.Count;
trajectoryLine.SetPositions(pointsInTrajectory.ToArray()); trajectoryLine.SetPositions(pointsInTrajectory.ToArray());

View File

@ -45,7 +45,7 @@ public class Projectile : MonoBehaviour
private void OnCollisionEnter(Collision collision) private void OnCollisionEnter(Collision collision)
{ {
HealthComponent hitHealthComp = collision.gameObject.GetComponent<HealthComponent>(); HealthComponent hitHealthComp = collision.gameObject.GetComponent<HealthComponent>();
if (hitHealthComp == comingFrom) return; // if (hitHealthComp == comingFrom) return;
if (hitHealthComp) if (hitHealthComp)
{ {
hitHealthComp.TakeDamage(damage); hitHealthComp.TakeDamage(damage);

View File

@ -1,9 +1,10 @@
using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions; using UnityEngine.Assertions;
public abstract class Tower : MonoBehaviour public abstract class Tower : MonoBehaviour
{ {
public bool towerSelected { get; set; } = true; public Observer<bool> TowerSelected { get; set; } = new(false);
protected HealthComponent healthComp; protected HealthComponent healthComp;
@ -13,8 +14,20 @@ public abstract class Tower : MonoBehaviour
{ {
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()
{ {