Added new assets
This commit is contained in:
@@ -7,7 +7,6 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
public Map GameMap;
|
||||
public PlayerManager Player;
|
||||
public Dictionary<StatsId, Stat> PlayerStats;
|
||||
// Start is called before the first frame update
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ad524142fef4ea41af294d55fb4c340
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,33 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GridBuildingSystem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform _testTransform;
|
||||
private GridXZ<GridObject> _grid;
|
||||
private void Awake()
|
||||
{
|
||||
int gridWidth = 10;
|
||||
int gridHeight = 10;
|
||||
float cellSize = 10f;
|
||||
|
||||
_grid = new GridXZ<GridObject>(gridWidth, gridHeight, cellSize, Vector3.zero, (GridXZ<GridObject> g, int x, int z) => new GridObject(g, x, z));
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
_grid.GetXZ(Mouse3d.GetMouseWorldPosition(), out int x, out int z);
|
||||
var gridObject = _grid.GetGridObject(x, z);
|
||||
if (gridObject.CanPlace())
|
||||
{
|
||||
var transform = Instantiate(_testTransform, _grid.GetWorldPosition(x, z), Quaternion.identity);
|
||||
gridObject.SetTransform(transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Can't place item here !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a18076dea00d39a4d8242bb7d35b4c61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GridObject
|
||||
{
|
||||
private GridXZ<GridObject> _grid;
|
||||
private int _x;
|
||||
private int _z;
|
||||
private Transform _transform;
|
||||
|
||||
|
||||
public GridObject(GridXZ<GridObject> grid, int x, int z)
|
||||
{
|
||||
_grid = grid;
|
||||
_x = x;
|
||||
_z = z;
|
||||
}
|
||||
|
||||
public void SetTransform(Transform transform)
|
||||
{
|
||||
_transform = transform;
|
||||
_grid.TriggerGridObjectChanged(_x, _z);
|
||||
}
|
||||
|
||||
public void ClearTransform()
|
||||
{
|
||||
_transform = null;
|
||||
_grid.TriggerGridObjectChanged(_x, _z);
|
||||
}
|
||||
|
||||
public bool CanPlace()
|
||||
{
|
||||
return _transform == null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _x + "," + _z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f2d010b7a2027743b08242c203a8f06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
------------------- Code Monkey -------------------
|
||||
|
||||
Thank you for downloading this package
|
||||
I hope you find it useful in your projects
|
||||
If you have any questions let me know
|
||||
Cheers!
|
||||
|
||||
unitycodemonkey.com
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class GridXZ<TGridObject>
|
||||
{
|
||||
|
||||
public event EventHandler<OnGridObjectChangedEventArgs> OnGridObjectChanged;
|
||||
public class OnGridObjectChangedEventArgs : EventArgs
|
||||
{
|
||||
public int x;
|
||||
public int z;
|
||||
}
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private float cellSize;
|
||||
private Vector3 originPosition;
|
||||
private TGridObject[,] gridArray;
|
||||
|
||||
public GridXZ(int width, int height, float cellSize, Vector3 originPosition, Func<GridXZ<TGridObject>, int, int, TGridObject> createGridObject)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.cellSize = cellSize;
|
||||
this.originPosition = originPosition;
|
||||
|
||||
gridArray = new TGridObject[width, height];
|
||||
|
||||
for (int x = 0; x < gridArray.GetLength(0); x++)
|
||||
{
|
||||
for (int z = 0; z < gridArray.GetLength(1); z++)
|
||||
{
|
||||
gridArray[x, z] = createGridObject(this, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
bool showDebug = true;
|
||||
if (showDebug)
|
||||
{
|
||||
TextMesh[,] debugTextArray = new TextMesh[width, height];
|
||||
|
||||
for (int x = 0; x < gridArray.GetLength(0); x++)
|
||||
{
|
||||
for (int z = 0; z < gridArray.GetLength(1); z++)
|
||||
{
|
||||
Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x, z + 1), Color.white, 100f);
|
||||
Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x + 1, z), Color.white, 100f);
|
||||
}
|
||||
}
|
||||
Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
|
||||
Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
|
||||
|
||||
OnGridObjectChanged += (object sender, OnGridObjectChangedEventArgs eventArgs) =>
|
||||
{
|
||||
debugTextArray[eventArgs.x, eventArgs.z].text = gridArray[eventArgs.x, eventArgs.z]?.ToString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public int GetWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int GetHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public float GetCellSize()
|
||||
{
|
||||
return cellSize;
|
||||
}
|
||||
|
||||
public Vector3 GetWorldPosition(int x, int z)
|
||||
{
|
||||
return new Vector3(x, 0, z) * cellSize + originPosition;
|
||||
}
|
||||
|
||||
public void GetXZ(Vector3 worldPosition, out int x, out int z)
|
||||
{
|
||||
x = Mathf.FloorToInt((worldPosition - originPosition).x / cellSize);
|
||||
z = Mathf.FloorToInt((worldPosition - originPosition).z / cellSize);
|
||||
}
|
||||
|
||||
public void SetGridObject(int x, int z, TGridObject value)
|
||||
{
|
||||
if (x >= 0 && z >= 0 && x < width && z < height)
|
||||
{
|
||||
gridArray[x, z] = value;
|
||||
TriggerGridObjectChanged(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerGridObjectChanged(int x, int z)
|
||||
{
|
||||
OnGridObjectChanged?.Invoke(this, new OnGridObjectChangedEventArgs { x = x, z = z });
|
||||
}
|
||||
|
||||
public void SetGridObject(Vector3 worldPosition, TGridObject value)
|
||||
{
|
||||
GetXZ(worldPosition, out int x, out int z);
|
||||
SetGridObject(x, z, value);
|
||||
}
|
||||
|
||||
public TGridObject GetGridObject(int x, int z)
|
||||
{
|
||||
if (x >= 0 && z >= 0 && x < width && z < height)
|
||||
{
|
||||
return gridArray[x, z];
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(TGridObject);
|
||||
}
|
||||
}
|
||||
|
||||
public TGridObject GetGridObject(Vector3 worldPosition)
|
||||
{
|
||||
int x, z;
|
||||
GetXZ(worldPosition, out x, out z);
|
||||
return GetGridObject(x, z);
|
||||
}
|
||||
|
||||
public Vector2Int ValidateGridPosition(Vector2Int gridPosition)
|
||||
{
|
||||
return new Vector2Int(
|
||||
Mathf.Clamp(gridPosition.x, 0, width - 1),
|
||||
Mathf.Clamp(gridPosition.y, 0, height - 1)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6f5d126221c69c4f904305c550ba857
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,33 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Mouse3d : MonoBehaviour
|
||||
{
|
||||
public static Mouse3d Instance { get; private set; }
|
||||
[SerializeField] private LayerMask _mouseColliderLayerMask = new LayerMask();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
_mouseColliderLayerMask = transform.gameObject.layer;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 999f, _mouseColliderLayerMask))
|
||||
{
|
||||
transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
public static Vector3 GetMouseWorldPosition() => Instance.GetMouseWorldPosition_Instance();
|
||||
private Vector3 GetMouseWorldPosition_Instance()
|
||||
{
|
||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 999f, _mouseColliderLayerMask))
|
||||
{
|
||||
return hit.point;
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using Assets.Scripts.Buildings;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Map
|
||||
{
|
||||
private List<BaseCell> Cells;
|
||||
|
||||
public Map()
|
||||
{
|
||||
Cells = new List<BaseCell>
|
||||
{
|
||||
new House(),
|
||||
new Burger()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f94ae0990a1cfa4b9ed0aebebde8681
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class OutlineSelection : MonoBehaviour
|
||||
{
|
||||
private Transform _hightlight;
|
||||
private Transform _selection;
|
||||
private RaycastHit _raycastHit;
|
||||
|
||||
void Update()
|
||||
{
|
||||
//if (_hightlight != null)
|
||||
//{
|
||||
// _hightlight.gameObject.GetComponent<Outline>().enabled = false;
|
||||
// _hightlight = null;
|
||||
//}
|
||||
|
||||
//var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
//if (!EventSystem.current.IsPointerOverGameObject() && Physics.Raycast(ray, out _raycastHit))
|
||||
//{
|
||||
// _hightlight = _raycastHit.transform;
|
||||
// if (_hightlight.CompareTag("Selectable") && _hightlight != _selection)
|
||||
// {
|
||||
// if (_hightlight.gameObject.GetComponent<Outline>() != null)
|
||||
// {
|
||||
// _hightlight.gameObject.GetComponent<Outline>().enabled = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var outline = _hightlight.gameObject.AddComponent<Outline>();
|
||||
// outline.enabled = true;
|
||||
// _hightlight.gameObject.GetComponent<Outline>().OutlineColor = Color.yellow;
|
||||
// _hightlight.gameObject.GetComponent<Outline>().OutlineWidth = 7f;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _hightlight = null;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22e20f55292258c479f3c37c0806694d
|
||||
guid: f3ae2c077e8e7c041b87a85a0ff8dd4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user