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,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
[Serializable]
public abstract class BasePopupUI : MonoBehaviour
{
public bool IsOpened { get; private set; }
[SerializeField] protected bool _closeByClickOutside = true;
[SerializeField] protected bool _lookAtCamera = true;
[SerializeField] protected GameObject _panel;
protected LevelScene _levelScene;
private Camera _mainCamera;
private bool _skipNextClick;
private HashSet<GameObject> _clickableChilds;
protected virtual void Awake()
{
_levelScene = FindObjectOfType<LevelScene>();
_clickableChilds = GetComponentsInChildren<Selectable>().Select(s => s.gameObject).ToHashSet();
_mainCamera = Camera.main;
}
private void Start()
{
if (_lookAtCamera)
{
transform.rotation = _mainCamera.transform.rotation;
}
OnCreated();
}
protected virtual void Update()
{
if (IsOpened
&& _closeByClickOutside
&& Input.GetMouseButtonDown(0)
&& !_clickableChilds.Contains(EventSystem.current.currentSelectedGameObject))
{
if (_skipNextClick)
_skipNextClick = false;
else
Close();
}
}
protected virtual void OnCreated()
{
}
protected virtual void OnOpened()
{
}
protected virtual void OnClosed()
{
}
public void Open()
{
if (IsOpened)
return;
IsOpened = true;
_skipNextClick = true;
_panel.SetActive(true);
OnOpened();
}
public void Close()
{
if (!IsOpened)
return;
OnClosed();
IsOpened = false;
_panel.SetActive(false);
}
}
}

View File

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

View File

@@ -0,0 +1,16 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class ClickableObject : MonoBehaviour
{
public event Action Clicked;
private void OnMouseDown()
{
Clicked?.Invoke();
}
}
}

View File

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

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class TowerBuildSlot : MonoBehaviour
{
public event Action OccupationChanged;
public bool IsOccupied
{
get => _isOccupied;
protected set
{
if (_isOccupied == value)
return;
_isOccupied = value;
OccupationChanged?.Invoke();
}
}
public int Id { get; private set; }
public TowerBase Tower { get; protected set; }
public Vector3 BuildLocation => transform.position;
[SerializeField] private GameObject _emptyStateObj;
private WatchReference<Any> slotWatch;
public void Init(int id)
{
Id = id;
slotWatch = Watch.GetOrAdd<Any>("TowerSlots").GetOrAdd<Any>(Id.ToString());
slotWatch.GetOrAdd("IsOccupied", () => IsOccupied);
}
public void Occupy(TowerBase tower)
{
Tower = tower;
IsOccupied = true;
_emptyStateObj.SetActive(false);
Watch.Push(slotWatch.GetOrAdd<string>("TowerId"), tower.Id);
}
public void Empty()
{
IsOccupied = false;
Tower = null;
_emptyStateObj.SetActive(true);
slotWatch.GetOrAdd<string>("TowerId").PushEmptyValue();
}
private bool _isOccupied;
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: fd36162806e5e204ba7176b2cb055a6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/TowerDefenceDemo/Scripts/Slot/TowerBuildSlot.cs
uploadId: 770587

View File

@@ -0,0 +1,56 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class TowerBuildSlotUIHandler : MonoBehaviour
{
[SerializeField] private TowerBuildSlot _targetSlot;
[SerializeField] private ClickableObject _slotClickable;
[SerializeField] private TowerSlotBuildPopupUI _buildUI;
[SerializeField] private TowerSlotDestroyPopupUI _destroyUI;
private void Awake()
{
_buildUI.TargetSlot = _targetSlot;
_destroyUI.TargetSlot = _targetSlot;
}
private void OnEnable()
{
_slotClickable.Clicked += OnSlotClicked;
_targetSlot.OccupationChanged += OnSlotOccupied;
}
private void OnDisable()
{
_slotClickable.Clicked -= OnSlotClicked;
_targetSlot.OccupationChanged -= OnSlotOccupied;
}
private void OnSlotClicked()
{
if (_targetSlot.IsOccupied)
{
_destroyUI.Open();
}
else
{
_buildUI.Open();
}
}
private void OnSlotOccupied()
{
if (_targetSlot.IsOccupied)
{
_buildUI.Close();
}
else
{
_destroyUI.Close();
}
}
}
}

View File

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

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class TowerSlotBuildPopupUI : BasePopupUI
{
[SerializeField] private List<BuildButton> _buildButtons = new();
public TowerBuildSlot TargetSlot { get; set; }
protected override void OnOpened()
{
base.OnOpened();
_levelScene.EnergyManager.EnergyChanged += OnEnergyChanged;
foreach (var buildButton in _buildButtons)
{
RefreshButton(buildButton);
buildButton.Button.onClick.AddListener(() => OnButtonClicked(buildButton));
}
}
protected override void OnClosed()
{
base.OnClosed();
_levelScene.EnergyManager.EnergyChanged -= OnEnergyChanged;
foreach (var buildButton in _buildButtons)
{
buildButton.Button.onClick.RemoveAllListeners();
}
}
private void RefreshButton(BuildButton buildButton)
{
var price = _levelScene.EconomyConfig.TowerBuildCosts[buildButton.Type];
var playerEnergy = _levelScene.EnergyManager.CurrentEnergy;
buildButton.Button.interactable = playerEnergy >= price;
buildButton.Text.text = $"{buildButton.Type}{Environment.NewLine}COST: -{price}".ToUpper();
}
private void OnEnergyChanged()
{
foreach (var buildButton in _buildButtons)
RefreshButton(buildButton);
}
private void OnButtonClicked(BuildButton buildButton)
{
_levelScene.TowerBuildManager.BuildTower(TargetSlot, buildButton.Type);
}
[Serializable]
public class BuildButton
{
[FormerlySerializedAs("Tower")] public TowerType Type;
public Button Button;
public Text Text;
}
}
}

View File

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

View File

@@ -0,0 +1,36 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Ingvar.LiveWatch.TowerDefenceDemo
{
public class TowerSlotDestroyPopupUI : BasePopupUI
{
public TowerBuildSlot TargetSlot { get; set; }
[SerializeField] private Button sellButton;
[SerializeField] private Text sellPriceText;
protected override void OnOpened()
{
base.OnOpened();
var sellPrice = _levelScene.EconomyConfig.TowerSellPrices[TargetSlot.Tower.Type];
sellPriceText.text = $"Destroy{Environment.NewLine}+{sellPrice}".ToUpper();
sellButton.onClick.AddListener(OnSellClicked);
}
protected override void OnClosed()
{
base.OnClosed();
sellButton.onClick.RemoveListener(OnSellClicked);
}
private void OnSellClicked()
{
_levelScene.TowerBuildManager.DestroyTower(TargetSlot);
}
}
}

View File

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