Show grid checkbox. Show properties in inspector.

This commit is contained in:
2016-02-06 02:13:38 +06:00
parent ba482724d3
commit 244b672b23
10 changed files with 91 additions and 264898 deletions

View File

@@ -416,7 +416,7 @@ namespace IsoTools {
bool IsIsoObjectDepends(IsoObject a, IsoObject b) { bool IsIsoObjectDepends(IsoObject a, IsoObject b) {
return return
a.Internal.ScreenRect.Overlaps(b.Internal.ScreenRect) && a.Internal.ScreenRect.Overlaps(b.Internal.ScreenRect, false) &&
IsIsoObjectDepends(a.position, a.size, b.position, b.size); IsIsoObjectDepends(a.position, a.size, b.position, b.size);
} }

View File

@@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 221bc03dca62748f284639c0b399875b guid: 221bc03dca62748f284639c0b399875b
timeCreated: 1454394623 timeCreated: 1454699157
licenseType: Free licenseType: Free
TextureImporter: TextureImporter:
fileIDToRecycleName: fileIDToRecycleName:

File diff suppressed because it is too large Load Diff

View File

@@ -18,12 +18,10 @@ namespace IsoTools.Tiled.Internal {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void CreateTiledMap(GameObject map_go) { void CreateTiledMap(GameObject map_go) {
var iso_object = map_go.AddComponent<IsoObject>(); var iso_object = map_go.AddComponent<IsoObject>();
iso_object.mode = IsoObject.Mode.Mode3d; iso_object.mode = IsoObject.Mode.Mode3d;
iso_object.position = Vector3.zero; iso_object.position = Vector3.zero;
iso_object.size = IsoUtils.Vec3FromXY(_asset.Data.Height, _asset.Data.Width); 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>(); var tiled_map = map_go.AddComponent<TiledMap>();
tiled_map.Asset = _asset; tiled_map.Asset = _asset;

View File

@@ -27,8 +27,7 @@ namespace IsoTools.Tiled.Internal {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
DrawDefaultInspector(); DrawDefaultInspector();
if ( _map && _map.Properties != null ) { if ( _map && _map.Properties != null ) {
GUILayout.Label(string.Format( _map.Properties.OnInspectorGUI("Map properties");
"Property count: {0}", _map.Properties.Count));
} }
} }
} }

View File

@@ -27,8 +27,7 @@ namespace IsoTools.Tiled.Internal {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
DrawDefaultInspector(); DrawDefaultInspector();
if ( _layer && _layer.Properties != null ) { if ( _layer && _layer.Properties != null ) {
GUILayout.Label(string.Format( _layer.Properties.OnInspectorGUI("Layer properties");
"Property count: {0}", _layer.Properties.Count));
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace IsoTools.Tiled.Internal { namespace IsoTools.Tiled.Internal {
@@ -51,6 +52,31 @@ namespace IsoTools.Tiled.Internal {
[Test] [Test]
public void Test03() { public void Test03() {
var props = new TiledMapProperties(null);
Assert.Throws<IndexOutOfRangeException>(() => {
props.GetKeyByIndex(0); });
Assert.Throws<IndexOutOfRangeException>(() => {
props.GetValueByIndex(0); });
var prop_list = new List<string>{
"prop1", "val1",
"prop2", "val2",
"prop3", "val3",
"prop4", "",
"fakep"
};
props = new TiledMapProperties(prop_list);
Assert.AreEqual(props.GetKeyByIndex (0), "prop1");
Assert.AreEqual(props.GetKeyByIndex (1), "prop2");
Assert.AreEqual(props.GetValueByIndex(0), "val1");
Assert.AreEqual(props.GetValueByIndex(1), "val2");
Assert.Throws<IndexOutOfRangeException>(() => {
props.GetKeyByIndex(-1); });
Assert.Throws<IndexOutOfRangeException>(() => {
props.GetValueByIndex(4); });
}
[Test]
public void Test04() {
var props = new TiledMapProperties(null); var props = new TiledMapProperties(null);
bool v0; bool v0;
short v1; short v1;
@@ -69,7 +95,7 @@ namespace IsoTools.Tiled.Internal {
} }
[Test] [Test]
public void Test04() { public void Test05() {
var prop_list = new List<string>{ var prop_list = new List<string>{
"bool" , "true", "bool" , "true",
"short" , "64", "short" , "64",

View File

@@ -27,8 +27,7 @@ namespace IsoTools.Tiled.Internal {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
DrawDefaultInspector(); DrawDefaultInspector();
if ( _tile && _tile.Properties != null ) { if ( _tile && _tile.Properties != null ) {
GUILayout.Label(string.Format( _tile.Properties.OnInspectorGUI("Tileset properties");
"Property count: {0}", _tile.Properties.Count));
} }
} }
} }

View File

@@ -14,6 +14,21 @@ namespace IsoTools.Tiled {
public TiledMapAsset Asset = null; public TiledMapAsset Asset = null;
public TiledMapProperties Properties = null; public TiledMapProperties Properties = null;
// ---------------------------------------------------------------------
//
// For editor
//
// ---------------------------------------------------------------------
#if UNITY_EDITOR
[SerializeField] bool _isShowGrid = false;
public bool isShowGrid {
get { return _isShowGrid; }
set { _isShowGrid = value; }
}
#endif
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// Functions // Functions
@@ -36,7 +51,7 @@ namespace IsoTools.Tiled {
void OnDisable() { void OnDisable() {
} }
#if UNITY_EDITOR #if UNITY_EDITOR
void Reset() { void Reset() {
} }
@@ -45,7 +60,7 @@ namespace IsoTools.Tiled {
void OnDrawGizmos() { void OnDrawGizmos() {
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
if ( iso_object.isShowBounds && iso_object.isoWorld ) { if ( isShowGrid && iso_object && iso_object.isoWorld ) {
IsoUtils.DrawGrid( IsoUtils.DrawGrid(
iso_object.isoWorld, iso_object.isoWorld,
iso_object.position, iso_object.size, iso_object.position, iso_object.size,
@@ -55,6 +70,6 @@ namespace IsoTools.Tiled {
void Update() { void Update() {
} }
#endif #endif
} }
} }

View File

@@ -1,7 +1,12 @@
using UnityEngine; using UnityEngine;
using System;
using System.Globalization; using System.Globalization;
using System.Collections.Generic; using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace IsoTools.Tiled { namespace IsoTools.Tiled {
public class TiledMapProperties { public class TiledMapProperties {
List<string> _properties = null; List<string> _properties = null;
@@ -22,6 +27,20 @@ namespace IsoTools.Tiled {
} }
} }
public string GetKeyByIndex(int index) {
if ( (uint)index >= (uint)Count ) {
throw new IndexOutOfRangeException();
}
return _properties[index * 2];
}
public string GetValueByIndex(int index) {
if ( (uint)index >= (uint)Count ) {
throw new IndexOutOfRangeException();
}
return _properties[index * 2 + 1];
}
public bool Has(string property_name) { public bool Has(string property_name) {
if ( _properties != null ) { if ( _properties != null ) {
for ( int i = 0, e = _properties.Count / 2; i < e; ++i ) { for ( int i = 0, e = _properties.Count / 2; i < e; ++i ) {
@@ -175,5 +194,23 @@ namespace IsoTools.Tiled {
value = string.Empty; value = string.Empty;
return false; return false;
} }
// -----------------------------
// For editor
// -----------------------------
#if UNITY_EDITOR
bool _showProperties = true;
public void OnInspectorGUI(string label) {
if ( Count > 0 ) {
_showProperties = EditorGUILayout.Foldout(_showProperties, label);
if ( _showProperties ) {
for ( int i = 0, e = Count; i < e; ++i ) {
EditorGUILayout.LabelField(GetKeyByIndex(i), GetValueByIndex(i));
}
}
}
}
#endif
} }
} }