Zabiju je
This commit is contained in:
@@ -3,9 +3,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization.Pseudo;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
@@ -13,8 +11,8 @@ namespace Subsystems{
|
||||
[System.Serializable]
|
||||
public class BuildingSettings
|
||||
{
|
||||
public Material ResidentalBuildingsMat;
|
||||
public float ResidentalBuildingHeight;
|
||||
public Material ResidentialBuildingsMat;
|
||||
public float ResidentialBuildingHeight;
|
||||
public Material CommercialBuildingsMat;
|
||||
public float CommercialBuildingHeight;
|
||||
public Material IndustrialBuildingsMat;
|
||||
@@ -65,7 +63,14 @@ namespace Subsystems{
|
||||
private BuildingSettings _buildingSettings;
|
||||
private PathwaySettings _pathwaySettings;
|
||||
private AreaSettings _areaSettings;
|
||||
private const float _metersPerUnit = 1f;
|
||||
private const float _metersPerUnit = 1f;
|
||||
|
||||
// Runtime marker collections
|
||||
private Dictionary<string, GameObject> _taskMarkers = new Dictionary<string, GameObject>();
|
||||
private Dictionary<string, GameObject> _bodyMarkers = new Dictionary<string, GameObject>();
|
||||
private Dictionary<string, GameObject> _playerAvatars = new Dictionary<string, GameObject>();
|
||||
private List<GameObject> _sabotageMarkers = new List<GameObject>();
|
||||
|
||||
public GameManager_Map(GameClient gameClient, GameObject mapCenterPoint, BuildingSettings buildingSettings, PathwaySettings pathwaySettings, AreaSettings areaSettings)
|
||||
{
|
||||
_gameClient = gameClient;
|
||||
@@ -74,8 +79,25 @@ namespace Subsystems{
|
||||
_pathwaySettings = pathwaySettings;
|
||||
_areaSettings = areaSettings;
|
||||
}
|
||||
|
||||
public bool IsSceneReady => _mapCenterPoint != null;
|
||||
|
||||
/// <summary>Called from OnSceneLoaded when Client.unity is loaded so the
|
||||
/// MapCenterPoint (which lives in Client.unity) can be wired at runtime.</summary>
|
||||
public void SetMapCenterPoint(GameObject go) { _mapCenterPoint = go; }
|
||||
public void BuildMap()
|
||||
{
|
||||
if (_mapCenterPoint == null)
|
||||
{
|
||||
Debug.LogWarning("[Map] BuildMap skipped: MapCenterPoint is not yet bound.");
|
||||
return;
|
||||
}
|
||||
if (_gameClient?.CurrentLobbyState?.MapData == null)
|
||||
{
|
||||
Debug.LogWarning("[Map] BuildMap skipped: no MapData in CurrentLobbyState.");
|
||||
return;
|
||||
}
|
||||
|
||||
ClearChildren();
|
||||
_centerPosition = _gameClient.CurrentLobbyState.MapData.Center;
|
||||
GameObject buildingsRoot = new GameObject("Buildings");
|
||||
@@ -139,8 +161,8 @@ namespace Subsystems{
|
||||
switch (b.BuildingType.ToLower())
|
||||
{
|
||||
case "residential":
|
||||
mat = _buildingSettings.ResidentalBuildingsMat;
|
||||
height = _buildingSettings.ResidentalBuildingHeight;
|
||||
mat = _buildingSettings.ResidentialBuildingsMat;
|
||||
height = _buildingSettings.ResidentialBuildingHeight;
|
||||
break;
|
||||
case "commercial":
|
||||
mat = _buildingSettings.CommercialBuildingsMat;
|
||||
@@ -372,5 +394,117 @@ namespace Subsystems{
|
||||
return mesh;
|
||||
}
|
||||
#endregion
|
||||
#region Markers
|
||||
|
||||
public void CreateTaskMarkers(List<GeoSus.Client.GameTask> tasks)
|
||||
{
|
||||
if (_mapCenterPoint == null) return;
|
||||
if (_centerPosition.Lat == 0 && _centerPosition.Lon == 0)
|
||||
{
|
||||
var md = _gameClient?.CurrentLobbyState?.MapData;
|
||||
if (md != null) _centerPosition = md.Center;
|
||||
}
|
||||
if (_centerPosition.Lat == 0 && _centerPosition.Lon == 0) return;
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
if (_taskMarkers.ContainsKey(task.TaskId)) continue;
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
go.name = $"Task_{task.TaskId}";
|
||||
go.transform.parent = _mapCenterPoint.transform;
|
||||
go.transform.position = task.Location.ToLocalVector3(_centerPosition) + Vector3.up * 0.3f;
|
||||
go.transform.localScale = Vector3.one * 0.5f;
|
||||
var mr = go.GetComponent<MeshRenderer>();
|
||||
if (mr) mr.material.color = Color.yellow;
|
||||
_taskMarkers[task.TaskId] = go;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveTaskMarker(string taskId)
|
||||
{
|
||||
if (_taskMarkers.TryGetValue(taskId, out var go))
|
||||
{
|
||||
UnityEngine.Object.Destroy(go);
|
||||
_taskMarkers.Remove(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateBodyMarker(string bodyId, Position location)
|
||||
{
|
||||
if (_mapCenterPoint == null) return;
|
||||
if (_bodyMarkers.ContainsKey(bodyId)) return;
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
|
||||
go.name = $"Body_{bodyId}";
|
||||
go.transform.parent = _mapCenterPoint?.transform;
|
||||
go.transform.position = location.ToLocalVector3(_centerPosition) + Vector3.up * 0.15f;
|
||||
go.transform.localScale = new Vector3(0.3f, 0.5f, 0.3f);
|
||||
go.transform.rotation = Quaternion.Euler(90, 0, 0); // lying down
|
||||
var mr = go.GetComponent<MeshRenderer>();
|
||||
if (mr) mr.material.color = Color.red;
|
||||
_bodyMarkers[bodyId] = go;
|
||||
}
|
||||
|
||||
public void ClearBodyMarkers()
|
||||
{
|
||||
foreach (var go in _bodyMarkers.Values)
|
||||
if (go) UnityEngine.Object.Destroy(go);
|
||||
_bodyMarkers.Clear();
|
||||
}
|
||||
|
||||
public void UpdatePlayerAvatars(Dictionary<string, PlayerPositionInfo> positions, string myUuid)
|
||||
{
|
||||
if (_mapCenterPoint == null) return;
|
||||
if (_centerPosition.Lat == 0 && _centerPosition.Lon == 0)
|
||||
{
|
||||
var md = _gameClient?.CurrentLobbyState?.MapData;
|
||||
if (md != null) _centerPosition = md.Center;
|
||||
}
|
||||
if (_centerPosition.Lat == 0 && _centerPosition.Lon == 0) return;
|
||||
foreach (var kvp in positions)
|
||||
{
|
||||
string uuid = kvp.Key;
|
||||
var info = kvp.Value;
|
||||
if (!_playerAvatars.TryGetValue(uuid, out var go) || go == null)
|
||||
{
|
||||
go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
|
||||
go.name = $"Player_{uuid.Substring(0, Mathf.Min(8, uuid.Length))}";
|
||||
go.transform.parent = _mapCenterPoint?.transform;
|
||||
go.transform.localScale = Vector3.one * 0.4f;
|
||||
_playerAvatars[uuid] = go;
|
||||
}
|
||||
go.transform.position = info.Position.ToLocalVector3(_centerPosition) + Vector3.up * 1f;
|
||||
|
||||
var mr = go.GetComponent<MeshRenderer>();
|
||||
if (mr)
|
||||
{
|
||||
if (uuid == myUuid) mr.material.color = Color.green;
|
||||
else if (info.State == GeoSus.Client.PlayerState.Dead) mr.material.color = Color.grey;
|
||||
else mr.material.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateSabotageMarkers(List<RepairStationInfo> stations)
|
||||
{
|
||||
foreach (var station in stations)
|
||||
{
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
||||
go.name = $"Sabotage_{station.StationId}";
|
||||
go.transform.parent = _mapCenterPoint?.transform;
|
||||
go.transform.position = station.Location.ToLocalVector3(_centerPosition) + Vector3.up * 1f;
|
||||
go.transform.localScale = new Vector3(0.5f, 2f, 0.5f);
|
||||
var mr = go.GetComponent<MeshRenderer>();
|
||||
if (mr) mr.material.color = new Color(1f, 0.5f, 0f); // orange
|
||||
_sabotageMarkers.Add(go);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearSabotageMarkers()
|
||||
{
|
||||
foreach (var go in _sabotageMarkers)
|
||||
if (go) UnityEngine.Object.Destroy(go);
|
||||
_sabotageMarkers.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user