maint: added livewatch asset

This commit is contained in:
Chris
2025-08-31 18:14:07 -04:00
parent 7f5d95787b
commit ae2371a6fa
385 changed files with 150792 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using System.Collections;
using UnityEngine;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class LaserEffect : MonoBehaviour
{
[SerializeField] private float _duration = 0.05f;
[SerializeField] private GameObject _laserBeam;
public void Play(Vector3 target)
{
target += Vector3.up * 0.5f;
var dist = (target - transform.position).magnitude;
transform.LookAt(target);
_laserBeam.transform.localScale = new Vector3(
_laserBeam.transform.localScale.x,
_laserBeam.transform.localScale.y,
dist/2f);
StopAllCoroutines();
StartCoroutine(ShowAndHide());
}
private IEnumerator ShowAndHide()
{
_laserBeam.SetActive(true);
yield return new WaitForSeconds(_duration);
_laserBeam.SetActive(false);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fc9b506708f84dc285684ec1f66a4793
timeCreated: 1726323107
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/LaserEffect.cs
uploadId: 770587

View File

@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class LaserTower : TowerBase
{
public override TowerType Type => TowerType.Laser;
[SerializeField] private float _cooldown = 0.5f;
[SerializeField] private int _damage = 5;
[SerializeField] private float _radius = 4f;
[SerializeField] private Transform _turretPivot;
[SerializeField] private ParticleSystem _laserEffect;
private LevelScene _levelScene;
private bool _isActive;
private float _lastFireTime;
private float _lastTargetUpdateTime;
private Vector2 ourPos => new Vector2(transform.position.x, transform.position.z);
private MobMain _previousTarget;
private const float targetFindCooldown = 0.05f;
private const float rotationSpeed = 5;
public override void Enable(LevelScene levelScene)
{
_isActive = true;
_lastFireTime = Time.time;
_levelScene = levelScene;
}
public override void Disable()
{
_isActive = false;
}
private void OnDrawGizmos()
{
Gizmos.DrawWireSphere(transform.position, _radius);
}
private void Update()
{
if (!_isActive)
return;
UpdateRotation();
if (Time.time < _lastFireTime + _cooldown)
return;
_lastFireTime = Time.time;
Fire();
}
private void UpdateRotation()
{
if (Time.time > _lastTargetUpdateTime + targetFindCooldown)
_previousTarget = FindNearestTarget();
if (_previousTarget == null || !_previousTarget.IsAlive)
return;
var targetDirection = _previousTarget.transform.position - _turretPivot.position;
var directionNew = Vector3.Slerp(_turretPivot.forward, targetDirection, Time.unscaledDeltaTime * rotationSpeed);
_turretPivot.forward = directionNew;
}
private MobMain FindNearestTarget()
{
MobMain targetMob = null;
foreach (var mob in _levelScene.MobManager.Mobs)
{
var mobPos = new Vector2(mob.transform.position.x, mob.transform.position.z);
var sqrDist = (mobPos - ourPos).sqrMagnitude;
if (sqrDist > _radius * _radius)
continue;
if (targetMob == null || mob.WaypointMover.TravelledDist > targetMob.WaypointMover.TravelledDist)
{
targetMob = mob;
}
}
return targetMob;
}
private void Fire()
{
var targetMob = FindNearestTarget();
if (targetMob != null)
{
if (targetMob.Health.CurrentHealth <= _damage)
Watch.Push("MobLog", $"{targetMob.Id} killed by {Id}")
.SetSortOrder(TD_WatchSortOrder.MobLog)
;
_turretPivot.forward = targetMob.transform.position - _turretPivot.position;
_laserEffect.transform.LookAt(targetMob.transform.position);
_laserEffect.Play();
targetMob.Health.TakeDamage(_damage);
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 163f0a04a378463a841d7ad2758ad6ad
timeCreated: 1726318386
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/LaserTower.cs
uploadId: 770587

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class ShockwaveTower : TowerBase
{
public override TowerType Type => TowerType.Shockwave;
[SerializeField] private float _cooldown = 1f;
[SerializeField] private int _damage = 20;
[SerializeField] private float _radius = 3f;
[SerializeField] private ParticleSystem _waveEffect;
private LevelScene _levelScene;
private bool _isActive;
private float _lastFireTime;
private Vector2 ourPos => new Vector2(transform.position.x, transform.position.z);
private List<MobMain> _pendingDamageMobs = new();
public override void Enable(LevelScene levelScene)
{
_isActive = true;
_lastFireTime = Time.time;
_levelScene = levelScene;
}
public override void Disable()
{
_isActive = false;
}
private void OnDrawGizmos()
{
Gizmos.DrawWireSphere(transform.position, _radius);
}
private void Update()
{
if (!_isActive)
return;
if (Time.time < _lastFireTime + _cooldown)
return;
_lastFireTime = Time.time;
Fire();
}
private void Fire()
{
_pendingDamageMobs.Clear();
foreach (var mob in _levelScene.MobManager.Mobs)
{
var mobPos = new Vector2(mob.transform.position.x, mob.transform.position.z);
var sqrDist = (mobPos - ourPos).sqrMagnitude;
if (sqrDist > _radius * _radius)
continue;
_pendingDamageMobs.Add(mob);
}
foreach (var mob in _pendingDamageMobs)
{
if (mob.Health.CurrentHealth <= _damage)
{
Watch.Push("MobLog", $"{mob.Id} killed by {Id}")
.SetSortOrder(TD_WatchSortOrder.MobLog)
;
}
mob.Health.TakeDamage(_damage);
}
_waveEffect.Play();
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 59b5965df77a462a9425484fb3d9f8f9
timeCreated: 1725990226
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/ShockwaveTower.cs
uploadId: 770587

View File

@@ -0,0 +1,12 @@
using UnityEngine;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public abstract class TowerBase : MonoBehaviour
{
public string Id { get; set; }
public abstract TowerType Type { get; }
public abstract void Enable(LevelScene levelScene);
public abstract void Disable();
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3e0632d72869458bbc6ea2eb55f19201
timeCreated: 1725990613
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/TowerBase.cs
uploadId: 770587

View File

@@ -0,0 +1,8 @@
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public enum TowerType
{
Shockwave,
Laser
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d9c13752bd084cdb978f2a51ce953371
timeCreated: 1726052989
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/TowerType.cs
uploadId: 770587

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class WaveEffect : MonoBehaviour
{
[SerializeField] private float _growDuration = 0.1f;
[SerializeField] private float _stayDuration = 0.1f;
[SerializeField] private Transform _wave;
private float _radius;
private Coroutine _effectRoutine;
private void OnEnable()
{
SetSizeRaw(0);
}
public void SetRadius(float radius)
{
_radius = radius;
}
public void Play()
{
SetSizeRaw(0);
if (_effectRoutine != null)
StopCoroutine(_effectRoutine);
_effectRoutine = StartCoroutine(EffectPlaying());
}
private IEnumerator EffectPlaying()
{
SetSizeRaw(0);
var timer = _growDuration;
while (timer >= 0)
{
timer -= Time.deltaTime;
var progress = 1 - timer / _growDuration;
SetSizeRaw(_radius * progress);
yield return null;
}
yield return new WaitForSeconds(_stayDuration);
SetSizeRaw(0);
}
private void SetSizeRaw(float value)
{
_wave.localScale = value * Vector3.one;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fad3a9a7a9ac406ab0618ee81f7d420f
timeCreated: 1725993754
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Tower/WaveEffect.cs
uploadId: 770587