Added map
This commit is contained in:
92
Assets/GameManager/AreaMat.mat
Normal file
92
Assets/GameManager/AreaMat.mat
Normal file
@@ -0,0 +1,92 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: AreaMat
|
||||
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _AlphaTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- PixelSnap: 0
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnableExternalAlpha: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 0.0813297, g: 1, b: 0, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
8
Assets/GameManager/AreaMat.mat.meta
Normal file
8
Assets/GameManager/AreaMat.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a46533bdf4003449bc9146ccef44e27
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using TMPro;
|
||||
/*
|
||||
GameManager - hlavní tøida pro správu hry
|
||||
@@ -13,43 +14,63 @@ using TMPro;
|
||||
GameManager_Map - subsystém pro správu mapy a prostøedí
|
||||
GameManager_Input - subsystém pro správu vstupu od hráèe
|
||||
GameManager_UI - subsystém pro správu uživatelského rozhraní
|
||||
GamaManager_Stats - subsystém pro správu statistik pro server
|
||||
GamaManager_Stats - subsystém pro správu statistik pro server
|
||||
*/
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[Header("Subsystems")]
|
||||
protected GameManager_Network networkSubsystem;
|
||||
protected GameManager_UI uiSubsystem;
|
||||
|
||||
protected GameManager_Map mapSubsystem;
|
||||
|
||||
protected GameClient gameClient;
|
||||
|
||||
[Header("Player Info")]
|
||||
public string displayName;
|
||||
|
||||
[Header("UI Elements")]
|
||||
public Canvas JoinCreateLobby;
|
||||
public Canvas InLobby;
|
||||
public Canvas LoadingScreen;
|
||||
public Canvas GameScreen;
|
||||
|
||||
|
||||
[Header("Map")]
|
||||
public GameObject MapCenterPoint;
|
||||
public BuildingSettings buildingSettings;
|
||||
public PathwaySettings pathwaySettings;
|
||||
public AreaSettings areaSettings;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
if (displayName == null || displayName == "")
|
||||
{
|
||||
displayName = "Player_" + Random.Range(1000, 9999).ToString();
|
||||
displayName = "Player_" + UnityEngine.Random.Range(1000, 9999).ToString();
|
||||
}
|
||||
gameClient = new GameClient(GenerateUUID(), /*displayName*/ GenerateUsername());
|
||||
uiSubsystem = new GameManager_UI(gameClient, JoinCreateLobby, InLobby);
|
||||
uiSubsystem = new GameManager_UI(gameClient, JoinCreateLobby, InLobby, LoadingScreen, GameScreen);
|
||||
networkSubsystem = new GameManager_Network(gameClient);
|
||||
mapSubsystem = new GameManager_Map(gameClient, MapCenterPoint, buildingSettings, pathwaySettings, areaSettings);
|
||||
networkSubsystem.OpenConection();
|
||||
InvokeRepeating(nameof(uiSubsystem.UpdateLobbyUI), 1f, 1f);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (gameClient.CurrentLobbyState != null)
|
||||
{
|
||||
uiSubsystem.UpdateLobbyUI();
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
if (gameClient.CurrentLobbyState.MapDataReady)
|
||||
{
|
||||
mapSubsystem.BuildMap();
|
||||
gameClient.CurrentLobbyState.MapDataReady = false;
|
||||
}
|
||||
}
|
||||
catch (NullReferenceException ex) { }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +82,13 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
protected string GenerateUsername()
|
||||
{
|
||||
string Username = Random.Range(0,10).ToString() + Random.Range(0, 10).ToString() + Random.Range(0, 10).ToString() + Random.Range(0, 10).ToString();
|
||||
string Username = UnityEngine.Random.Range(0,10).ToString() + UnityEngine.Random.Range(0, 10).ToString() + UnityEngine.Random.Range(0, 10).ToString() + UnityEngine.Random.Range(0, 10).ToString();
|
||||
Debug.Log(Username);
|
||||
return Username;
|
||||
}
|
||||
public void CreateLobbyButton()
|
||||
{
|
||||
networkSubsystem.CrateLobby(50.0755, 14.4378);
|
||||
networkSubsystem.CrateLobby(50.7727264, 15.0719876);
|
||||
}
|
||||
public void JoinLobbyButton()
|
||||
{
|
||||
@@ -85,6 +106,10 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
networkSubsystem.LeaveLobby();
|
||||
}
|
||||
public void StartGameButton()
|
||||
{
|
||||
networkSubsystem.StartGame();
|
||||
}
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
gameClient.Disconnect();
|
||||
|
||||
2
Assets/GameManager/GameManager.cs.meta
Normal file
2
Assets/GameManager/GameManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e2c3e4ba4e36ea40a686e58feca4d2b
|
||||
390
Assets/GameManager/GameManager_Map.cs
Normal file
390
Assets/GameManager/GameManager_Map.cs
Normal file
@@ -0,0 +1,390 @@
|
||||
using GeoSus.Client;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization.Pseudo;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace Subsystems{
|
||||
[System.Serializable]
|
||||
public class BuildingSettings
|
||||
{
|
||||
public Material ResidentalBuildingsMat;
|
||||
public float ResidentalBuildingHeight;
|
||||
public Material CommercialBuildingsMat;
|
||||
public float CommercialBuildingHeight;
|
||||
public Material IndustrialBuildingsMat;
|
||||
public float IndustrialBuildingHeight;
|
||||
public Material DefaultBuildingMat;
|
||||
public float DefaultBuildingHeight;
|
||||
}
|
||||
[System.Serializable]
|
||||
public class PathwaySettings
|
||||
{
|
||||
public Material FootwayMat;
|
||||
public float FootwayWidth;
|
||||
public Material PathMat;
|
||||
public float PathWidth;
|
||||
public Material StepsMat;
|
||||
public float StepsWidth;
|
||||
public Material CyclewayMat;
|
||||
public float CyclewayWidth;
|
||||
public Material PedestrianMat;
|
||||
public float PedestrianWidth;
|
||||
public Material RoadMat;
|
||||
public float RoadWidth;
|
||||
public Material ServiceMat;
|
||||
public float ServiceWidth;
|
||||
public Material ResidentialMat;
|
||||
public float ResidentialWidth;
|
||||
public Material TrackMat;
|
||||
public float TrackWidth;
|
||||
public Material DefaultMat;
|
||||
public float DefaultWidth;
|
||||
}
|
||||
[System.Serializable]
|
||||
public class AreaSettings
|
||||
{
|
||||
public Material ParkMat;
|
||||
public Material GardenMat;
|
||||
public Material PlaygroundMat;
|
||||
public Material ForestMat;
|
||||
public Material GrassMat;
|
||||
public Material WaterMat;
|
||||
public Material DefaultMat;
|
||||
}
|
||||
public class GameManager_Map
|
||||
{
|
||||
private GameClient _gameClient;
|
||||
private GameObject _mapCenterPoint;
|
||||
private Position _centerPosition;
|
||||
private BuildingSettings _buildingSettings;
|
||||
private PathwaySettings _pathwaySettings;
|
||||
private AreaSettings _areaSettings;
|
||||
private const float _metersPerUnit = 1f;
|
||||
public GameManager_Map(GameClient gameClient, GameObject mapCenterPoint, BuildingSettings buildingSettings, PathwaySettings pathwaySettings, AreaSettings areaSettings)
|
||||
{
|
||||
_gameClient = gameClient;
|
||||
_mapCenterPoint = mapCenterPoint;
|
||||
_buildingSettings = buildingSettings;
|
||||
_pathwaySettings = pathwaySettings;
|
||||
_areaSettings = areaSettings;
|
||||
}
|
||||
public void BuildMap()
|
||||
{
|
||||
ClearChildren();
|
||||
_centerPosition = _gameClient.CurrentLobbyState.MapData.Center;
|
||||
GameObject buildingsRoot = new GameObject("Buildings");
|
||||
buildingsRoot.transform.parent = _mapCenterPoint.transform;
|
||||
|
||||
GameObject pathRoot = new GameObject("Pathways");
|
||||
pathRoot.transform.parent = _mapCenterPoint.transform;
|
||||
|
||||
GameObject areaRoot = new GameObject("Areas");
|
||||
areaRoot.transform.parent = _mapCenterPoint.transform;
|
||||
|
||||
foreach (var building in _gameClient.CurrentLobbyState.MapData.GetBuildings())
|
||||
{
|
||||
var buildingType = _gameClient.CurrentLobbyState.MapData.BuildingTypes[_gameClient.CurrentLobbyState.MapData.GetBuildings().IndexOf(building)];
|
||||
building.Name = buildingType;
|
||||
GameObject b = BuildBuildingMesh(building);
|
||||
b.transform.parent = buildingsRoot.transform;
|
||||
}
|
||||
foreach (var path in _gameClient.CurrentLobbyState.MapData.GetPathways())
|
||||
{
|
||||
GameObject p = BuildPathwayMesh(path);
|
||||
p.transform.parent = pathRoot.transform;
|
||||
}
|
||||
foreach (var area in _gameClient.CurrentLobbyState.MapData.GetAreas())
|
||||
{
|
||||
GameObject a = BuildAreaMesh(area);
|
||||
a.transform.parent = areaRoot.transform;
|
||||
}
|
||||
//TODO: POIs
|
||||
}
|
||||
GameObject BuildBuildingMesh(MapBuilding b)
|
||||
{
|
||||
var building = new GameObject($"Building_{b.Name ?? "Unknown"}");
|
||||
|
||||
// Výpočet středu budovy
|
||||
Vector3 center = CalculatePolygonCenter(b.Outline);
|
||||
building.transform.position = center;
|
||||
|
||||
// Vytvoření mesh pro budovu
|
||||
MeshFilter meshFilter = building.AddComponent<MeshFilter>();
|
||||
MeshRenderer meshRenderer = building.AddComponent<MeshRenderer>();
|
||||
|
||||
float height;
|
||||
Material mat;
|
||||
switch (b.BuildingType.ToLower())
|
||||
{
|
||||
case "residential":
|
||||
mat = _buildingSettings.ResidentalBuildingsMat;
|
||||
height = _buildingSettings.ResidentalBuildingHeight;
|
||||
break;
|
||||
case "commercial":
|
||||
mat = _buildingSettings.CommercialBuildingsMat;
|
||||
height = _buildingSettings.CommercialBuildingHeight;
|
||||
break;
|
||||
case "industrial":
|
||||
mat = _buildingSettings.IndustrialBuildingsMat;
|
||||
height = _buildingSettings.IndustrialBuildingHeight;
|
||||
break;
|
||||
default:
|
||||
mat = _buildingSettings.DefaultBuildingMat;
|
||||
height = _buildingSettings.DefaultBuildingHeight;
|
||||
break;
|
||||
}
|
||||
Mesh mesh = CreateExtrudedPolygonMesh(b.Outline, height);
|
||||
meshFilter.mesh = mesh;
|
||||
|
||||
//TODO: material by type
|
||||
// Použijeme barvu podle typu budovy
|
||||
meshRenderer.material = mat;
|
||||
|
||||
// Přidání collideru pro interakci
|
||||
building.AddComponent<MeshCollider>();
|
||||
return building;
|
||||
}
|
||||
GameObject BuildPathwayMesh(MapPathway w)
|
||||
{
|
||||
var path = new GameObject($"Path_{w.Name ?? "Unknown"}");
|
||||
|
||||
// Použijeme LineRenderer pro jednoduchost
|
||||
LineRenderer line = path.AddComponent<LineRenderer>();
|
||||
float width;
|
||||
Material mat;
|
||||
|
||||
switch (w.PathType)
|
||||
{
|
||||
case PathType.Footway:
|
||||
mat = _pathwaySettings.FootwayMat;
|
||||
width = _pathwaySettings.FootwayWidth;
|
||||
break;
|
||||
case PathType.Path:
|
||||
mat = _pathwaySettings.PathMat;
|
||||
width = _pathwaySettings.PathWidth;
|
||||
break;
|
||||
case PathType.Steps:
|
||||
mat = _pathwaySettings.StepsMat;
|
||||
width = _pathwaySettings.PathWidth;
|
||||
break;
|
||||
case PathType.Cycleway:
|
||||
mat = _pathwaySettings.CyclewayMat;
|
||||
width = _pathwaySettings.CyclewayWidth;
|
||||
break;
|
||||
case PathType.Pedestrian:
|
||||
mat = _pathwaySettings.PedestrianMat;
|
||||
width = _pathwaySettings.PedestrianWidth;
|
||||
break;
|
||||
case PathType.Road:
|
||||
mat = _pathwaySettings.RoadMat;
|
||||
width = _pathwaySettings.RoadWidth;
|
||||
break;
|
||||
case PathType.Service:
|
||||
mat = _pathwaySettings.ServiceMat;
|
||||
width = _pathwaySettings.ServiceWidth;
|
||||
break;
|
||||
case PathType.Residential:
|
||||
mat = _pathwaySettings.ResidentialMat;
|
||||
width = _pathwaySettings.ResidentialWidth;
|
||||
break;
|
||||
case PathType.Track:
|
||||
mat = _pathwaySettings.TrackMat;
|
||||
width = _pathwaySettings.TrackWidth;
|
||||
break;
|
||||
default:
|
||||
mat = _pathwaySettings.DefaultMat;
|
||||
width = _pathwaySettings.DefaultWidth;
|
||||
break;
|
||||
}
|
||||
|
||||
line.material = mat;
|
||||
line.widthMultiplier = width;
|
||||
|
||||
// Nastavení bodů cesty
|
||||
line.positionCount = w.Points.Count;
|
||||
for (int i = 0; i < w.Points.Count; i++)
|
||||
{
|
||||
Vector3 pos = LatLonToLocal(w.Points[i]);
|
||||
pos.y = 0.1f; // Mírně nad zemí
|
||||
line.SetPosition(i, pos);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
GameObject BuildAreaMesh(MapArea a)
|
||||
{
|
||||
var area = new GameObject($"Area_{a.Name ?? "Unknown"}");
|
||||
|
||||
MeshFilter meshFilter = area.AddComponent<MeshFilter>();
|
||||
MeshRenderer meshRenderer = area.AddComponent<MeshRenderer>();
|
||||
|
||||
// Vytvoření plochého mesh
|
||||
Mesh mesh = CreateFlatPolygonMesh(a.Outline);
|
||||
meshFilter.mesh = mesh;
|
||||
|
||||
|
||||
Material mat;
|
||||
switch (a.AreaType)
|
||||
{
|
||||
case MapAreaType.Park:
|
||||
mat = _areaSettings.ParkMat;
|
||||
break;
|
||||
case MapAreaType.Garden:
|
||||
mat = _areaSettings.GardenMat;
|
||||
break;
|
||||
case MapAreaType.Playground:
|
||||
mat = _areaSettings.PlaygroundMat;
|
||||
break;
|
||||
case MapAreaType.Forest:
|
||||
mat = _areaSettings.ForestMat;
|
||||
break;
|
||||
case MapAreaType.Grass:
|
||||
mat = _areaSettings.GrassMat;
|
||||
break;
|
||||
case MapAreaType.Water:
|
||||
mat = _areaSettings.WaterMat;
|
||||
break;
|
||||
default:
|
||||
mat = _areaSettings.DefaultMat;
|
||||
break;
|
||||
}
|
||||
|
||||
meshRenderer.material = mat;
|
||||
|
||||
area.transform.position = new Vector3(0, 0.05f, 0); // Těsně nad zemí
|
||||
|
||||
return area;
|
||||
}
|
||||
//TODO: POIs
|
||||
void ClearChildren()
|
||||
{
|
||||
List<GameObject> toDestroy = new List<GameObject>();
|
||||
foreach (Transform t in _mapCenterPoint.transform)
|
||||
toDestroy.Add(t.gameObject);
|
||||
foreach (var g in toDestroy)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(g);
|
||||
}
|
||||
}
|
||||
Vector3 LatLonToLocal(Position position)
|
||||
{
|
||||
if (_gameClient.CurrentLobbyState.MapData == null) return Vector3.zero;
|
||||
|
||||
// Výpočet vzdálenosti a směru od středu
|
||||
// Zjednodušená verze - pro malé vzdálenosti je dost přesná
|
||||
|
||||
double latDiff = position.Lat - _gameClient.CurrentLobbyState.MapData.Center.Lat;
|
||||
double lonDiff = position.Lon - _gameClient.CurrentLobbyState.MapData.Center.Lon;
|
||||
|
||||
// Převod stupňů na metry
|
||||
// 1 stupeň latitude ≈ 111320 metrů
|
||||
// 1 stupeň longitude závisí na latitude: 111320 * cos(latitude)
|
||||
double metersPerDegreeLat = 111320.0;
|
||||
double metersPerDegreeLon = 111320.0 * Math.Cos(_gameClient.CurrentLobbyState.MapData.Center.Lat * Math.PI / 180.0);
|
||||
|
||||
float x = (float)(lonDiff * metersPerDegreeLon);
|
||||
float z = (float)(latDiff * metersPerDegreeLat);
|
||||
|
||||
return new Vector3(x, 0, z);
|
||||
}
|
||||
#region Polygon Utils
|
||||
private Vector3 CalculatePolygonCenter(List<Position> points)
|
||||
{
|
||||
Vector3 center = Vector3.zero;
|
||||
foreach (var point in points)
|
||||
{
|
||||
center += LatLonToLocal(point);
|
||||
}
|
||||
return center / points.Count;
|
||||
}
|
||||
private Mesh CreateExtrudedPolygonMesh(List<Position> outline, float height)
|
||||
{
|
||||
Mesh mesh = new Mesh();
|
||||
|
||||
int vertexCount = outline.Count;
|
||||
|
||||
// Vertices - spodní a horní podstava
|
||||
Vector3[] vertices = new Vector3[vertexCount * 2];
|
||||
Vector3 center = CalculatePolygonCenter(outline);
|
||||
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
{
|
||||
Vector3 pos = LatLonToLocal(outline[i]) - center;
|
||||
vertices[i] = pos; // Spodní
|
||||
vertices[i + vertexCount] = pos + Vector3.up * height; // Horní
|
||||
}
|
||||
|
||||
// Triangles - jen boční stěny pro jednoduchost
|
||||
List<int> triangles = new List<int>();
|
||||
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
{
|
||||
int next = (i + 1) % vertexCount;
|
||||
|
||||
// Boční stěna - dva trojúhelníky
|
||||
triangles.Add(i);
|
||||
triangles.Add(i + vertexCount);
|
||||
triangles.Add(next);
|
||||
|
||||
triangles.Add(next);
|
||||
triangles.Add(i + vertexCount);
|
||||
triangles.Add(next + vertexCount);
|
||||
}
|
||||
|
||||
// Horní podstava - zjednodušená triangulace (fan)
|
||||
if (vertexCount >= 3)
|
||||
{
|
||||
for (int i = 1; i < vertexCount - 1; i++)
|
||||
{
|
||||
triangles.Add(vertexCount); // Střed (první bod horní)
|
||||
triangles.Add(vertexCount + i);
|
||||
triangles.Add(vertexCount + i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
mesh.vertices = vertices;
|
||||
mesh.triangles = triangles.ToArray();
|
||||
mesh.RecalculateNormals();
|
||||
mesh.RecalculateBounds();
|
||||
|
||||
return mesh;
|
||||
}
|
||||
private Mesh CreateFlatPolygonMesh(List<Position> outline)
|
||||
{
|
||||
Mesh mesh = new Mesh();
|
||||
|
||||
int vertexCount = outline.Count;
|
||||
Vector3[] vertices = new Vector3[vertexCount];
|
||||
Vector3 center = CalculatePolygonCenter(outline);
|
||||
|
||||
for (int i = 0; i < vertexCount; i++)
|
||||
{
|
||||
vertices[i] = LatLonToLocal(outline[i]) - center;
|
||||
}
|
||||
|
||||
// Triangulace - fan pattern
|
||||
List<int> triangles = new List<int>();
|
||||
if (vertexCount >= 3)
|
||||
{
|
||||
for (int i = 1; i < vertexCount - 1; i++)
|
||||
{
|
||||
triangles.Add(0);
|
||||
triangles.Add(i);
|
||||
triangles.Add(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
mesh.vertices = vertices;
|
||||
mesh.triangles = triangles.ToArray();
|
||||
mesh.RecalculateNormals();
|
||||
|
||||
return mesh;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
2
Assets/GameManager/GameManager_Map.cs.meta
Normal file
2
Assets/GameManager/GameManager_Map.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71870ee18b89dd7438e5362ff9e02a3b
|
||||
@@ -10,6 +10,7 @@ namespace Subsystems
|
||||
private const string _serverAddress = "geosus.honzuvkod.dev";
|
||||
private const int _serverPort = 7777;
|
||||
private GameClient _gameClient;
|
||||
private GameManager_Map _mapSubsystem;
|
||||
public async void OpenConection()
|
||||
{
|
||||
while (true)
|
||||
@@ -78,14 +79,31 @@ namespace Subsystems
|
||||
}
|
||||
private void OnGameEvent(GameEvent gameEvent)
|
||||
{
|
||||
switch (gameEvent.Type)
|
||||
switch (gameEvent.EventType)
|
||||
{
|
||||
case "PlayerJoined":
|
||||
Debug.Log($"Player {gameEvent.GetPayload<PlayerJoinedPayload>().DisplayName} joined");
|
||||
HandlePlayerJoined(gameEvent);
|
||||
break;
|
||||
case "PlayerLeft":
|
||||
Debug.Log($"Player {gameEvent.GetPayload<PlayerLeftPayload>()} left");
|
||||
break;
|
||||
case "GameStarting":
|
||||
Debug.Log("Game is starting!");
|
||||
break;
|
||||
case "GameStarted":
|
||||
Debug.Log("Game started");
|
||||
break;
|
||||
case "MapDataReady":
|
||||
Debug.Log("Map data ready");
|
||||
break;
|
||||
case "PlayerMapDataReceived":
|
||||
Debug.Log("Player map data recieved");
|
||||
break;
|
||||
case "MapDataError":
|
||||
Debug.Log("Received MapData server error");
|
||||
break;
|
||||
default:
|
||||
Debug.Log("Received GameEvent of type: " + gameEvent.Type);
|
||||
Debug.Log("Received GameEvent of type: " + gameEvent.EventType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -111,23 +129,11 @@ namespace Subsystems
|
||||
Debug.LogError("Failed to create lobby: " + message.Error);
|
||||
}
|
||||
}
|
||||
private void HandlePlayerJoined(GameEvent gameEvent)
|
||||
{
|
||||
var payload = gameEvent.GetPayload<PlayerJoinedPayload>();
|
||||
_gameClient.CurrentLobbyState.Players.Add(new PlayerInfo
|
||||
{
|
||||
ClientUuid = payload.ClientUuid,
|
||||
DisplayName = payload.DisplayName,
|
||||
IsOwner = false,
|
||||
IsReady = false,
|
||||
State = PlayerState.Alive
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void CrateLobby(double lat, double lon)
|
||||
{
|
||||
_gameClient.CreateLobby(new Position(lat, lon));
|
||||
_gameClient.CreateLobby(new Position(lat, lon));
|
||||
}
|
||||
public void JoinLobby(string joinCode)
|
||||
{
|
||||
@@ -145,8 +151,11 @@ namespace Subsystems
|
||||
_gameClient.Disconnect();
|
||||
Application.Quit();
|
||||
}
|
||||
public void StartGame()
|
||||
{
|
||||
_gameClient.StartGame();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
Assets/GameManager/GameManager_Network.cs.meta
Normal file
2
Assets/GameManager/GameManager_Network.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c2032ed1184ad7418cc415edf97b69e
|
||||
@@ -11,25 +11,61 @@ namespace Subsystems
|
||||
private GameClient _gameClient;
|
||||
private Canvas _CreateJoinLobby;
|
||||
private Canvas _InLobby;
|
||||
public GameManager_UI(GameClient gameClient, Canvas CreateJoinLobby, Canvas InLobby)
|
||||
private Canvas _LoadingScreen;
|
||||
private Canvas _GameScreen;
|
||||
public GameManager_UI(GameClient gameClient, Canvas CreateJoinLobby, Canvas InLobby, Canvas LoadingScreen, Canvas GameScreen)
|
||||
{
|
||||
_gameClient = gameClient;
|
||||
_CreateJoinLobby = CreateJoinLobby;
|
||||
_LoadingScreen = LoadingScreen;
|
||||
_GameScreen = GameScreen;
|
||||
_InLobby = InLobby;
|
||||
_CreateJoinLobby.enabled = true;
|
||||
_InLobby.enabled = false;
|
||||
_GameScreen.enabled = false;
|
||||
_LoadingScreen.enabled = false;
|
||||
}
|
||||
public void UpdateLobbyUI()
|
||||
{
|
||||
_InLobby.enabled = true;
|
||||
_CreateJoinLobby.enabled = false;
|
||||
var playerList = _InLobby.transform.Find("PlayerList").GetComponent<TMPro.TMP_Text>();
|
||||
playerList.text = "";
|
||||
foreach (var player in _gameClient.CurrentLobbyState.Players)
|
||||
if (_gameClient.CurrentLobbyState == null)
|
||||
{
|
||||
playerList.text += player.DisplayName + "\n";
|
||||
_CreateJoinLobby.enabled = true;
|
||||
_InLobby.enabled = false;
|
||||
_GameScreen.enabled = false;
|
||||
_LoadingScreen.enabled = false;
|
||||
return;
|
||||
}
|
||||
_InLobby.transform.Find("JoinCode").GetComponent<TMPro.TMP_Text>().text = _gameClient.CurrentLobbyState.JoinCode;
|
||||
else if (_gameClient.CurrentLobbyState.Phase == GamePhase.Loading)
|
||||
{
|
||||
_CreateJoinLobby.enabled = false;
|
||||
_InLobby.enabled = false;
|
||||
_GameScreen.enabled = false;
|
||||
_LoadingScreen.enabled = true;
|
||||
return;
|
||||
}
|
||||
else if (_gameClient.CurrentLobbyState.Phase == GamePhase.Lobby)
|
||||
{
|
||||
_InLobby.enabled = true;
|
||||
_CreateJoinLobby.enabled = false;
|
||||
var playerList = _InLobby.transform.Find("PlayerList").GetComponent<TMPro.TMP_Text>();
|
||||
playerList.text = "";
|
||||
foreach (var player in _gameClient.CurrentLobbyState.Players)
|
||||
{
|
||||
playerList.text += player.DisplayName + "\n";
|
||||
}
|
||||
_InLobby.transform.Find("JoinCode").GetComponent<TMPro.TMP_Text>().text = _gameClient.CurrentLobbyState.JoinCode;
|
||||
return;
|
||||
}
|
||||
else if (_gameClient.CurrentLobbyState.Phase == GamePhase.Playing)
|
||||
{
|
||||
_CreateJoinLobby.enabled = false;
|
||||
_InLobby.enabled = false;
|
||||
_GameScreen.enabled = true;
|
||||
_LoadingScreen.enabled = false;
|
||||
_GameScreen.transform.Find("Role").GetComponent<TMPro.TMP_Text>().text = _gameClient.MyRole.ToString() ;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
Assets/GameManager/GameManager_UI.cs.meta
Normal file
2
Assets/GameManager/GameManager_UI.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f575016e02384774d88b46ed7f09579f
|
||||
2
Assets/GameManager/ITask.cs.meta
Normal file
2
Assets/GameManager/ITask.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e926b313c00d4f48ad68750c88817bf
|
||||
92
Assets/GameManager/TestMaterial.mat
Normal file
92
Assets/GameManager/TestMaterial.mat
Normal file
@@ -0,0 +1,92 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: TestMaterial
|
||||
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _AlphaTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- PixelSnap: 0
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnableExternalAlpha: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
8
Assets/GameManager/TestMaterial.mat.meta
Normal file
8
Assets/GameManager/TestMaterial.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6744524496c8e1549882277283c132cc
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user