add extensions
This commit is contained in:
1 parent
278f5aa211
commit
f296a4acee
7 files changed
+173
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: daaa3de8d868e9143915557053953b5b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
using Mapbox.Unity.Map;
|
||||||
|
using Project;
|
||||||
|
using System;
|
||||||
|
using Unity.Netcode;
|
||||||
|
using GeoJSON.Net.Geometry;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Virgis {
|
||||||
|
|
||||||
|
public class MapBoxLayer : MapBoxLayerPrototype
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly NetworkVariable<MapboxData> data = new();
|
||||||
|
private MapboxData tmpdata = new();
|
||||||
|
|
||||||
|
new protected void Awake() {
|
||||||
|
base.Awake();
|
||||||
|
featureType = FeatureType.MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNetworkSpawn() {
|
||||||
|
base.OnNetworkSpawn();
|
||||||
|
data.OnValueChanged += SetData;
|
||||||
|
data.Value = tmpdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNetworkDespawn()
|
||||||
|
{
|
||||||
|
base.OnNetworkDespawn();
|
||||||
|
data.OnValueChanged -= SetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize(GeogData props)
|
||||||
|
{
|
||||||
|
|
||||||
|
Enum.TryParse<ImagerySourceType>(props.imagerySourceType, true, out tmpdata.st);
|
||||||
|
Enum.TryParse<ElevationLayerType>(props.elevationLayerType, true, out tmpdata.lt);
|
||||||
|
Enum.TryParse<ElevationSourceType>(props.elevationSourceType, true, out tmpdata.et);
|
||||||
|
tmpdata.origin = GeoAppState.instance.project.Origin;
|
||||||
|
tmpdata.MapSize = props.MapSize;
|
||||||
|
tmpdata.MapScale = props.MapScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetData(MapboxData olddata, MapboxData newdata) {
|
||||||
|
VirgisAbstractMap mbLayer = GetComponent<VirgisAbstractMap>();
|
||||||
|
mbLayer.UseWorldScale();
|
||||||
|
mbLayer.SetProperties(newdata.st, newdata.lt, newdata.et, newdata.MapSize);
|
||||||
|
mbLayer.Initialize(newdata.origin.Coordinates.Vector2d(), newdata.MapScale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializeable struct that defines all data needed to instantiate the Mapbox Map
|
||||||
|
/// </summary>
|
||||||
|
struct MapboxData : INetworkSerializable
|
||||||
|
{
|
||||||
|
public ImagerySourceType st;
|
||||||
|
public ElevationLayerType lt;
|
||||||
|
public ElevationSourceType et;
|
||||||
|
public Point origin;
|
||||||
|
public int MapSize;
|
||||||
|
public int MapScale;
|
||||||
|
|
||||||
|
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
|
||||||
|
{
|
||||||
|
if (serializer.IsReader)
|
||||||
|
{
|
||||||
|
var reader = serializer.GetFastBufferReader();
|
||||||
|
reader.ReadValueSafe(out st);
|
||||||
|
reader.ReadValueSafe(out lt);
|
||||||
|
reader.ReadValueSafe(out et);
|
||||||
|
reader.ReadValueSafe(out string json);
|
||||||
|
origin = JsonConvert.DeserializeObject<Point>(json);
|
||||||
|
reader.ReadValueSafe(out MapSize);
|
||||||
|
reader.ReadValueSafe(out MapScale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var writer = serializer.GetFastBufferWriter();
|
||||||
|
writer.WriteValueSafe(st);
|
||||||
|
writer.WriteValueSafe(lt);
|
||||||
|
writer.WriteValueSafe(et);
|
||||||
|
writer.WriteValueSafe(JsonConvert.SerializeObject(origin));
|
||||||
|
writer.WriteValueSafe(MapSize);
|
||||||
|
writer.WriteValueSafe(MapScale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 108d18c9bfd6e924ab7b9faeaffe5a01
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using GeoJSON.Net.Geometry;
|
||||||
|
using Mapbox.Utils;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Virgis {
|
||||||
|
|
||||||
|
public static class MapboxExtensionMethods {
|
||||||
|
/// <summary>
|
||||||
|
/// Converts Iposition to Vector2D
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">IPosition</param>
|
||||||
|
/// <returns>Mapbox.Utils.Vector2d</returns>
|
||||||
|
public static Vector2d Vector2d(this IPosition position) {
|
||||||
|
return new Vector2d(position.Latitude, position.Longitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdf747bbaecadf740b027f2f0d328b42
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Mapbox.Unity.Map;
|
||||||
|
|
||||||
|
namespace Virgis {
|
||||||
|
|
||||||
|
public class VirgisAbstractMap : AbstractMap {
|
||||||
|
|
||||||
|
public Material tileMaterial;
|
||||||
|
|
||||||
|
public void SetProperties(ImagerySourceType imageSource, ElevationLayerType elevationLayerType, ElevationSourceType elevationSource, int size = 1) {
|
||||||
|
_imagery.SetProperties(imageSource, false, false, false);
|
||||||
|
_terrain.SetProperties(elevationSource, elevationLayerType);
|
||||||
|
MapOptions mapOptions = Options;
|
||||||
|
MapExtentOptions extentOptions = mapOptions.extentOptions;
|
||||||
|
extentOptions.extentType = MapExtentType.RangeAroundCenter;
|
||||||
|
extentOptions.defaultExtents.rangeAroundCenterOptions.east = size;
|
||||||
|
extentOptions.defaultExtents.rangeAroundCenterOptions.west = size;
|
||||||
|
extentOptions.defaultExtents.rangeAroundCenterOptions.north = size;
|
||||||
|
extentOptions.defaultExtents.rangeAroundCenterOptions.south = size;
|
||||||
|
SetTileMaterial(tileMaterial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 34041eb43a44fa44195af04bd19b3c42
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in new issue
Block a user