Added IInteractable and Stations
This commit is contained in:
117
Assets/GameManager/GameManager_Game.cs
Normal file
117
Assets/GameManager/GameManager_Game.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using GeoSus.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.Rendering.RayTracingAccelerationStructure;
|
||||
|
||||
namespace Subsystems
|
||||
{
|
||||
[System.Serializable]
|
||||
public class StationSettings
|
||||
{
|
||||
public GameObject TaskStationPrefab;
|
||||
public GameObject SabotageStationPrefab;
|
||||
public GameObject MeetingStationPrefab;
|
||||
public GameObject BodyStationPrefab;
|
||||
|
||||
}
|
||||
public class GameManager_Game
|
||||
{
|
||||
private GameClient _gameClient;
|
||||
private GameObject _player;
|
||||
private GameObject _map;
|
||||
private float _range;
|
||||
private List<TaskData> _availableTasks;
|
||||
public List<GameObject> Stations { get; private set; }
|
||||
private StationSettings _stationSettings;
|
||||
public GameManager_Game(GameClient client, GameObject player, GameObject map, List<TaskData> availableTasks, float range = 20f, StationSettings stationSettings = null)
|
||||
{
|
||||
_gameClient = client;
|
||||
_player = player;
|
||||
_map = map;
|
||||
_availableTasks = availableTasks;
|
||||
_range = range;
|
||||
_stationSettings = stationSettings;
|
||||
}
|
||||
public bool CheckSightLine(Vector3 target)
|
||||
{
|
||||
RaycastHit hit;
|
||||
Vector3 direction = target - _player.transform.position;
|
||||
Ray ray = new Ray(new Vector3(_player.transform.position.x, 0.1f, _player.transform.position.z), direction);
|
||||
Physics.Raycast(ray, out hit, _range);
|
||||
if (hit.collider.tag == "Player")
|
||||
{
|
||||
Debug.Log("Target is visible");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Target is not visible");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public void InitializeStation(Position pos, StationType type)
|
||||
{
|
||||
GameObject stationPrefab = null;
|
||||
PlayerRole? reqRole = null;
|
||||
switch (type)
|
||||
{
|
||||
case StationType.Task:
|
||||
stationPrefab = _stationSettings.TaskStationPrefab;
|
||||
reqRole = PlayerRole.Crew;
|
||||
break;
|
||||
case StationType.Sabotage:
|
||||
stationPrefab = _stationSettings.SabotageStationPrefab;
|
||||
break;
|
||||
case StationType.Meeting:
|
||||
stationPrefab = _stationSettings.MeetingStationPrefab;
|
||||
break;
|
||||
case StationType.Body:
|
||||
stationPrefab = _stationSettings.BodyStationPrefab;
|
||||
break;
|
||||
default:
|
||||
Debug.LogError("Invalid station type");
|
||||
break;
|
||||
}
|
||||
var station = UnityEngine.Object.Instantiate(stationPrefab);
|
||||
station.transform.position = pos.ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center);
|
||||
Stations.Add(station);
|
||||
IInteractable interactable = station.GetComponent<IInteractable>();
|
||||
interactable.Location = pos;
|
||||
interactable.InteractionRange = _range;
|
||||
/*Stations = new List<GameObject>();
|
||||
foreach (var task in _gameClient.MyTasks)
|
||||
{
|
||||
System.Random rnd = new System.Random();
|
||||
int index = rnd.Next(0, _availableTasks.Count);
|
||||
var station = UnityEngine.Object.Instantiate(_stationPrefab);
|
||||
ITask TaskSettings = station.GetComponent<ITask>();
|
||||
TaskSettings.TaskID = task.TaskId;
|
||||
TaskSettings.TaskLocation = task.Location;
|
||||
station.transform.position = TaskSettings.TaskLocation.ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center);
|
||||
station.SetActive(false);
|
||||
|
||||
Stations.Add(station);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
void CheckForPlayers()
|
||||
{
|
||||
foreach (var player in _gameClient.PlayerPositions.Where(p => p.Value.State == PlayerState.Alive))
|
||||
{
|
||||
if (CheckSightLine(player.Value.Position.ToLocalVector3(_gameClient.CurrentLobbyState.MapData.Center)))
|
||||
{
|
||||
Debug.Log($"Player {player.Key} is visible");
|
||||
//TODO: Render player on map
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Player {player.Key} is not visible");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user