Level Grid
parent
3c0d9812f9
commit
208d2a2352
@ -1,11 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class GridObject {
|
||||
public GridObject(GridSystem gridSystem, GridPosition gridPosition) {
|
||||
GridSystem = gridSystem;
|
||||
GridPosition = gridPosition;
|
||||
UnitList = new();
|
||||
}
|
||||
|
||||
public GridSystem GridSystem { get; private set; }
|
||||
public GridPosition GridPosition { get; private set; }
|
||||
public List<Unit> UnitList { get; set; }
|
||||
|
||||
public override string ToString() => GridPosition.ToString();
|
||||
public override string ToString() {
|
||||
string unitString = UnitList.Aggregate("", (current, unit) => current + (unit + "\n"));
|
||||
return $"{GridPosition.ToString()}\n{unitString}";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelGrid : MonoBehaviour {
|
||||
[SerializeField] private Transform GridDebugObjectPrefab;
|
||||
|
||||
private GridSystem gridSystem;
|
||||
|
||||
public static LevelGrid Instance { get; private set; }
|
||||
|
||||
private void Awake() {
|
||||
if (Instance is not null) {
|
||||
Debug.LogError($"There is more than one LevelGrid! {transform} - {Instance}");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
gridSystem = new(10, 10, 2f);
|
||||
gridSystem.CreateDebugObjects(GridDebugObjectPrefab);
|
||||
}
|
||||
|
||||
public void AddUnitAtGridPosition(GridPosition gridPosition, Unit unit) => gridSystem.GetGridObject(gridPosition).UnitList.Add(unit);
|
||||
|
||||
public List<Unit> GetUnitListAtGridPosition(GridPosition gridPosition) => gridSystem.GetGridObject(gridPosition).UnitList;
|
||||
public void RemoveUnitAtGridPosition(GridPosition gridPosition, Unit unit) => gridSystem.GetGridObject(gridPosition).UnitList.Remove(unit);
|
||||
|
||||
public GridPosition GetGridPosition(Vector3 worldPosition) => gridSystem.GetGridPosition(worldPosition);
|
||||
|
||||
public void UnitMovedGridPosition(Unit unit, GridPosition fromGridPosition, GridPosition toGridPosition) {
|
||||
RemoveUnitAtGridPosition(fromGridPosition, unit);
|
||||
AddUnitAtGridPosition(toGridPosition, unit);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a133b47a7f2fe5e4a125626d7df416f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,15 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Testing : MonoBehaviour {
|
||||
[SerializeField] private Transform GridDebugObjectPrefab;
|
||||
private void Start() { }
|
||||
|
||||
private GridSystem gridSystem;
|
||||
|
||||
private void Start() {
|
||||
gridSystem = new GridSystem(10, 10, 2f);
|
||||
gridSystem.CreateDebugObjects(GridDebugObjectPrefab);
|
||||
Debug.Log(new GridPosition(5, 7));
|
||||
}
|
||||
|
||||
private void Update() => Debug.Log(gridSystem.GetGridPosition(MouseWorld.GetPosition()));
|
||||
private void Update() { }
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue