Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions documentation/docs/05-changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGELOG

#### [Develop](https://github.com/mapbox/mapbox-unity-sdk/tree/develop)

- Added new raster tiles that request retina resolution
- Added mipmap, texture format (and compression via DXT), and retina resolution support to `MapImageFactory`

#### v0.5.1

*05/01/2017*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEditor;
using Mapbox.Unity.MeshGeneration.Factories;
Expand All @@ -12,6 +12,9 @@ public SerializedProperty
material_Prop,
basicMaps_Prop,
customMapId_Prop,
useMipMap_Prop,
textureFormat_Prop,
useRetina_Prop,
mapId_Prop;
private MonoScript script;

Expand Down Expand Up @@ -39,8 +42,9 @@ void OnEnable()
mapIdType_Prop = serializedObject.FindProperty("_mapIdType");
mapId_Prop = serializedObject.FindProperty("_mapId");
material_Prop = serializedObject.FindProperty("_baseMaterial");
basicMaps_Prop = serializedObject.FindProperty("_basicMapIds");

useMipMap_Prop = serializedObject.FindProperty("_useMipMap");
textureFormat_Prop = serializedObject.FindProperty("_textureFormat");
useRetina_Prop = serializedObject.FindProperty("_useRetina");
script = MonoScript.FromScriptableObject((MapImageFactory)target);
for (int i = 0; i < _basicMapIds.Length; i++)
{
Expand All @@ -49,7 +53,7 @@ void OnEnable()
_choiceIndex = i;
break;
}
}
}
}

public override void OnInspectorGUI()
Expand All @@ -65,7 +69,7 @@ public override void OnInspectorGUI()
EditorGUILayout.Space();
var st = (MapImageType)mapIdType_Prop.enumValueIndex;
EditorGUI.indentLevel++;

switch (st)
{
case MapImageType.BasicMapboxStyle:
Expand All @@ -90,6 +94,33 @@ public override void OnInspectorGUI()

}
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Raster Tile Texture Settings");
EditorGUI.indentLevel++;

EditorGUILayout.PropertyField(textureFormat_Prop, new GUIContent("Texture Format"));
var textureFormat = (TextureFormat)textureFormat_Prop.intValue;
if (textureFormat == TextureFormat.DXT1 || textureFormat == TextureFormat.DXT5)
{
EditorGUILayout.HelpBox("Texture will be compressed. This will reduce image quality and lead to longer initialization times but save memory.", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox("Use DXT format to save memory.", MessageType.Warning);
}

EditorGUILayout.PropertyField(useMipMap_Prop, new GUIContent("Create Mip Maps"));
if (useMipMap_Prop.boolValue)
{
EditorGUILayout.HelpBox("Mip maps will consume additional memory but reduce noise at increasing distances.", MessageType.Warning);
}
EditorGUILayout.PropertyField(useRetina_Prop, new GUIContent("Request Retina-resolution"));
if (useRetina_Prop.boolValue)
{
EditorGUILayout.HelpBox("Retina will consume additional memory but greatly improves visual quality.", MessageType.Warning);
}
EditorGUI.indentLevel--;

if (GUILayout.Button("Update"))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Mapbox.Unity.Utilities;
namespace Mapbox.Unity.MeshGeneration.Factories
{
using System;
Expand Down Expand Up @@ -30,6 +31,15 @@ public class MapImageFactory : Factory
[SerializeField]
public Material _baseMaterial;

[SerializeField]
TextureFormat _textureFormat = TextureFormat.DXT1;

[SerializeField]
bool _useMipMap = false;

[SerializeField]
bool _useRetina;

private Dictionary<Vector2, UnityTile> _tiles;

public override void Initialize(IFileSource fs)
Expand Down Expand Up @@ -69,7 +79,17 @@ private void Run(UnityTile tile)
parameters.MapId = _mapId;

tile.ImageDataState = TilePropertyState.Loading;
var rasterTile = parameters.MapId.StartsWith("mapbox://") ? new RasterTile() : new ClassicRasterTile();

RasterTile rasterTile;
if (parameters.MapId.StartsWith("mapbox://", StringComparison.Ordinal))
{
rasterTile = _useRetina ? new RetinaRasterTile() : new RasterTile();
}
else
{
rasterTile = _useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile();
}

rasterTile.Initialize(parameters, (Action)(() =>
{
if (rasterTile.Error != null)
Expand All @@ -80,8 +100,7 @@ private void Run(UnityTile tile)

var rend = tile.GetComponent<MeshRenderer>();
rend.material = _baseMaterial;
tile.ImageData = new Texture2D(256, 256, TextureFormat.RGB24, false);
tile.ImageData.wrapMode = TextureWrapMode.Clamp;
tile.ImageData = new Texture2D(0, 0, _textureFormat, _useMipMap);
tile.ImageData.LoadImage(rasterTile.Data);
rend.material.mainTexture = tile.ImageData;
tile.ImageDataState = TilePropertyState.Loaded;
Expand Down