mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-14 17:09:31 +07:00
create tiled map from asset wip
This commit is contained in:
@@ -64,11 +64,11 @@
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoRaycastHit.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoRigidbody.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoSphereCollider.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoTile.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoTileLayer.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoTileMap.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoWorld.cs" />
|
||||
<Compile Include="Assets\IsoTools\Tiled\TiledMap.cs" />
|
||||
<Compile Include="Assets\IsoTools\Tiled\TiledMapAsset.cs" />
|
||||
<Compile Include="Assets\IsoTools\Tiled\TiledMapLayer.cs" />
|
||||
<Compile Include="Assets\IsoTools\Tiled\TiledMapTile.cs" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace IsoTools.Internal {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( iso_world ) {
|
||||
_positions = targets
|
||||
.Where(p => p as IsoObject)
|
||||
.Where(p => p is IsoObject)
|
||||
.Select(p => p as IsoObject)
|
||||
.ToDictionary(p => p, p => p.transform.position);
|
||||
_iso_zpositions = targets
|
||||
.Where(p => p as IsoObject)
|
||||
.Where(p => p is IsoObject)
|
||||
.Select(p => p as IsoObject)
|
||||
.ToDictionary(p => p, p => p.position.z);
|
||||
_center = _viewCenter = _positions.Aggregate(Vector3.zero, (AccIn, p) => {
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace IsoTools.Internal {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// ChangeX
|
||||
// XChange
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -404,6 +404,34 @@ namespace IsoTools.Internal {
|
||||
return c;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// ColorChange
|
||||
// -----------------------------
|
||||
|
||||
public static Color ColorChangeA(Color color, float a) {
|
||||
var c = color;
|
||||
c.a = a;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Color ColorChangeR(Color color, float r) {
|
||||
var c = color;
|
||||
c.r = r;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Color ColorChangeG(Color color, float g) {
|
||||
var c = color;
|
||||
c.g = g;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Color ColorChangeB(Color color, float b) {
|
||||
var c = color;
|
||||
c.b = b;
|
||||
return c;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Approximately
|
||||
@@ -517,19 +545,21 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawRect(IsoWorld iso_world, Rect rect, float z, Color color) {
|
||||
public static void DrawGrid(IsoWorld iso_world, Vector3 pos, Vector3 size, Color color) {
|
||||
if ( iso_world ) {
|
||||
Handles.color = color;
|
||||
var points = new Vector3[]{
|
||||
new Vector3(rect.x, rect.y, z),
|
||||
new Vector3(rect.x, rect.y + rect.height, z),
|
||||
new Vector3(rect.x + rect.width, rect.y + rect.height, z),
|
||||
new Vector3(rect.x + rect.width, rect.y, z)
|
||||
};
|
||||
Handles.DrawLine(points[0], points[1]);
|
||||
Handles.DrawLine(points[1], points[2]);
|
||||
Handles.DrawLine(points[2], points[3]);
|
||||
Handles.DrawLine(points[3], points[0]);
|
||||
var size_x = Mathf.RoundToInt(size.x);
|
||||
var size_y = Mathf.RoundToInt(size.y);
|
||||
for ( var i = 0; i <= size_x; ++i ) {
|
||||
Handles.DrawLine(
|
||||
iso_world.IsoToScreen(new Vector3(pos.x + i, pos.y + 0.0f , pos.z)),
|
||||
iso_world.IsoToScreen(new Vector3(pos.x + i, pos.y + size_y, pos.z)));
|
||||
}
|
||||
for ( var i = 0; i <= size_y; ++i ) {
|
||||
Handles.DrawLine(
|
||||
iso_world.IsoToScreen(new Vector3(pos.x + 0.0f , pos.y + i, pos.z)),
|
||||
iso_world.IsoToScreen(new Vector3(pos.x + size_x, pos.y + i, pos.z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace IsoTools {
|
||||
public class IsoTile : MonoBehaviour {
|
||||
}
|
||||
} // namespace IsoTools
|
||||
@@ -1,6 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace IsoTools {
|
||||
public class IsoTileLayer : MonoBehaviour {
|
||||
}
|
||||
} // namespace IsoTools
|
||||
@@ -1,7 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace IsoTools {
|
||||
[RequireComponent(typeof(IsoObject))]
|
||||
public class IsoTileMap : MonoBehaviour {
|
||||
}
|
||||
} // namespace IsoTools
|
||||
9
Assets/IsoTools/Tiled/Examples/Maps.meta
Normal file
9
Assets/IsoTools/Tiled/Examples/Maps.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c2fbdd96ea4a4c8797c486bbc633541
|
||||
folderAsset: yes
|
||||
timeCreated: 1454257185
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,10 +28,10 @@ MonoBehaviour:
|
||||
Tiles: 01000000020000000100000010000000170000000e0000000400000001000000030000000200000001000000010000000100000002000000040000000500000006000000080000001300000007000000030000000400000003000000040000000300000001000000010000000200000001000000080000000700000002000000030000000400000004000000010000000200000004000000020000000100000003000000040000000100000002000000020000000100000001000000020000000400000005000000110000000d0000000d000000060000000100000003000000060000000200000003000000050000000d00000006000000030000000800000013000000130000000c0000000e00000001000000020000000a000000110000000d000000150000000f0000000700000003000000020000000400000001000000100000000a0000000600000003000000180000000b000000130000000700000004000000010000000100000005000000060000000100000010000000180000000e000000040000000f00000007000000040000000200000005000000060000000200000008000000160000000d00000009000000180000000e000000020000000400000004000000030000000100000008000000070000000400000001000000080000000c00000018000000170000000e00000002000000010000000200000004000000020000000200000003000000030000000400000003000000080000000f0000000c00000012000000030000000300000003000000050000000d00000006000000010000000200000002000000020000000300000004000000100000001200000001000000020000000400000010000000180000000a00000006000000020000000400000003000000040000000200000014000000120000000200000003000000010000001400000017000000180000000a00000006000000030000000300000004000000030000000800000007000000040000000400000002000000080000000c00000017000000180000001200000004000000030000000100000004000000030000000400000003000000040000000100000002000000080000000c000000180000000e000000040000000100000003000000020000000200000004000000040000000300000004000000030000000200000008000000130000000700000002000000020000000300000003000000020000000100000004000000
|
||||
Properties: []
|
||||
- Name: Tile Layer 2
|
||||
OffsetX: 0
|
||||
OffsetY: 0
|
||||
Visible: 1
|
||||
Tiles: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
OffsetX: 150
|
||||
OffsetY: -150
|
||||
Visible: 0
|
||||
Tiles: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
Properties:
|
||||
- layer prop
|
||||
- 765
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b96dccad0a464c0c8462411423c292a
|
||||
timeCreated: 1453399907
|
||||
guid: 7b6bd76df16f04c1aadbdf1c8812c49a
|
||||
timeCreated: 1454257185
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1216209dcca642f8a467ef74633b079
|
||||
timeCreated: 1453491116
|
||||
guid: 221bc03dca62748f284639c0b399875b
|
||||
timeCreated: 1454267285
|
||||
licenseType: Free
|
||||
TextureImporter:
|
||||
fileIDToRecycleName:
|
||||
@@ -68,7 +68,7 @@ TextureImporter:
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 1
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
textureType: 8
|
||||
buildTargetSettings: []
|
||||
@@ -268,7 +268,7 @@
|
||||
<tile gid="4"/>
|
||||
</data>
|
||||
</layer>
|
||||
<layer name="Tile Layer 2" width="14" height="16">
|
||||
<layer name="Tile Layer 2" width="14" height="16" visible="0" offsetx="150" offsety="-150">
|
||||
<properties>
|
||||
<property name="em" value=""/>
|
||||
<property name="layer prop" value="765"/>
|
||||
@@ -334,6 +334,8 @@
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="4"/>
|
||||
<tile gid="3"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
@@ -346,10 +348,8 @@
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="4"/>
|
||||
<tile gid="3"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
<tile gid="0"/>
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5c11b9c26a8e45329ed18f3df13478d
|
||||
timeCreated: 1453399906
|
||||
guid: 16b40ea9c34624e40bfb804614c5ae92
|
||||
timeCreated: 1454257185
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
9
Assets/IsoTools/Tiled/Examples/Scenes.meta
Normal file
9
Assets/IsoTools/Tiled/Examples/Scenes.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0727e91b8e19c4622b2fb287b71ec633
|
||||
folderAsset: yes
|
||||
timeCreated: 1454257201
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -85,45 +85,6 @@ NavMeshSettings:
|
||||
cellSize: 0.16666667
|
||||
manualCellSize: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &40999084
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 4
|
||||
m_Component:
|
||||
- 4: {fileID: 40999085}
|
||||
- 114: {fileID: 40999086}
|
||||
m_Layer: 0
|
||||
m_Name: TileLayer1
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &40999085
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 40999084}
|
||||
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_Children: []
|
||||
m_Father: {fileID: 1457742461}
|
||||
m_RootOrder: 1
|
||||
--- !u!114 &40999086
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 40999084}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a91f3c41a71c5484f9af8489443ef844, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &234184844
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -181,11 +142,11 @@ Camera:
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
near clip plane: -0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 350
|
||||
orthographic size: 3
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
@@ -206,7 +167,7 @@ Transform:
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 234184844}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalPosition: {x: 0, y: 2, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
@@ -222,106 +183,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 3f01619d3802e814f86f9e6bb965349a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_tileSize: 16
|
||||
_tileSize: 0.32
|
||||
_tileRatio: 0.5
|
||||
_tileAngle: 45
|
||||
_tileHeight: 16
|
||||
_tileHeight: 0.32
|
||||
_stepDepth: 0.1
|
||||
_startDepth: 1
|
||||
--- !u!1 &1457742458
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 4
|
||||
m_Component:
|
||||
- 4: {fileID: 1457742461}
|
||||
- 114: {fileID: 1457742460}
|
||||
- 114: {fileID: 1457742459}
|
||||
m_Layer: 0
|
||||
m_Name: TileMap
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1457742459
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1457742458}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 65223c9354c874240a67280485a6b300, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &1457742460
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1457742458}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_mode: 0
|
||||
_size: {x: 1, y: 1, z: 1}
|
||||
_position: {x: 0, y: 0, z: 0}
|
||||
_isAlignment: 1
|
||||
_isShowBounds: 1
|
||||
--- !u!4 &1457742461
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1457742458}
|
||||
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_Children:
|
||||
- {fileID: 1959786508}
|
||||
- {fileID: 40999085}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
--- !u!1 &1959786507
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 4
|
||||
m_Component:
|
||||
- 4: {fileID: 1959786508}
|
||||
- 114: {fileID: 1959786509}
|
||||
m_Layer: 0
|
||||
m_Name: TileLayer0
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1959786508
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1959786507}
|
||||
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_Children: []
|
||||
m_Father: {fileID: 1457742461}
|
||||
m_RootOrder: 0
|
||||
--- !u!114 &1959786509
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1959786507}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a91f3c41a71c5484f9af8489443ef844, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
@@ -1,64 +1,138 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using IsoTools.Tiled;
|
||||
using IsoTools.Internal;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace IsoTools.Tiled.Internal {
|
||||
[CustomEditor(typeof(TiledMapAsset))]
|
||||
public class TiledMapAssetEditor : Editor {
|
||||
TiledMapAsset _asset = null;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void CreateTiledMap(GameObject map_go) {
|
||||
var iso_object = map_go.AddComponent<IsoObject>();
|
||||
iso_object.mode = IsoObject.Mode.Mode3d;
|
||||
iso_object.position = Vector3.zero;
|
||||
iso_object.size = IsoUtils.Vec3FromXY(_asset.Data.Height, _asset.Data.Width);
|
||||
iso_object.isAlignment = true;
|
||||
iso_object.isShowBounds = true;
|
||||
|
||||
var tiled_map = map_go.AddComponent<TiledMap>();
|
||||
tiled_map.Asset = _asset;
|
||||
foreach ( var layer in _asset.Data.Layers ) {
|
||||
CreateTiledMapLayer(tiled_map, layer);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateTiledMapLayer(TiledMap map, TiledMapLayerData layer_data) {
|
||||
var layer_go = new GameObject(layer_data.Name);
|
||||
layer_go.transform.SetParent(map.transform, false);
|
||||
layer_go.transform.localPosition = IsoUtils.Vec3FromXY(layer_data.OffsetX, -layer_data.OffsetY);
|
||||
layer_go.SetActive(layer_data.Visible);
|
||||
|
||||
var tiled_layer = layer_go.AddComponent<TiledMapLayer>();
|
||||
tiled_layer.Asset = _asset;
|
||||
for ( var i = 0; i < _asset.Data.Height; ++i ) {
|
||||
for ( var j = 0; j < _asset.Data.Width; ++j ) {
|
||||
CreateTileMapTile(tiled_layer, layer_data, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateTileMapTile(TiledMapLayer layer, TiledMapLayerData layer_data, int j, int i) {
|
||||
var tile_gid = layer_data.Tiles[i*_asset.Data.Width + j];
|
||||
if ( tile_gid > 0 ) {
|
||||
var asset_path = AssetDatabase.GetAssetPath(_asset);
|
||||
if ( string.IsNullOrEmpty(asset_path) ) {
|
||||
throw new UnityException(string.Format(
|
||||
"not found tiled map asset ({0}) path",
|
||||
_asset.name));
|
||||
}
|
||||
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( !iso_world ) {
|
||||
throw new UnityException("not found IsoWorld");
|
||||
}
|
||||
|
||||
var tileset = FindTilesetByTileGid(tile_gid);
|
||||
if ( tileset == null ) {
|
||||
throw new UnityException(string.Format(
|
||||
"tileset for tile ({0}) on layer ({1}) not found",
|
||||
tile_gid, layer_data.Name));
|
||||
}
|
||||
|
||||
var tile_tileset_sprite_name = string.Format(
|
||||
"{0}_{1}",
|
||||
Path.GetFileNameWithoutExtension(tileset.ImageSource),
|
||||
tile_gid);
|
||||
var tileset_assets = AssetDatabase.LoadAllAssetsAtPath(
|
||||
Path.Combine(Path.GetDirectoryName(asset_path), tileset.ImageSource));
|
||||
var tile_sprite = tileset_assets
|
||||
.Where(p => p is Sprite && p.name == tile_tileset_sprite_name)
|
||||
.Select(p => p as Sprite)
|
||||
.FirstOrDefault();
|
||||
if ( !tile_sprite ) {
|
||||
throw new UnityException(string.Format(
|
||||
"sprite ({0}) for tile ({1}) on layer ({2}) not found",
|
||||
tile_tileset_sprite_name, tile_gid, layer_data.Name));
|
||||
}
|
||||
|
||||
var tile_go = new GameObject(string.Format("Tile_{0}_{1}", j, i));
|
||||
tile_go.transform.SetParent(layer.transform, false);
|
||||
|
||||
tile_go.transform.localPosition =
|
||||
iso_world.IsoToScreen(IsoUtils.Vec3FromXY(
|
||||
-i + _asset.Data.Height - 1,
|
||||
-j + _asset.Data.Width - 1));
|
||||
|
||||
tile_go.transform.localPosition += new Vector3(
|
||||
tileset.TileOffsetX / tile_sprite.pixelsPerUnit,
|
||||
tileset.TileOffsetY / tile_sprite.pixelsPerUnit,
|
||||
-(i + j) * iso_world.stepDepth);
|
||||
|
||||
var tiled_tile = tile_go.AddComponent<TiledMapTile>();
|
||||
tiled_tile.Asset = _asset;
|
||||
|
||||
var tile_spr = tile_go.AddComponent<SpriteRenderer>();
|
||||
tile_spr.sprite = tile_sprite;
|
||||
}
|
||||
}
|
||||
|
||||
TiledMapTilesetData FindTilesetByTileGid(int tile_gid) {
|
||||
return _asset.Data.Tilesets.Find(p => {
|
||||
return tile_gid >= p.FirstGid && tile_gid < p.FirstGid + p.TileCount;
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void OnEnable() {
|
||||
_asset = target as TiledMapAsset;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
DrawDefaultInspector();
|
||||
if ( GUILayout.Button("Create prefab") ) {
|
||||
//TestTestTest();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void TestTestTest() {
|
||||
foreach ( var layer in _asset.Data.Layers ) {
|
||||
for ( var i = 0; i < _asset.Data.Height; ++i ) {
|
||||
for ( var j = 0; j < _asset.Data.Width; ++j ) {
|
||||
var tile_gid = layer.Tiles[i*_asset.Data.Width + j];
|
||||
var tileset_data = FindTilesetByGid(tile_gid);
|
||||
if ( tileset_data != null ) {
|
||||
var sp_go = new GameObject();
|
||||
var sp = sp_go.AddComponent<SpriteRenderer>();
|
||||
var assets = AssetDatabase.LoadAllAssetsAtPath(
|
||||
string.Format("Assets/IsoTools/Tiled/Examples/{0}",
|
||||
tileset_data.ImageSource));
|
||||
|
||||
foreach ( var asset in assets ) {
|
||||
var aaa = asset as Sprite;
|
||||
if ( aaa && aaa.name == string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(tileset_data.ImageSource), tile_gid) ) {
|
||||
var go = new GameObject(string.Format("{0}_{1}", j, i));
|
||||
var iso_object = go.AddComponent<IsoObject>();
|
||||
iso_object.position = new Vector3(-i, -j, 0.0f);
|
||||
iso_object.size = Vector3.one;
|
||||
//iso_object.isShowBounds = true;
|
||||
sp.sprite = aaa;
|
||||
sp.transform.SetParent(go.transform, false);
|
||||
sp.transform.localPosition = new Vector3(tileset_data.TileOffsetX, tileset_data.TileOffsetY, 0.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( GUILayout.Button("Create tiled map on scene") ) {
|
||||
var map_go = new GameObject("TiledMap");
|
||||
try {
|
||||
CreateTiledMap(map_go);
|
||||
} catch ( Exception e ) {
|
||||
Debug.LogErrorFormat("Create tiled map error: {0}", e.Message);
|
||||
DestroyImmediate(map_go, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TiledMapTilesetData FindTilesetByGid(int gid) {
|
||||
foreach ( var tileset in _asset.Data.Tilesets ) {
|
||||
if ( gid >= tileset.FirstGid && gid < tileset.FirstGid + tileset.TileCount ) {
|
||||
return tileset;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
} // namespace IsoTools.Tiled.Internal
|
||||
58
Assets/IsoTools/Tiled/TiledMap.cs
Normal file
58
Assets/IsoTools/Tiled/TiledMap.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using IsoTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace IsoTools.Tiled {
|
||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(IsoObject))]
|
||||
public class TiledMap : MonoBehaviour {
|
||||
|
||||
public TiledMapAsset Asset = null;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void Awake() {
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void Reset() {
|
||||
}
|
||||
|
||||
void OnValidate() {
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
if ( iso_object.isShowBounds && iso_object.isoWorld ) {
|
||||
IsoUtils.DrawGrid(
|
||||
iso_object.isoWorld,
|
||||
iso_object.position, iso_object.size,
|
||||
IsoUtils.ColorChangeA(Color.green, 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace IsoTools.Tiled
|
||||
15
Assets/IsoTools/Tiled/TiledMapLayer.cs
Normal file
15
Assets/IsoTools/Tiled/TiledMapLayer.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using IsoTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace IsoTools.Tiled {
|
||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||
public class TiledMapLayer : MonoBehaviour {
|
||||
|
||||
public TiledMapAsset Asset = null;
|
||||
}
|
||||
} // namespace IsoTools.Tiled
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6151a74ad7049489693493e10480103a
|
||||
timeCreated: 1453567204
|
||||
guid: 2683a35aa9e5c4d7786be4a908523bbb
|
||||
timeCreated: 1454267808
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
15
Assets/IsoTools/Tiled/TiledMapTile.cs
Normal file
15
Assets/IsoTools/Tiled/TiledMapTile.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using IsoTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace IsoTools.Tiled {
|
||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||
public class TiledMapTile : MonoBehaviour {
|
||||
|
||||
public TiledMapAsset Asset = null;
|
||||
}
|
||||
} // namespace IsoTools.Tiled
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a91f3c41a71c5484f9af8489443ef844
|
||||
timeCreated: 1453567185
|
||||
guid: 6aede06b08d82497586194285ed30f71
|
||||
timeCreated: 1454274398
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
@@ -10,3 +10,6 @@ EditorSettings:
|
||||
m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d
|
||||
m_DefaultBehaviorMode: 1
|
||||
m_SpritePackerMode: 2
|
||||
m_SpritePackerPaddingPower: 1
|
||||
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
|
||||
m_ProjectGenerationRootNamespace:
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoTileMap.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Tiled/Internal/Editor/TiledMapAssetEditor.cs">
|
||||
<Files>
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoTile.cs" Line="6" Column="24" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoTileLayer.cs" Line="4" Column="27" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoTileMap.cs" Line="4" Column="25" />
|
||||
<File FileName="Assets/IsoTools/Tiled/TiledMapAsset.cs" Line="15" Column="10" NotebookId="1" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="331" Column="1" NotebookId="1" />
|
||||
<File FileName="Assets/IsoTools/Tiled/Internal/Editor/TiledMapAssetEditor.cs" Line="57" Column="55" />
|
||||
<File FileName="Assets/IsoTools/Tiled/Internal/Editor/TiledMapPostprocessor.cs" Line="138" Column="7" />
|
||||
<File FileName="Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/IsoTools/Tiled/TiledMapAsset.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/IsoTools/Tiled/TiledMapTile.cs" Line="14" Column="3" NotebookId="1" />
|
||||
<File FileName="Assets/IsoTools/Tiled/TiledMapLayer.cs" Line="5" Column="17" NotebookId="1" />
|
||||
<File FileName="Assets/IsoTools/Tiled/TiledMap.cs" Line="14" Column="37" NotebookId="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user