Initial Commit

This commit is contained in:
2026-03-19 11:57:23 +00:00
commit f19100a166
3800 changed files with 3008160 additions and 0 deletions

25
Assets/Scripts/Player.cs Normal file
View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Player : MonoBehaviour
{
[Header("Units")]
public List<Unit> units = new List<Unit>();
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//is this my unit?
public bool IsMyUnit(Unit unit)
{
return units.Contains(unit);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6ea3fcb1ceb3ba74da2ee9ceba7667f6

View File

@@ -0,0 +1,17 @@
using UnityEngine;
public class SelectionMarker : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6a8f32ff27a2db046802396bb5ddeeb4

22
Assets/Scripts/Unit.cs Normal file
View File

@@ -0,0 +1,22 @@
using UnityEngine;
public class Unit : MonoBehaviour
{
[Header("Components")]
public GameObject selectionVisual;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void ToggleSelectionVisual(bool selected)
{
selectionVisual.SetActive(selected);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5f8b0e87bcbd4604bbd5586aaa650b48

View File

@@ -0,0 +1,16 @@
using UnityEngine;
public class UnitCommander : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fa6dc96105d46ae44b9f4384031dd38f

View File

@@ -0,0 +1,16 @@
using UnityEngine;
public class UnitMover : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ae3471825595e3e4d9674cbde78fa3e8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
using UnityEngine;
using System.Collections.Generic;
using System;
public class UnitSelection : MonoBehaviour
{
public LayerMask unitLayerMask;
private List<Unit> selectedUnits = new List<Unit>();
public RectTransform selectionBox;
private Vector2 startPos;
//components
private Camera cam;
private Player player;
void Awake()
{
//get the components
cam = Camera.main;
player = GetComponent<Player>();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
//mouse up
if(Input.GetMouseButtonUp(0))
{
ReleaseSelectionBox();
}
//mouse held down
if(Input.GetMouseButton(0))
{
UpdateSelectionBox(Input.mousePosition);
}
//mouse down
if(Input.GetMouseButtonDown(0))
{
startPos = Input.mousePosition;
ToggleSelectionVisual(false);
selectedUnits = new List<Unit>();
TrySelect(Input.mousePosition);
}
}
//called when we release the selection box
void ReleaseSelectionBox()
{
selectionBox.gameObject.SetActive(false);
Vector2 min = selectionBox.anchoredPosition - (selectionBox.sizeDelta / 2);
Vector2 max = selectionBox.anchoredPosition + (selectionBox.sizeDelta / 2);
foreach(Unit unit in player.units)
{
Vector3 screenPos = cam.WorldToScreenPoint(unit.transform.position);
if(screenPos.x > min.x && screenPos.x < max.x && screenPos.y > min.y && screenPos.y < max.y)
{
selectedUnits.Add(unit);
unit.ToggleSelectionVisual(true);
}
}
}
//called when we are creating a selection box
void UpdateSelectionBox(Vector2 curMousePos)
{
if(!selectionBox.gameObject.activeInHierarchy)
selectionBox.gameObject.SetActive(true);
float width = curMousePos.x - startPos.x;
float height = curMousePos.y - startPos.y;
selectionBox.sizeDelta = new Vector2(MathF.Abs(width), Mathf.Abs(height));
selectionBox.anchoredPosition = startPos + new Vector2(width / 2, height / 2);
}
//called when we click on a unit
private void TrySelect(Vector2 screenPos)
{
Ray ray = cam.ScreenPointToRay(screenPos);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100, unitLayerMask))
{
Unit unit = hit.collider.GetComponent<Unit>();
if(player.IsMyUnit(unit))
{
selectedUnits.Add(unit);
unit.ToggleSelectionVisual(true);
}
}
}
void ToggleSelectionVisual(bool selected)
{
foreach(Unit unit in selectedUnits)
{
unit.ToggleSelectionVisual(selected);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 674a6053cb5f7904b8a919dd5c35807d