mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2026-01-04 17:20:57 +07:00
Tiled support begined
This commit is contained in:
@@ -46,6 +46,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Assets\IsoTools\Scripts\Internal\Editor\IsoObjectEditor.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\Internal\Editor\IsoObjectEditor.cs" />
|
||||||
|
<Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapAssetEditor.cs" />
|
||||||
|
<Compile Include="Assets\IsoTools\Tiled\Internal\Editor\TiledMapPostprocessor.cs" />
|
||||||
<Reference Include="UnityEditor.Advertisements">
|
<Reference Include="UnityEditor.Advertisements">
|
||||||
<HintPath>/Applications/Unity_5.3/Unity.app/Contents/UnityExtensions/Unity/Advertisements/Editor/UnityEditor.Advertisements.dll</HintPath>
|
<HintPath>/Applications/Unity_5.3/Unity.app/Contents/UnityExtensions/Unity/Advertisements/Editor/UnityEditor.Advertisements.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -65,6 +65,7 @@
|
|||||||
<Compile Include="Assets\IsoTools\Scripts\IsoRigidbody.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\IsoRigidbody.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Scripts\IsoSphereCollider.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\IsoSphereCollider.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Scripts\IsoWorld.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\IsoWorld.cs" />
|
||||||
|
<Compile Include="Assets\IsoTools\Tiled\TiledMapAsset.cs" />
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>/Applications/Unity_5.3/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
<HintPath>/Applications/Unity_5.3/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -63,14 +63,18 @@ SpriteRenderer:
|
|||||||
m_ProbeAnchor: {fileID: 0}
|
m_ProbeAnchor: {fileID: 0}
|
||||||
m_ScaleInLightmap: 1
|
m_ScaleInLightmap: 1
|
||||||
m_PreserveUVs: 0
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
m_ImportantGI: 0
|
m_ImportantGI: 0
|
||||||
m_AutoUVMaxDistance: .5
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
m_AutoUVMaxAngle: 89
|
m_AutoUVMaxAngle: 89
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
m_Sprite: {fileID: 21300000, guid: 529e3cb7140cf0340a859f744523212e, type: 3}
|
m_Sprite: {fileID: 21300000, guid: 529e3cb7140cf0340a859f744523212e, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
--- !u!1001 &100100000
|
--- !u!1001 &100100000
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
@@ -63,14 +63,18 @@ SpriteRenderer:
|
|||||||
m_ProbeAnchor: {fileID: 0}
|
m_ProbeAnchor: {fileID: 0}
|
||||||
m_ScaleInLightmap: 1
|
m_ScaleInLightmap: 1
|
||||||
m_PreserveUVs: 0
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
m_ImportantGI: 0
|
m_ImportantGI: 0
|
||||||
m_AutoUVMaxDistance: .5
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
m_AutoUVMaxAngle: 89
|
m_AutoUVMaxAngle: 89
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
m_Sprite: {fileID: 21300000, guid: acb19fa5475385a47a614d3a2f318ed1, type: 3}
|
m_Sprite: {fileID: 21300000, guid: acb19fa5475385a47a614d3a2f318ed1, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
--- !u!1001 &100100000
|
--- !u!1001 &100100000
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
@@ -81,7 +81,15 @@ Prefab:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications: []
|
m_Modifications:
|
||||||
|
- target: {fileID: 0}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: 2.73
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 0}
|
||||||
|
propertyPath: _position.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_ParentPrefab: {fileID: 0}
|
m_ParentPrefab: {fileID: 0}
|
||||||
m_RootGameObject: {fileID: 153404}
|
m_RootGameObject: {fileID: 153404}
|
||||||
|
|||||||
@@ -63,14 +63,18 @@ SpriteRenderer:
|
|||||||
m_ProbeAnchor: {fileID: 0}
|
m_ProbeAnchor: {fileID: 0}
|
||||||
m_ScaleInLightmap: 1
|
m_ScaleInLightmap: 1
|
||||||
m_PreserveUVs: 0
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
m_ImportantGI: 0
|
m_ImportantGI: 0
|
||||||
m_AutoUVMaxDistance: .5
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
m_AutoUVMaxAngle: 89
|
m_AutoUVMaxAngle: 89
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
m_Sprite: {fileID: 21300000, guid: 8e9123aea46456b4d9dd4558840f0d88, type: 3}
|
m_Sprite: {fileID: 21300000, guid: 8e9123aea46456b4d9dd4558840f0d88, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
--- !u!1001 &100100000
|
--- !u!1001 &100100000
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
@@ -63,14 +63,18 @@ SpriteRenderer:
|
|||||||
m_ProbeAnchor: {fileID: 0}
|
m_ProbeAnchor: {fileID: 0}
|
||||||
m_ScaleInLightmap: 1
|
m_ScaleInLightmap: 1
|
||||||
m_PreserveUVs: 0
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
m_ImportantGI: 0
|
m_ImportantGI: 0
|
||||||
m_AutoUVMaxDistance: .5
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
m_AutoUVMaxAngle: 89
|
m_AutoUVMaxAngle: 89
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
m_Sprite: {fileID: 21300000, guid: 6f46be8cb617f6045a549493667d808c, type: 3}
|
m_Sprite: {fileID: 21300000, guid: 6f46be8cb617f6045a549493667d808c, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
--- !u!1001 &100100000
|
--- !u!1001 &100100000
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
@@ -173,4 +173,4 @@ namespace IsoTools.Internal {
|
|||||||
DirtyTargetPosition();
|
DirtyTargetPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace IsoTools
|
} // namespace IsoTools.Internal
|
||||||
9
Assets/IsoTools/Tiled.meta
Normal file
9
Assets/IsoTools/Tiled.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4c2e044565a4a48858823973540bf756
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1453182016
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/IsoTools/Tiled/Examples.meta
Normal file
9
Assets/IsoTools/Tiled/Examples.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 95500b2c162ee45889fff8e8de30bdc5
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1453182058
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4b96dccad0a464c0c8462411423c292a
|
||||||
|
timeCreated: 1453320478
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/IsoTools/Tiled/Examples/isometric_grass_and_water.png
Normal file
BIN
Assets/IsoTools/Tiled/Examples/isometric_grass_and_water.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
@@ -0,0 +1,57 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a1c9afa4544b94d3fb95fbc12c956100
|
||||||
|
timeCreated: 1453182058
|
||||||
|
licenseType: Free
|
||||||
|
TextureImporter:
|
||||||
|
fileIDToRecycleName: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 1
|
||||||
|
linearTexture: 0
|
||||||
|
correctGamma: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
isReadable: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 0
|
||||||
|
cubemapConvolution: 0
|
||||||
|
cubemapConvolutionSteps: 7
|
||||||
|
cubemapConvolutionExponent: 1.5
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: -1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
filterMode: -1
|
||||||
|
aniso: -1
|
||||||
|
mipBias: -1
|
||||||
|
wrapMode: 1
|
||||||
|
nPOTScale: 0
|
||||||
|
lightmap: 0
|
||||||
|
rGBM: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
spriteMode: 1
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
alphaIsTransparency: 1
|
||||||
|
textureType: 8
|
||||||
|
buildTargetSettings: []
|
||||||
|
spriteSheet:
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
spritePackingTag:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
1321
Assets/IsoTools/Tiled/Examples/isometric_grass_and_water.tmx
Normal file
1321
Assets/IsoTools/Tiled/Examples/isometric_grass_and_water.tmx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9a8d107ba5b67476dbfe4fdcba671cb6
|
||||||
|
timeCreated: 1453182058
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/IsoTools/Tiled/Internal.meta
Normal file
9
Assets/IsoTools/Tiled/Internal.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4af79c76da8fe4ee1b2a0cd711fb04a4
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1453217672
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
9
Assets/IsoTools/Tiled/Internal/Editor.meta
Normal file
9
Assets/IsoTools/Tiled/Internal/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9e14fd592ac9a4690a5b6a34edb31898
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1453182090
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
20
Assets/IsoTools/Tiled/Internal/Editor/TiledMapAssetEditor.cs
Normal file
20
Assets/IsoTools/Tiled/Internal/Editor/TiledMapAssetEditor.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using IsoTools.Tiled;
|
||||||
|
|
||||||
|
namespace IsoTools.Tiled.Internal {
|
||||||
|
[CustomEditor(typeof(TiledMapAsset))]
|
||||||
|
public class TiledMapAssetEditor : Editor {
|
||||||
|
TiledMapAsset _asset = null;
|
||||||
|
|
||||||
|
void OnEnable() {
|
||||||
|
_asset = target as TiledMapAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
DrawDefaultInspector();
|
||||||
|
if ( GUILayout.Button("Create prefab") ) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace IsoTools.Tiled.Internal
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1612079295b4947b58adc4bb6585b7dd
|
||||||
|
timeCreated: 1453182090
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
167
Assets/IsoTools/Tiled/Internal/Editor/TiledMapPostprocessor.cs
Normal file
167
Assets/IsoTools/Tiled/Internal/Editor/TiledMapPostprocessor.cs
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using IsoTools.Tiled;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace IsoTools.Tiled.Internal {
|
||||||
|
public class TiledMapPostprocessor : AssetPostprocessor {
|
||||||
|
static void OnPostprocessAllAssets(
|
||||||
|
string[] imported_assets, string[] deleted_assets,
|
||||||
|
string[] moved_assets, string[] moved_from_asset_paths)
|
||||||
|
{
|
||||||
|
var tmx_assets = imported_assets
|
||||||
|
.Where(p => Path.GetExtension(p).ToLower().Equals(".tmx"));
|
||||||
|
foreach ( var tmx_asset in tmx_assets ) {
|
||||||
|
TmxAssetProcess(tmx_asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TmxAssetProcess(string tmx_asset) {
|
||||||
|
var tile_map_data = LoadTiledMapFromTmxFile(tmx_asset);
|
||||||
|
if ( tile_map_data != null ) {
|
||||||
|
var new_asset_path = Path.ChangeExtension(tmx_asset, ".asset");
|
||||||
|
var new_asset = AssetDatabase.LoadAssetAtPath<TiledMapAsset>(new_asset_path);
|
||||||
|
if ( !new_asset ) {
|
||||||
|
new_asset = ScriptableObject.CreateInstance<TiledMapAsset>();
|
||||||
|
AssetDatabase.CreateAsset(new_asset, new_asset_path);
|
||||||
|
}
|
||||||
|
new_asset.Data = tile_map_data;
|
||||||
|
EditorUtility.SetDirty(new_asset);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static TiledMapData LoadTiledMapFromTmxFile(string tmx_path) {
|
||||||
|
try {
|
||||||
|
var tmx_root_elem = XDocument.Load(tmx_path).Document.Root;
|
||||||
|
var tiled_map_data = new TiledMapData();
|
||||||
|
LoadTiledMapOptsFromTmxRootElem(tmx_root_elem, tiled_map_data);
|
||||||
|
LoadTiledMapLayersFromTmxRootElem(tmx_root_elem, tiled_map_data);
|
||||||
|
LoadTiledMapTilesetsFromTmxRootElem(tmx_root_elem, tiled_map_data);
|
||||||
|
return tiled_map_data;
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
Debug.LogErrorFormat("Parsing TMX file error: {0}", e.Message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadTiledMapOptsFromTmxRootElem(XElement root_elem, TiledMapData data) {
|
||||||
|
data.Width = SafeLoadIntFromElemAttr(root_elem, "width" , data.Width);
|
||||||
|
data.Height = SafeLoadIntFromElemAttr(root_elem, "height" , data.Height);
|
||||||
|
data.TileWidth = SafeLoadIntFromElemAttr(root_elem, "tilewidth" , data.TileWidth);
|
||||||
|
data.TileHeight = SafeLoadIntFromElemAttr(root_elem, "tileheight", data.TileHeight);
|
||||||
|
var orientation_str = root_elem.Attribute("orientation").Value;
|
||||||
|
switch ( orientation_str ) {
|
||||||
|
case "isometric":
|
||||||
|
data.Orientation = TiledMapOrientation.Isometric;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new UnityException(string.Format(
|
||||||
|
"Parsing TMX file error: unsupported orientation ({0})",
|
||||||
|
orientation_str));
|
||||||
|
}
|
||||||
|
SafeLoadPropertiesFromOwnerElem(root_elem, data.Properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Layers
|
||||||
|
// -----------------------------
|
||||||
|
|
||||||
|
static void LoadTiledMapLayersFromTmxRootElem(XElement root_elem, TiledMapData data) {
|
||||||
|
foreach ( var layer_elem in root_elem.Elements("layer") ) {
|
||||||
|
var layer = new TiledMapLayerData();
|
||||||
|
LoadTiledMapLayerFromTmxLayerElem(layer_elem, layer);
|
||||||
|
data.Layers.Add(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadTiledMapLayerFromTmxLayerElem(XElement layer_elem, TiledMapLayerData layer) {
|
||||||
|
layer.Name = SafeLoadStrFromElemAttr (layer_elem, "name" , string.Empty);
|
||||||
|
layer.Width = SafeLoadIntFromElemAttr (layer_elem, "width" , layer.Width);
|
||||||
|
layer.Height = SafeLoadIntFromElemAttr (layer_elem, "height" , layer.Height);
|
||||||
|
layer.OffsetX = SafeLoadIntFromElemAttr (layer_elem, "offsetx", layer.OffsetX);
|
||||||
|
layer.OffsetY = SafeLoadIntFromElemAttr (layer_elem, "offsety", layer.OffsetY);
|
||||||
|
layer.Visible = SafeLoadBoolFromElemAttr(layer_elem, "visible", layer.Visible);
|
||||||
|
LoadTiledMapLayerTilesFromTmxLayerElem(layer_elem, layer);
|
||||||
|
SafeLoadPropertiesFromOwnerElem(layer_elem, layer.Properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadTiledMapLayerTilesFromTmxLayerElem(XElement layer_elem, TiledMapLayerData layer) {
|
||||||
|
foreach ( var elem in layer_elem.Element("data").Elements("tile") ) {
|
||||||
|
layer.Tiles.Add(SafeLoadIntFromElemAttr(elem, "gid", 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Tilesets
|
||||||
|
// -----------------------------
|
||||||
|
|
||||||
|
static void LoadTiledMapTilesetsFromTmxRootElem(XElement root_elem, TiledMapData data) {
|
||||||
|
foreach ( var tileset_elem in root_elem.Elements("tileset") ) {
|
||||||
|
var tileset = new TiledMapTilesetData();
|
||||||
|
LoadTiledMapTilesetFromTmxTilesetElem(tileset_elem, tileset);
|
||||||
|
data.Tilesets.Add(tileset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadTiledMapTilesetFromTmxTilesetElem(XElement tileset_elem, TiledMapTilesetData tileset) {
|
||||||
|
tileset.FirstGid = SafeLoadIntFromElemAttr(tileset_elem, "firstgid" , tileset.FirstGid);
|
||||||
|
tileset.Name = SafeLoadStrFromElemAttr(tileset_elem, "name" , tileset.Name);
|
||||||
|
tileset.Margin = SafeLoadIntFromElemAttr(tileset_elem, "margin" , tileset.Margin);
|
||||||
|
tileset.Spacing = SafeLoadIntFromElemAttr(tileset_elem, "spacing" , tileset.Spacing);
|
||||||
|
tileset.TileWidth = SafeLoadIntFromElemAttr(tileset_elem, "tilewidth" , tileset.TileWidth);
|
||||||
|
tileset.TileHeight = SafeLoadIntFromElemAttr(tileset_elem, "tileheight", tileset.TileHeight);
|
||||||
|
tileset.TileCount = SafeLoadIntFromElemAttr(tileset_elem, "tilecount" , tileset.TileCount);
|
||||||
|
tileset.TileOffsetX = SafeLoadIntFromElemAttr(tileset_elem.Element("tileoffset"), "x" , tileset.TileOffsetX);
|
||||||
|
tileset.TileOffsetY = SafeLoadIntFromElemAttr(tileset_elem.Element("tileoffset"), "y" , tileset.TileOffsetY);
|
||||||
|
tileset.Image = SafeLoadStrFromElemAttr(tileset_elem.Element("image" ), "source", tileset.Image);
|
||||||
|
tileset.ImageWidth = SafeLoadIntFromElemAttr(tileset_elem.Element("image" ), "widht" , tileset.ImageWidth);
|
||||||
|
tileset.ImageHeight = SafeLoadIntFromElemAttr(tileset_elem.Element("image" ), "height", tileset.ImageHeight);
|
||||||
|
SafeLoadPropertiesFromOwnerElem(tileset_elem, tileset.Properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Common
|
||||||
|
// -----------------------------
|
||||||
|
|
||||||
|
static string SafeLoadStrFromElemAttr(XElement elem, string attr_name, string def_value) {
|
||||||
|
if ( elem != null && elem.Attribute(attr_name) != null ) {
|
||||||
|
return elem.Attribute(attr_name).Value;
|
||||||
|
}
|
||||||
|
return def_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SafeLoadIntFromElemAttr(XElement elem, string attr_name, int def_value) {
|
||||||
|
int value;
|
||||||
|
if ( int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return def_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool SafeLoadBoolFromElemAttr(XElement elem, string attr_name, bool def_value) {
|
||||||
|
int value;
|
||||||
|
if ( int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
|
||||||
|
return value != 0;
|
||||||
|
}
|
||||||
|
return def_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SafeLoadPropertiesFromOwnerElem(XElement owner_elem, List<string> props) {
|
||||||
|
var props_elem = owner_elem != null ? owner_elem.Element("properties") : null;
|
||||||
|
if ( props_elem != null ) {
|
||||||
|
foreach ( var prop_elem in props_elem.Elements("property") ) {
|
||||||
|
var prop_name = SafeLoadStrFromElemAttr(prop_elem, "name" , string.Empty);
|
||||||
|
var prop_value = SafeLoadStrFromElemAttr(prop_elem, "value", string.Empty);
|
||||||
|
props.Add(prop_name);
|
||||||
|
props.Add(prop_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace IsoTools.Tiled.Internal
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac5896bd1f00843dba1aa5a571380e1b
|
||||||
|
timeCreated: 1453182091
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
53
Assets/IsoTools/Tiled/TiledMapAsset.cs
Normal file
53
Assets/IsoTools/Tiled/TiledMapAsset.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace IsoTools.Tiled {
|
||||||
|
public enum TiledMapOrientation {
|
||||||
|
Isometric
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class TiledMapLayerData {
|
||||||
|
public string Name = string.Empty;
|
||||||
|
public int Width = 0;
|
||||||
|
public int Height = 0;
|
||||||
|
public int OffsetX = 0;
|
||||||
|
public int OffsetY = 0;
|
||||||
|
public bool Visible = true;
|
||||||
|
public List<int> Tiles = new List<int>();
|
||||||
|
public List<string> Properties = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class TiledMapTilesetData {
|
||||||
|
public int FirstGid = 0;
|
||||||
|
public string Name = string.Empty;
|
||||||
|
public int Margin = 0;
|
||||||
|
public int Spacing = 0;
|
||||||
|
public int TileWidth = 0;
|
||||||
|
public int TileHeight = 0;
|
||||||
|
public int TileCount = 0;
|
||||||
|
public int TileOffsetX = 0;
|
||||||
|
public int TileOffsetY = 0;
|
||||||
|
public string Image = string.Empty;
|
||||||
|
public int ImageWidth = 0;
|
||||||
|
public int ImageHeight = 0;
|
||||||
|
public List<string> Properties = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class TiledMapData {
|
||||||
|
public int Width = 0;
|
||||||
|
public int Height = 0;
|
||||||
|
public int TileWidth = 0;
|
||||||
|
public int TileHeight = 0;
|
||||||
|
public TiledMapOrientation Orientation = TiledMapOrientation.Isometric;
|
||||||
|
public List<string> Properties = new List<string>();
|
||||||
|
public List<TiledMapLayerData> Layers = new List<TiledMapLayerData>();
|
||||||
|
public List<TiledMapTilesetData> Tilesets = new List<TiledMapTilesetData>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TiledMapAsset : ScriptableObject {
|
||||||
|
public TiledMapData Data = new TiledMapData();
|
||||||
|
}
|
||||||
|
} // namespace IsoTools.Tiled
|
||||||
12
Assets/IsoTools/Tiled/TiledMapAsset.cs.meta
Normal file
12
Assets/IsoTools/Tiled/TiledMapAsset.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 88b6d219eb032493cacdfdd698dc960b
|
||||||
|
timeCreated: 1453182084
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,17 +1,10 @@
|
|||||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/PlayMaker/Internal/IsoFSMEvents.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Tiled/Internal/Editor/TiledMapPostprocessor.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoAddExplosionForce.cs" Line="54" Column="33" />
|
<File FileName="Assets/IsoTools/Tiled/Internal/Editor/TiledMapAssetEditor.cs" Line="20" Column="25" />
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoAddForce.cs" Line="64" Column="33" />
|
<File FileName="Assets/IsoTools/Tiled/Internal/Editor/TiledMapPostprocessor.cs" Line="14" Column="54" />
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoResize.cs" Line="58" Column="33" />
|
<File FileName="Assets/IsoTools/Tiled/TiledMapAsset.cs" Line="15" Column="3" NotebookId="1" />
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoSetPosition.cs" Line="46" Column="33" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoSetSize.cs" Line="46" Column="33" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoSetVelocity.cs" Line="33" Column="33" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoTranslate.cs" Line="58" Column="33" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoGetMode.cs" Line="35" Column="7" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Actions/IsoSetMode.cs" Line="32" Column="26" />
|
|
||||||
<File FileName="Assets/IsoTools/PlayMaker/Internal/IsoFSMEvents.cs" Line="23" Column="3" />
|
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user