Compare commits
10 Commits
0.0.2
...
a4f78b3a95
Author | SHA1 | Date | |
---|---|---|---|
a4f78b3a95 | |||
074a58dabd | |||
a2ef175a81 | |||
915ba55c2e | |||
f154a2a468 | |||
c52d438d40 | |||
8d3f53ba13 | |||
1db25e62e7 | |||
18312176d9 | |||
5be6e32b03 |
@@ -56,7 +56,7 @@ namespace Cryville.Common.Unity.UI {
|
||||
const float _placeholderLength = 100;
|
||||
int _firstIndex, _lastIndex;
|
||||
readonly Stack<GameObject> _pool = new();
|
||||
void Update() {
|
||||
void LateUpdate() {
|
||||
int axis = (int)m_direction;
|
||||
int sign = m_direction == 0 ? 1 : -1;
|
||||
float padding = axis == 0 ? m_padding.left : m_padding.top;
|
||||
|
@@ -1,3 +1,3 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("0.0.2")]
|
||||
[assembly: AssemblyVersion("0.0.3")]
|
||||
|
@@ -15,14 +15,18 @@ namespace Cryville.EEW.Unity.Map {
|
||||
MapElementManager m_layerElementSub;
|
||||
[SerializeField]
|
||||
GameObject m_prefabTile;
|
||||
[SerializeField]
|
||||
GameObject m_prefabBitmapHolder;
|
||||
|
||||
readonly MapTileCacheManager _tiles = new();
|
||||
float _elementLayerZ;
|
||||
|
||||
void Start() {
|
||||
_camera = GetComponent<Camera>();
|
||||
_tiles.ExtraCachedZoomLevel = 20;
|
||||
_tiles.Parent = m_layerTile;
|
||||
_tiles.PrefabTile = m_prefabTile;
|
||||
_tiles.PrefabBitmapHolder = m_prefabBitmapHolder;
|
||||
_tiles.CacheDir = Application.temporaryCachePath;
|
||||
_camera.orthographicSize = 0.5f / MathF.Max(1, (float)_camera.pixelWidth / _camera.pixelHeight);
|
||||
_elementLayerZ = m_layerElement.transform.position.z;
|
||||
|
@@ -98,24 +98,25 @@ namespace Cryville.EEW.Unity.Map.Element {
|
||||
for (int d = 0; d < 360; d++) {
|
||||
Quaternion q = Quaternion.AngleAxis(d, axis);
|
||||
Vector3 p = q * rp;
|
||||
Vector2 p2 = ToTilePos(p).ToVector2();
|
||||
if (lp2 != null) {
|
||||
float dx = p2.x - lp2.Value.x;
|
||||
if (MathF.Abs(dx) >= 0.5) {
|
||||
_vertexBuffer[d] = p2.x < 0.5 ? p2 + new Vector2(1, 0) : p2 - new Vector2(1, 0);
|
||||
renderer.AddSegment(_vertexBuffer, segmentIndex, d - segmentIndex + 1);
|
||||
segmentIndex = d;
|
||||
}
|
||||
}
|
||||
_vertexBuffer[d] = p2;
|
||||
lp2 = p2;
|
||||
AddVertex(renderer, ref lp2, ref segmentIndex, d, p);
|
||||
}
|
||||
Vector2 rp2 = ToTilePos(rp).ToVector2();
|
||||
_vertexBuffer[360] = rp2;
|
||||
AddVertex(renderer, ref lp2, ref segmentIndex, 360, rp);
|
||||
renderer.AddSegment(_vertexBuffer, segmentIndex, 361 - segmentIndex);
|
||||
}
|
||||
renderer.SetMaterial(isHistory ? m_historyMaterial : m_ongoingMaterial);
|
||||
}
|
||||
|
||||
void AddVertex(MultiLineRenderer renderer, ref Vector2? lp2, ref int segmentIndex, int d, Vector3 p) {
|
||||
Vector2 p2 = ToTilePos(p).ToVector2();
|
||||
if (lp2 != null && MathF.Abs(p2.x - lp2.Value.x) >= 0.5) {
|
||||
_vertexBuffer[d] = p2.x < 0.5 ? p2 + new Vector2(1, 0) : p2 - new Vector2(1, 0);
|
||||
renderer.AddSegment(_vertexBuffer, segmentIndex, d - segmentIndex + 1);
|
||||
segmentIndex = d;
|
||||
}
|
||||
_vertexBuffer[d] = p2;
|
||||
lp2 = p2;
|
||||
}
|
||||
|
||||
static PointF ToTilePos(Vector3 p) => MapTileUtils.WorldToTilePos(new(MathF.Atan2(p.z, p.x) / MathF.PI * 180f, MathF.Asin(p.y) / MathF.PI * 180f));
|
||||
}
|
||||
}
|
||||
|
@@ -150,12 +150,8 @@ namespace Cryville.EEW.Unity.Map {
|
||||
_mesh.Clear();
|
||||
if (_positions == null) return;
|
||||
if (_positionCount <= 1) return;
|
||||
float hw = m_width / 2;
|
||||
int maxVertexCount = 4 * (_positionCount - 1);
|
||||
var vbuf = ArrayPool<Vector3>.Shared.Rent(maxVertexCount);
|
||||
var ubuf = ArrayPool<Vector2>.Shared.Rent(maxVertexCount);
|
||||
var ibuf = ArrayPool<int>.Shared.Rent(3 * (2 + 4 * (_positionCount - 2)));
|
||||
|
||||
float hw = m_width / 2;
|
||||
int i, vi = 0, ii = 0, li = 0, ri = 1;
|
||||
float uvScale = 1 / (m_tilingScale * m_width);
|
||||
Vector2 p0 = _positions[0], p1 = default;
|
||||
@@ -163,6 +159,12 @@ namespace Cryville.EEW.Unity.Map {
|
||||
if ((p1 = _positions[i]) != p0) break;
|
||||
}
|
||||
if (i >= _positionCount) return;
|
||||
|
||||
int maxVertexCount = 4 * (_positionCount - 1);
|
||||
var vbuf = ArrayPool<Vector3>.Shared.Rent(maxVertexCount);
|
||||
var ubuf = ArrayPool<Vector2>.Shared.Rent(maxVertexCount);
|
||||
var ibuf = ArrayPool<int>.Shared.Rent(3 * (2 + 4 * (_positionCount - 2)));
|
||||
|
||||
Vector2 dp0 = NormalizeSmallVector(p1 - p0), np0 = GetNormal(dp0 * hw);
|
||||
vbuf[vi] = p0 - np0; ubuf[vi++] = new(0, 0);
|
||||
vbuf[vi] = p0 + np0; ubuf[vi++] = new(0, 1);
|
||||
|
@@ -1,43 +1,21 @@
|
||||
using Cryville.EEW.Core.Map;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Cryville.EEW.Unity.Map {
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
sealed class MapTile : MonoBehaviour {
|
||||
static readonly SemaphoreSlim _semaphore = new(2);
|
||||
|
||||
static readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(10) };
|
||||
|
||||
[SerializeField] Transform _idView;
|
||||
|
||||
public MapTileIndex Index { get; set; }
|
||||
public bool IsEmpty { get; private set; }
|
||||
|
||||
Action<MapTile> _callback;
|
||||
|
||||
SpriteRenderer _renderer;
|
||||
|
||||
UnityWebRequest _req;
|
||||
DownloadHandlerTexture _texHandler;
|
||||
Texture2D _tex;
|
||||
Sprite _sprite;
|
||||
|
||||
void Awake() {
|
||||
_renderer = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
FileInfo _localFile;
|
||||
bool _downloadDone;
|
||||
public void Load(MapTileIndex index, string cacheDir, Action<MapTile> onUpdated) {
|
||||
public void Init(MapTileIndex index) {
|
||||
Index = index;
|
||||
_callback = onUpdated;
|
||||
_localFile = new(Path.Combine(cacheDir, $"map/{Index.Z}/{Index.NX}/{Index.NY}"));
|
||||
float z = 1 << index.Z;
|
||||
transform.localPosition = new(index.X / z, -(index.Y + 1) / z, -index.Z / 100f);
|
||||
transform.localScale = new Vector3(1 / z, 1 / z, 1);
|
||||
@@ -45,69 +23,22 @@ namespace Cryville.EEW.Unity.Map {
|
||||
byte e = SharedSettings.Instance.IdBytes[((index.X << 2) + index.Y) & 0x1f];
|
||||
int ex = e >> 4, ey = e & 0xf;
|
||||
_idView.localPosition = new(ex / 16f, 1 - ey / 16f, -1 / 200f);
|
||||
if (_localFile.Exists) {
|
||||
_downloadDone = true;
|
||||
}
|
||||
else {
|
||||
Task.Run(() => RunAsync($"https://server.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{Index.Z}/{Index.NY}/{Index.NX}"));
|
||||
}
|
||||
}
|
||||
async Task RunAsync(string url) {
|
||||
await _semaphore.WaitAsync().ConfigureAwait(true);
|
||||
try {
|
||||
Directory.CreateDirectory(_localFile.DirectoryName);
|
||||
using var webStream = await _httpClient.GetStreamAsync(new Uri(url)).ConfigureAwait(true);
|
||||
using var fileStream = new FileStream(_localFile.FullName, FileMode.Create, FileAccess.Write);
|
||||
await webStream.CopyToAsync(fileStream).ConfigureAwait(true);
|
||||
}
|
||||
finally {
|
||||
_semaphore.Release();
|
||||
}
|
||||
_downloadDone = true;
|
||||
}
|
||||
|
||||
public void Set(Sprite sprite) {
|
||||
if (_renderer) {
|
||||
_renderer.sprite = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
bool _isDestroyed;
|
||||
public void Destroy() {
|
||||
_isDestroyed = true;
|
||||
}
|
||||
void Update() {
|
||||
if (_downloadDone) {
|
||||
try {
|
||||
_texHandler = new DownloadHandlerTexture();
|
||||
_req = new UnityWebRequest($"file:///{_localFile}") {
|
||||
downloadHandler = _texHandler,
|
||||
disposeDownloadHandlerOnDispose = true,
|
||||
};
|
||||
_req.SendWebRequest();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
_downloadDone = false;
|
||||
if (_isDestroyed) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
if (_req == null || !_req.isDone) return;
|
||||
if (_texHandler.isDone) {
|
||||
_tex = _texHandler.texture;
|
||||
_tex.wrapMode = TextureWrapMode.Clamp;
|
||||
_sprite = Sprite.Create(_tex, new Rect(0, 0, _tex.width, _tex.height), Vector2.zero, _tex.height, 0, SpriteMeshType.FullRect, Vector4.zero, false);
|
||||
_renderer.sprite = _sprite;
|
||||
}
|
||||
else {
|
||||
Debug.LogError(_req.error);
|
||||
_localFile.Delete();
|
||||
IsEmpty = true;
|
||||
}
|
||||
_req.Dispose();
|
||||
_req = null;
|
||||
_callback?.Invoke(this);
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
if (_req != null) {
|
||||
_req.Abort();
|
||||
_req.Dispose();
|
||||
_texHandler.Dispose();
|
||||
}
|
||||
if (_sprite) Destroy(_sprite);
|
||||
if (_tex) Destroy(_tex);
|
||||
IsEmpty = true;
|
||||
_callback?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
Assets/Cryville.EEW.Unity/Map/MapTileBitmapHolder.cs
Normal file
35
Assets/Cryville.EEW.Unity/Map/MapTileBitmapHolder.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Cryville.EEW.Core.Map;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.EEW.Unity.Map {
|
||||
sealed class MapTileBitmapHolder : Core.Map.MapTileBitmapHolder {
|
||||
MapTileBitmapHolderBehaviour _behaviour;
|
||||
|
||||
public MapTileBitmapHolder(MapTileIndex index, GameObject gameObject) : base(index) {
|
||||
_behaviour = gameObject.GetComponent<MapTileBitmapHolderBehaviour>();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
base.Dispose(disposing);
|
||||
if (disposing) {
|
||||
if (_behaviour) _behaviour.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Uri GetUri() =>
|
||||
new($"https://server.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{Index.Z}/{Index.NY}/{Index.NX}");
|
||||
|
||||
protected override Task LoadBitmap(FileInfo file, CancellationToken cancellationToken) {
|
||||
_behaviour.Load(file);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Bind(MapTile tile) {
|
||||
_behaviour.Bind(tile);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville.EEW.Unity/Map/MapTileBitmapHolder.cs.meta
Normal file
11
Assets/Cryville.EEW.Unity/Map/MapTileBitmapHolder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7ad3a3ac7d829249ba21987d585b07f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Cryville.EEW.Unity.Map {
|
||||
sealed class MapTileBitmapHolderBehaviour : MonoBehaviour {
|
||||
Action<Sprite> _callback;
|
||||
public void Bind(MapTile tile) {
|
||||
if (_isDone)
|
||||
tile.Set(_sprite);
|
||||
else
|
||||
_callback += tile.Set;
|
||||
}
|
||||
|
||||
UnityWebRequest _req;
|
||||
DownloadHandlerTexture _texHandler;
|
||||
Texture2D _tex;
|
||||
Sprite _sprite;
|
||||
|
||||
FileInfo _localFile;
|
||||
bool _isReady;
|
||||
bool _isDone;
|
||||
public void Load(FileInfo file) {
|
||||
_localFile = file;
|
||||
_isReady = true;
|
||||
}
|
||||
void Update() {
|
||||
if (_isDestroyed) {
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
if (_isReady) {
|
||||
try {
|
||||
_texHandler = new DownloadHandlerTexture();
|
||||
_req = new UnityWebRequest($"file:///{_localFile}") {
|
||||
downloadHandler = _texHandler,
|
||||
disposeDownloadHandlerOnDispose = true,
|
||||
};
|
||||
_req.SendWebRequest();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
_isReady = false;
|
||||
}
|
||||
if (_req == null || !_req.isDone) return;
|
||||
if (_texHandler.isDone) {
|
||||
_tex = _texHandler.texture;
|
||||
_tex.wrapMode = TextureWrapMode.Clamp;
|
||||
_sprite = Sprite.Create(_tex, new Rect(0, 0, _tex.width, _tex.height), Vector2.zero, _tex.height, 0, SpriteMeshType.FullRect, Vector4.zero, false);
|
||||
}
|
||||
else {
|
||||
Debug.LogError(_req.error);
|
||||
_localFile.Delete();
|
||||
}
|
||||
_req.Dispose();
|
||||
_texHandler.Dispose();
|
||||
_req = null;
|
||||
_callback?.Invoke(_sprite);
|
||||
_isDone = true;
|
||||
}
|
||||
|
||||
|
||||
bool _isDestroyed;
|
||||
public void Destroy() {
|
||||
_isDestroyed = true;
|
||||
}
|
||||
void OnDestroy() {
|
||||
if (_req != null) {
|
||||
_req.Abort();
|
||||
_req.Dispose();
|
||||
_texHandler.Dispose();
|
||||
}
|
||||
if (_sprite) Destroy(_sprite);
|
||||
if (_tex) Destroy(_tex);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c17f6b26e9a6bd74e8b2d071c6951c41
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,165 +1,36 @@
|
||||
using Cryville.EEW.Core.Map;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.EEW.Unity.Map {
|
||||
sealed class TileZOrderComparer : IComparer<MapTileIndex>, IComparer<MapTile> {
|
||||
public static readonly TileZOrderComparer Instance = new();
|
||||
public int Compare(MapTileIndex a, MapTileIndex b) {
|
||||
var c = a.Z.CompareTo(b.Z);
|
||||
if (c != 0) return c;
|
||||
c = a.Y.CompareTo(b.Y);
|
||||
if (c != 0) return c;
|
||||
return a.X.CompareTo(b.X);
|
||||
}
|
||||
public int Compare(MapTile a, MapTile b) {
|
||||
if (a == null) return b == null ? 0 : -1;
|
||||
if (b == null) return 1;
|
||||
return Compare(a.Index, b.Index);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class MapTileCacheManager : IDisposable {
|
||||
public int ExtraCachedZoomLevel { get; set; } = 20;
|
||||
|
||||
GameObject m_prefabTile;
|
||||
public GameObject PrefabTile {
|
||||
get => m_prefabTile;
|
||||
set {
|
||||
m_prefabTile = value;
|
||||
if (_dummyTask) GameObject.Destroy(_dummyTask.gameObject);
|
||||
_dummyTask = GameObject.Instantiate(m_prefabTile, Parent, false).GetComponent<MapTile>();
|
||||
}
|
||||
}
|
||||
sealed class MapTileCacheManager : MapTileCacheManager<MapTileBitmapHolder> {
|
||||
public GameObject PrefabTile { get; set; }
|
||||
public GameObject PrefabBitmapHolder { get; set; }
|
||||
|
||||
public Transform Parent { get; set; }
|
||||
|
||||
public string CacheDir { get; set; }
|
||||
|
||||
public event Action Updated;
|
||||
void OnUpdated(MapTile tile) {
|
||||
if (tile.IsEmpty) {
|
||||
lock (ActiveTiles) {
|
||||
if (_cache.Remove(tile.Index)) {
|
||||
ActiveTiles.RemoveAt(ActiveTiles.BinarySearch(tile, TileZOrderComparer.Instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
Updated?.Invoke();
|
||||
protected override MapTileBitmapHolder CreateBitmapHolder(MapTileIndex index) => new(index, GameObject.Instantiate(PrefabBitmapHolder, Parent, false));
|
||||
|
||||
protected override string GetCacheFilePath(MapTileIndex index) => Path.Combine(CacheDir, $"map/{index.Z}/{index.NX}/{index.NY}");
|
||||
|
||||
readonly Dictionary<MapTile<MapTileBitmapHolder>, MapTile> _map = new();
|
||||
protected override void OnTileCreated(MapTile<MapTileBitmapHolder> tile) {
|
||||
base.OnTileCreated(tile);
|
||||
var gameObject = GameObject.Instantiate(PrefabTile, Parent, false);
|
||||
var uTile = gameObject.GetComponent<MapTile>();
|
||||
_map.Add(tile, uTile);
|
||||
uTile.Init(tile.Index);
|
||||
tile.BitmapHolder.Bind(uTile);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
MonoBehaviour.Destroy(_dummyTask);
|
||||
|
||||
lock (ActiveTiles) {
|
||||
foreach (var task in ActiveTiles)
|
||||
GameObject.Destroy(task.gameObject);
|
||||
ActiveTiles.Clear();
|
||||
_cache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<MapTileIndex, MapTile> _cache = new();
|
||||
public List<MapTile> ActiveTiles { get; } = new();
|
||||
|
||||
MapTileIndex _a, _b;
|
||||
|
||||
public void MoveTo(MapTileIndex a, MapTileIndex b) {
|
||||
if (a.Z != b.Z) throw new ArgumentException("Mismatched Z index.");
|
||||
if (a.X >= b.X || a.Y >= b.Y) throw new ArgumentException("Incorrect relative X/Y index.");
|
||||
|
||||
lock (ActiveTiles) {
|
||||
UnloadTiles(a, b);
|
||||
_a = a; _b = b;
|
||||
LoadTiles(a, b);
|
||||
}
|
||||
}
|
||||
void LoadTiles(MapTileIndex a, MapTileIndex b) {
|
||||
for (int z = Math.Max(0, a.Z - ExtraCachedZoomLevel); z <= Math.Max(0, a.Z); z++) {
|
||||
var ia = a.ZoomToLevel(z, Math.Floor);
|
||||
var ib = b.ZoomToLevel(z, Math.Ceiling);
|
||||
for (int x = ia.X; x < ib.X; x++) {
|
||||
for (int y = ia.Y; y < ib.Y; y++) {
|
||||
var index = new MapTileIndex(x, y, z);
|
||||
if (_cache.ContainsKey(index)) continue;
|
||||
var task = GameObject.Instantiate(PrefabTile, Parent, false).GetComponent<MapTile>();
|
||||
task.Load(index, CacheDir, OnUpdated);
|
||||
_cache.Add(index, task);
|
||||
var i = ~ActiveTiles.BinarySearch(task, TileZOrderComparer.Instance);
|
||||
ActiveTiles.Insert(i, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void UnloadTiles(MapTileIndex a, MapTileIndex b) {
|
||||
if (a.Z != _a.Z) {
|
||||
for (int z = _a.Z - ExtraCachedZoomLevel; z < a.Z - ExtraCachedZoomLevel; z++) UnloadTilesAtZoomLevel(z);
|
||||
for (int z = a.Z + 1; z <= _a.Z; z++) UnloadTilesAtZoomLevel(z);
|
||||
}
|
||||
if (a.X > _a.X) {
|
||||
for (int z = Math.Max(0, a.Z); z >= Math.Max(0, a.Z - ExtraCachedZoomLevel); --z) {
|
||||
var ia0 = _a.ZoomToLevel(z, Math.Floor);
|
||||
var ib0 = _b.ZoomToLevel(z, Math.Ceiling);
|
||||
var ia1 = a.ZoomToLevel(z, Math.Floor);
|
||||
if (ia0.X == ia1.X) break;
|
||||
UnloadTilesInRegion(ia0.X, ia0.Y, ia1.X, ib0.Y, z);
|
||||
}
|
||||
}
|
||||
if (b.X < _b.X) {
|
||||
for (int z = Math.Max(0, a.Z); z >= Math.Max(0, a.Z - ExtraCachedZoomLevel); --z) {
|
||||
var ia0 = _a.ZoomToLevel(z, Math.Floor);
|
||||
var ib0 = _b.ZoomToLevel(z, Math.Ceiling);
|
||||
var ib1 = b.ZoomToLevel(z, Math.Ceiling);
|
||||
if (ib0.X == ib1.X) break;
|
||||
UnloadTilesInRegion(ib1.X, ia0.Y, ib0.X, ib0.Y, z);
|
||||
}
|
||||
}
|
||||
if (a.Y > _a.Y) {
|
||||
for (int z = Math.Max(0, a.Z); z >= Math.Max(0, a.Z - ExtraCachedZoomLevel); --z) {
|
||||
var ia0 = _a.ZoomToLevel(z, Math.Floor);
|
||||
var ib0 = _b.ZoomToLevel(z, Math.Ceiling);
|
||||
var ia1 = a.ZoomToLevel(z, Math.Floor);
|
||||
if (ia0.Y == ia1.Y) break;
|
||||
UnloadTilesInRegion(ia0.X, ia0.Y, ib0.X, ia1.Y, z);
|
||||
}
|
||||
}
|
||||
if (b.Y < _b.Y) {
|
||||
for (int z = Math.Max(0, a.Z); z >= Math.Max(0, a.Z - ExtraCachedZoomLevel); --z) {
|
||||
var ia0 = _a.ZoomToLevel(z, Math.Floor);
|
||||
var ib0 = _b.ZoomToLevel(z, Math.Ceiling);
|
||||
var ib1 = b.ZoomToLevel(z, Math.Ceiling);
|
||||
if (ib0.Y == ib1.Y) break;
|
||||
UnloadTilesInRegion(ia0.X, ib1.Y, ib0.X, ib0.Y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
void UnloadTilesInRegion(int x1, int y1, int x2, int y2, int z) {
|
||||
for (int x = x1; x < x2; x++) {
|
||||
for (int y = y1; y < y2; y++) {
|
||||
var index = new MapTileIndex(x, y, z);
|
||||
if (!_cache.TryGetValue(index, out var task)) continue;
|
||||
GameObject.Destroy(task.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MapTile _dummyTask;
|
||||
void UnloadTilesAtZoomLevel(int z) {
|
||||
if (z < 0) return;
|
||||
|
||||
_dummyTask.Index = new(int.MinValue, int.MinValue, z);
|
||||
var i0 = ActiveTiles.BinarySearch(_dummyTask, TileZOrderComparer.Instance);
|
||||
if (i0 < 0) i0 = ~i0;
|
||||
|
||||
_dummyTask.Index = new(int.MinValue, int.MinValue, z + 1);
|
||||
var i1 = ActiveTiles.BinarySearch(_dummyTask, TileZOrderComparer.Instance);
|
||||
if (i1 < 0) i1 = ~i1;
|
||||
|
||||
for (var i = i1 - 1; i >= i0; --i) {
|
||||
var index = ActiveTiles[i].Index;
|
||||
if (!_cache.TryGetValue(index, out var task)) continue;
|
||||
GameObject.Destroy(task.gameObject);
|
||||
protected override void OnTileDestroyed(MapTile<MapTileBitmapHolder> tile) {
|
||||
base.OnTileDestroyed(tile);
|
||||
if (_map.TryGetValue(tile, out var uTile)) {
|
||||
uTile.Destroy();
|
||||
_map.Remove(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,9 +14,12 @@ namespace Cryville.EEW.Unity.UI {
|
||||
[SerializeField] GameObject m_listViewRail;
|
||||
[SerializeField] GameObject m_expander;
|
||||
|
||||
void Start() {
|
||||
void OnEnable() {
|
||||
m_groupHeader.onClick.AddListener(OnGroupHeaderClicked);
|
||||
}
|
||||
void OnDisable() {
|
||||
m_groupHeader.onClick.RemoveListener(OnGroupHeaderClicked);
|
||||
}
|
||||
void OnGroupHeaderClicked() {
|
||||
SetExpanded(!m_listViewContainer.activeSelf);
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ namespace Cryville.EEW.Unity.UI {
|
||||
}
|
||||
void SetView(float mainSeverity, string title, string location, CultureInfo culture) {
|
||||
SetSeverity(mainSeverity);
|
||||
SetText(m_textView, string.Format("{0} {1}", title, location), culture);
|
||||
SetText(m_textView, string.Format(culture, "{0} {1}", title, location), culture);
|
||||
}
|
||||
static void SetText(TMPLocalizedText view, string text, CultureInfo culture) {
|
||||
if (string.IsNullOrWhiteSpace(text)) {
|
||||
@@ -47,9 +47,12 @@ namespace Cryville.EEW.Unity.UI {
|
||||
void Awake() {
|
||||
_dockRatioTweener = new(() => m_dockLayoutGroup.DockOccupiedRatio, v => m_dockLayoutGroup.DockOccupiedRatio = v, Tweeners.Single);
|
||||
}
|
||||
void Start() {
|
||||
void OnEnable() {
|
||||
m_button.onClick.AddListener(OnViewClicked);
|
||||
}
|
||||
void OnDisable() {
|
||||
m_button.onClick.RemoveListener(OnViewClicked);
|
||||
}
|
||||
void OnViewClicked() {
|
||||
EventOngoingListView.Instance.OnItemClicked(_viewModel);
|
||||
}
|
||||
|
@@ -14,9 +14,12 @@ namespace Cryville.EEW.Unity.UI {
|
||||
[SerializeField] TMPLocalizedText m_revisionView;
|
||||
ReportViewModel _viewModel;
|
||||
|
||||
protected virtual void Start() {
|
||||
protected virtual void OnEnable() {
|
||||
if (m_reportViewButton != null) m_reportViewButton.onClick.AddListener(OnViewClicked);
|
||||
}
|
||||
protected virtual void OnDisable() {
|
||||
if (m_reportViewButton != null) m_reportViewButton.onClick.RemoveListener(OnViewClicked);
|
||||
}
|
||||
void OnViewClicked() {
|
||||
Worker.Instance.SetSelected(_viewModel);
|
||||
}
|
||||
|
@@ -8,10 +8,14 @@ namespace Cryville.EEW.Unity.UI {
|
||||
|
||||
[SerializeField] Button m_revisionViewContainerButton;
|
||||
|
||||
protected override void Start() {
|
||||
base.Start();
|
||||
protected override void OnEnable() {
|
||||
base.OnEnable();
|
||||
m_revisionViewContainerButton.onClick.AddListener(OnRevisionViewClicked);
|
||||
}
|
||||
protected override void OnDisable() {
|
||||
base.OnDisable();
|
||||
m_revisionViewContainerButton.onClick.RemoveListener(OnRevisionViewClicked);
|
||||
}
|
||||
void OnRevisionViewClicked() {
|
||||
m_listView.gameObject.SetActive(!m_listView.gameObject.activeSelf);
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,17 +12,30 @@ namespace Cryville.EEW.Unity.UI {
|
||||
_textView = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
StringBuilder _sb = new();
|
||||
char[] _buffer = new char[256];
|
||||
void Update() {
|
||||
_textView.text = string.Format(
|
||||
_sb.Clear();
|
||||
_sb.AppendFormat(
|
||||
CultureInfo.InvariantCulture,
|
||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||
"FPS: i{0:0} / s{1:0}\n",
|
||||
1 / Time.deltaTime,
|
||||
1 / Time.smoothDeltaTime,
|
||||
1 / Time.smoothDeltaTime
|
||||
);
|
||||
_sb.AppendFormat(
|
||||
CultureInfo.InvariantCulture,
|
||||
"SMem: {0:N0} / {1:N0}\n",
|
||||
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong()
|
||||
);
|
||||
_sb.AppendFormat(
|
||||
CultureInfo.InvariantCulture,
|
||||
"IMem: {0:N0} / {1:N0}",
|
||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
||||
);
|
||||
_sb.CopyTo(0, _buffer, _sb.Length);
|
||||
_textView.SetText(_buffer, 0, _sb.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -19,7 +18,7 @@ namespace Cryville.EEW.Unity.UI {
|
||||
time = TimeZoneInfo.ConvertTime(time, timeZone, tTimeZone);
|
||||
else
|
||||
tTimeZone = timeZone;
|
||||
_textView.text = SharedSettings.Instance.DoDisplayTimeZone ? string.Format(CultureInfo.CurrentCulture, "{0:G} ({1})", time, tTimeZone.ToTimeZoneString()) : time.ToString(CultureInfo.CurrentCulture);
|
||||
_textView.text = SharedSettings.Instance.DoDisplayTimeZone ? string.Format(SharedCultures.CurrentCulture, "{0:G} ({1})", time, tTimeZone.ToTimeZoneString()) : time.ToString(SharedCultures.CurrentCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,8 @@ namespace Cryville.EEW.Unity {
|
||||
[SerializeField] EventGroupListView m_historyEventGroupList;
|
||||
[SerializeField] GameObject m_connectingHint;
|
||||
|
||||
GroupingCoreWorker _worker;
|
||||
CoreWorker _worker;
|
||||
ReportGrouper _grouper;
|
||||
CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
void Awake() {
|
||||
@@ -52,6 +53,7 @@ namespace Cryville.EEW.Unity {
|
||||
App.Init();
|
||||
|
||||
_worker = new(new TTSWorker());
|
||||
_grouper = new ReportGrouper();
|
||||
_cancellationTokenSource = new();
|
||||
}
|
||||
|
||||
@@ -64,8 +66,8 @@ namespace Cryville.EEW.Unity {
|
||||
_worker.TTSMessageGeneratorContext = SharedSettings.Instance;
|
||||
_ongoingReportManager.Changed += OnOngoingReported;
|
||||
_worker.Reported += OnReported;
|
||||
_worker.GroupUpdated += OnGroupUpdated;
|
||||
_worker.GroupRemoved += OnGroupRemoved;
|
||||
_grouper.GroupUpdated += OnGroupUpdated;
|
||||
_grouper.GroupRemoved += OnGroupRemoved;
|
||||
Task.Run(() => GatewayVerify(_cancellationTokenSource.Token)).ContinueWith(task => {
|
||||
if (task.IsFaulted) {
|
||||
OnReported(this, new() { Title = task.Exception.Message });
|
||||
@@ -189,6 +191,7 @@ namespace Cryville.EEW.Unity {
|
||||
void OnReported(object sender, ReportViewModel e) {
|
||||
if (e.Model is Exception && e.Model is not SourceWorkerNetworkException)
|
||||
Debug.LogError(e);
|
||||
_grouper.Report(e);
|
||||
_ongoingReportManager.Report(e);
|
||||
_uiActionQueue.Enqueue(() => {
|
||||
if (m_mapElementManager.OngoingCount == 0) {
|
||||
|
@@ -677,6 +677,7 @@ MonoBehaviour:
|
||||
m_layerElement: {fileID: 1602500234}
|
||||
m_layerElementSub: {fileID: 303098821}
|
||||
m_prefabTile: {fileID: 7683017549812261837, guid: e090edd328c6750478f5849a43a9d278, type: 3}
|
||||
m_prefabBitmapHolder: {fileID: 1455558857588368834, guid: 1a5cf693e0cf6b94390f72f521c151ba, type: 3}
|
||||
--- !u!1 &408286580
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
BIN
Assets/Plugins/Analyzers/Cryville.EEW.Analyzer.dll
Normal file
BIN
Assets/Plugins/Analyzers/Cryville.EEW.Analyzer.dll
Normal file
Binary file not shown.
78
Assets/Plugins/Analyzers/Cryville.EEW.Analyzer.dll.meta
Normal file
78
Assets/Plugins/Analyzers/Cryville.EEW.Analyzer.dll.meta
Normal file
@@ -0,0 +1,78 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88e8ae9c8ce06934ab7681fb678d7b00
|
||||
labels:
|
||||
- RoslynAnalyzer
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1525,6 +1525,16 @@
|
||||
The culture <c>zh-TW</c>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Cryville.EEW.SharedCultures.CurrentCulture">
|
||||
<summary>
|
||||
The current culture.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Cryville.EEW.SharedCultures.CurrentUICulture">
|
||||
<summary>
|
||||
The current UI culture.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Cryville.EEW.SharedCultures.Get(System.String)">
|
||||
<summary>
|
||||
Gets a culture of the specified name.
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
46
Assets/Prefabs/Bitmap Holder.prefab
Normal file
46
Assets/Prefabs/Bitmap Holder.prefab
Normal file
@@ -0,0 +1,46 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &1455558857588368834
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 8746876075196617235}
|
||||
- component: {fileID: 122704584488816298}
|
||||
m_Layer: 0
|
||||
m_Name: Bitmap Holder
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &8746876075196617235
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1455558857588368834}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &122704584488816298
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1455558857588368834}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c17f6b26e9a6bd74e8b2d071c6951c41, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
7
Assets/Prefabs/Bitmap Holder.prefab.meta
Normal file
7
Assets/Prefabs/Bitmap Holder.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a5cf693e0cf6b94390f72f521c151ba
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -134,7 +134,7 @@ PlayerSettings:
|
||||
16:10: 1
|
||||
16:9: 1
|
||||
Others: 1
|
||||
bundleVersion: 0.0.2
|
||||
bundleVersion: 0.0.3
|
||||
preloadedAssets: []
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
|
Reference in New Issue
Block a user