style again

This commit is contained in:
2015-07-11 18:52:36 +06:00
parent 3437fa40ce
commit ff77d077e2
16 changed files with 103 additions and 141 deletions

View File

@@ -29,7 +29,7 @@ namespace IsoTools {
} }
} }
bool IsAnyAlignment { bool isAnyAlignment {
get { return _positions.Keys.Any(p => p.isAlignment); } get { return _positions.Keys.Any(p => p.isAlignment); }
} }
@@ -47,7 +47,7 @@ namespace IsoTools {
float ZMoveIsoObjects(float delta) { float ZMoveIsoObjects(float delta) {
Undo.RecordObjects(_iso_zpositions.Keys.ToArray(), "Move"); Undo.RecordObjects(_iso_zpositions.Keys.ToArray(), "Move");
var is_any_alignment = IsAnyAlignment; var is_any_alignment = isAnyAlignment;
return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => { return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => {
var iso_object = pair.Key; var iso_object = pair.Key;
var iso_orig_z = pair.Value; var iso_orig_z = pair.Value;
@@ -63,7 +63,7 @@ namespace IsoTools {
Vector3 XYMoveIsoObjects(Vector3 delta) { Vector3 XYMoveIsoObjects(Vector3 delta) {
Undo.RecordObjects(_positions.Keys.ToArray(), "Move"); Undo.RecordObjects(_positions.Keys.ToArray(), "Move");
var is_any_alignment = IsAnyAlignment; var is_any_alignment = isAnyAlignment;
return _positions.Aggregate(Vector3.zero, (AccIn, pair) => { return _positions.Aggregate(Vector3.zero, (AccIn, pair) => {
var iso_object = pair.Key; var iso_object = pair.Key;
var iso_orig_p = pair.Value; var iso_orig_p = pair.Value;

View File

@@ -42,8 +42,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: 1} _size: {x: 1, y: 1, z: 1}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21217528 --- !u!212 &21217528
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -42,8 +42,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: 3} _size: {x: 1, y: 1, z: 3}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21263702 --- !u!212 &21263702
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -42,8 +42,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 3, z: 1} _size: {x: 1, y: 3, z: 1}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21253620 --- !u!212 &21253620
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -42,8 +42,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 3, y: 1, z: 1} _size: {x: 3, y: 1, z: 1}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21262204 --- !u!212 &21262204
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -42,8 +42,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 3, y: 3, z: 0} _size: {x: 3, y: 3, z: 0}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21253404 --- !u!212 &21253404
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -39,7 +39,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 114888} m_GameObject: {fileID: 114888}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 32, y: 16, z: 22.2222233} m_LocalPosition: {x: 1.29999995, y: .649999976, z: 22.2222233}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 483872} - {fileID: 483872}
@@ -70,8 +70,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: .529999971} _size: {x: 1, y: 1, z: .529999971}
_position: {x: 2, y: 0, z: 0} _position: {x: 2, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21221408 --- !u!212 &21221408
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -39,7 +39,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 155780} m_GameObject: {fileID: 155780}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -64, y: 0, z: 0} m_LocalPosition: {x: -2.5999999, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 457334} - {fileID: 457334}
@@ -70,8 +70,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: .529999971} _size: {x: 1, y: 1, z: .529999971}
_position: {x: -2, y: 2, z: 0} _position: {x: -2, y: 2, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21228980 --- !u!212 &21228980
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -51,7 +51,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 112436} m_GameObject: {fileID: 112436}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 32, y: -16, z: 0} m_LocalPosition: {x: 1.29999995, y: -.649999976, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 400788} - {fileID: 400788}
@@ -70,8 +70,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: .529999971} _size: {x: 1, y: 1, z: .529999971}
_position: {x: 0, y: -2, z: 0} _position: {x: 0, y: -2, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21298190 --- !u!212 &21298190
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -70,8 +70,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_size: {x: 1, y: 1, z: .529999971} _size: {x: 1, y: 1, z: .529999971}
_position: {x: 0, y: 0, z: 0} _position: {x: 0, y: 0, z: 0}
_alignment: 1 _isAlignment: 1
_showBounds: 0 _isShowBounds: 0
--- !u!212 &21238442 --- !u!212 &21238442
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -184,6 +184,10 @@ Prefab:
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 4 value: 4
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: m_Name
value: Road0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@@ -394,7 +398,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: m_Name propertyPath: m_Name
value: Road 4 value: Road9
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: _showBounds propertyPath: _showBounds
@@ -456,7 +460,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: m_Name propertyPath: m_Name
value: Road 2 value: Road8
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: _showBounds propertyPath: _showBounds
@@ -516,6 +520,10 @@ Prefab:
propertyPath: _position.y propertyPath: _position.y
value: 1 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 166186, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2}
propertyPath: m_Name
value: CityTile_066
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@@ -916,6 +924,10 @@ Prefab:
propertyPath: _position.y propertyPath: _position.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11438418, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2}
propertyPath: _position.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 30a269be2fc864c9ea00c7a65636d543, type: 2}
m_IsPrefabParent: 0 m_IsPrefabParent: 0
@@ -1088,7 +1100,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: m_Name propertyPath: m_Name
value: Road 5 value: Road10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: _showBounds propertyPath: _showBounds
@@ -1498,7 +1510,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 114888, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: m_Name propertyPath: m_Name
value: Road 1 value: Road7
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2} - target: {fileID: 11480044, guid: 04fdbaa6703674aa59a45e7b9fa9fff6, type: 2}
propertyPath: _showBounds propertyPath: _showBounds
@@ -2106,7 +2118,7 @@ Transform:
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1768303655} m_GameObject: {fileID: 1768303655}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0, y: 1.99000001, z: -10} m_LocalPosition: {x: -0, y: 2, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}

View File

@@ -5,8 +5,7 @@ using UnityEditor;
#endif #endif
namespace IsoTools { namespace IsoTools {
[ExecuteInEditMode] [ExecuteInEditMode, DisallowMultipleComponent]
[DisallowMultipleComponent]
public class IsoObject : MonoBehaviour { public class IsoObject : MonoBehaviour {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -18,7 +17,6 @@ namespace IsoTools {
[SerializeField] [SerializeField]
Vector3 _size = Vector3.one; Vector3 _size = Vector3.one;
/// <summary>Isometric object size.</summary>
public Vector3 size { public Vector3 size {
get { return _size; } get { return _size; }
set { set {
@@ -27,35 +25,29 @@ namespace IsoTools {
} }
} }
/// <summary>Isometric object size X.</summary>
public float sizeX { public float sizeX {
get { return size.x; } get { return size.x; }
set { size = IsoUtils.Vec3ChangeX(size, value); } set { size = IsoUtils.Vec3ChangeX(size, value); }
} }
/// <summary>Isometric object size Y.</summary>
public float sizeY { public float sizeY {
get { return size.y; } get { return size.y; }
set { size = IsoUtils.Vec3ChangeY(size, value); } set { size = IsoUtils.Vec3ChangeY(size, value); }
} }
/// <summary>Isometric object size Z.</summary>
public float sizeZ { public float sizeZ {
get { return size.z; } get { return size.z; }
set { size = IsoUtils.Vec3ChangeZ(size, value); } set { size = IsoUtils.Vec3ChangeZ(size, value); }
} }
/// <summary>Isometric object size XY.</summary>
public Vector2 sizeXY { public Vector2 sizeXY {
get { return new Vector2(sizeX, sizeY); } get { return new Vector2(sizeX, sizeY); }
} }
/// <summary>Isometric object size YZ.</summary>
public Vector2 sizeYZ { public Vector2 sizeYZ {
get { return new Vector2(sizeY, sizeZ); } get { return new Vector2(sizeY, sizeZ); }
} }
/// <summary>Isometric object size XZ.</summary>
public Vector2 sizeXZ { public Vector2 sizeXZ {
get { return new Vector2(sizeX, sizeZ); } get { return new Vector2(sizeX, sizeZ); }
} }
@@ -69,7 +61,6 @@ namespace IsoTools {
[SerializeField] [SerializeField]
Vector3 _position = Vector3.zero; Vector3 _position = Vector3.zero;
/// <summary>Isometric object position.</summary>
public Vector3 position { public Vector3 position {
get { return _position; } get { return _position; }
set { set {
@@ -78,35 +69,29 @@ namespace IsoTools {
} }
} }
/// <summary>Isometric object position X.</summary>
public float positionX { public float positionX {
get { return position.x; } get { return position.x; }
set { position = IsoUtils.Vec3ChangeX(position, value); } set { position = IsoUtils.Vec3ChangeX(position, value); }
} }
/// <summary>Isometric object position Y.</summary>
public float positionY { public float positionY {
get { return position.y; } get { return position.y; }
set { position = IsoUtils.Vec3ChangeY(position, value); } set { position = IsoUtils.Vec3ChangeY(position, value); }
} }
/// <summary>Isometric object position Z.</summary>
public float positionZ { public float positionZ {
get { return position.z; } get { return position.z; }
set { position = IsoUtils.Vec3ChangeZ(position, value); } set { position = IsoUtils.Vec3ChangeZ(position, value); }
} }
/// <summary>Isometric object position XY.</summary>
public Vector2 positionXY { public Vector2 positionXY {
get { return new Vector2(positionX, positionY); } get { return new Vector2(positionX, positionY); }
} }
/// <summary>Isometric object position YZ.</summary>
public Vector2 positionYZ { public Vector2 positionYZ {
get { return new Vector2(positionY, positionZ); } get { return new Vector2(positionY, positionZ); }
} }
/// <summary>Isometric object position XZ.</summary>
public Vector2 positionXZ { public Vector2 positionXZ {
get { return new Vector2(positionX, positionZ); } get { return new Vector2(positionX, positionZ); }
} }
@@ -117,41 +102,34 @@ namespace IsoTools {
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/// <summary>Isometric object tile position.</summary>
public Vector3 tilePosition { public Vector3 tilePosition {
get { return IsoUtils.Vec3Round(position); } get { return IsoUtils.Vec3Round(position); }
set { position = value; } set { position = value; }
} }
/// <summary>Isometric object tile position X.</summary>
public float tilePositionX { public float tilePositionX {
get { return tilePosition.x; } get { return tilePosition.x; }
set { tilePosition = IsoUtils.Vec3ChangeX(tilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeX(tilePosition, value); }
} }
/// <summary>Isometric object tile position Y.</summary>
public float tilePositionY { public float tilePositionY {
get { return tilePosition.y; } get { return tilePosition.y; }
set { tilePosition = IsoUtils.Vec3ChangeY(tilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeY(tilePosition, value); }
} }
/// <summary>Isometric object tile position Z.</summary>
public float tilePositionZ { public float tilePositionZ {
get { return tilePosition.z; } get { return tilePosition.z; }
set { tilePosition = IsoUtils.Vec3ChangeZ(tilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeZ(tilePosition, value); }
} }
/// <summary>Isometric object tile position XY.</summary>
public Vector2 tilePositionXY { public Vector2 tilePositionXY {
get { return new Vector2(tilePositionX, tilePositionY); } get { return new Vector2(tilePositionX, tilePositionY); }
} }
/// <summary>Isometric object tile position YZ.</summary>
public Vector2 tilePositionYZ { public Vector2 tilePositionYZ {
get { return new Vector2(tilePositionY, tilePositionZ); } get { return new Vector2(tilePositionY, tilePositionZ); }
} }
/// <summary>Isometric object tile position XZ.</summary>
public Vector2 tilePositionXZ { public Vector2 tilePositionXZ {
get { return new Vector2(tilePositionX, tilePositionZ); } get { return new Vector2(tilePositionX, tilePositionZ); }
} }
@@ -165,7 +143,7 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
Vector3 _lastSize = Vector3.zero; Vector3 _lastSize = Vector3.zero;
Vector3 _lastPosition = Vector3.zero; Vector3 _lastPosition = Vector3.zero;
Vector2 _lastTransform = Vector2.zero; Vector2 _lastTransPos = Vector2.zero;
[SerializeField] bool _isAlignment = true; [SerializeField] bool _isAlignment = true;
[SerializeField] bool _isShowBounds = false; [SerializeField] bool _isShowBounds = false;
@@ -204,7 +182,7 @@ namespace IsoTools {
public void FixTransform() { public void FixTransform() {
#if UNITY_EDITOR #if UNITY_EDITOR
if ( Application.isEditor && !Application.isPlaying && isAlignment ) { if ( !Application.isPlaying && isAlignment ) {
_position = tilePosition; _position = tilePosition;
} }
#endif #endif
@@ -226,7 +204,7 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
_lastSize = size; _lastSize = size;
_lastPosition = position; _lastPosition = position;
_lastTransform = transform.position; _lastTransPos = transform.position;
#endif #endif
} }
@@ -236,12 +214,16 @@ namespace IsoTools {
void MarkEditorObjectDirty() { void MarkEditorObjectDirty() {
#if UNITY_EDITOR #if UNITY_EDITOR
if ( Application.isEditor ) {
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
}
#endif #endif
} }
// ------------------------------------------------------------------------
//
// Messages
//
// ------------------------------------------------------------------------
void Awake() { void Awake() {
FixLastProperties(); FixLastProperties();
FixIsoPosition(); FixIsoPosition();
@@ -263,24 +245,22 @@ namespace IsoTools {
} }
void OnDrawGizmos() { void OnDrawGizmos() {
if ( isShowBounds && isoWorld ) { if ( isShowBounds ) {
IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red); IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red);
} }
} }
void Update() { void Update() {
if ( Application.isEditor ) {
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) { if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
size = _size; size = _size;
} }
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) { if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
position = _position; position = _position;
} }
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) { if ( !IsoUtils.Vec2Approximately(_lastTransPos, transform.position) ) {
FixIsoPosition(); FixIsoPosition();
} }
} }
}
#endif #endif
} }
} // namespace IsoTools } // namespace IsoTools

View File

@@ -1,5 +1,4 @@
using UnityEngine; using UnityEngine;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
#if UNITY_EDITOR #if UNITY_EDITOR
@@ -7,8 +6,7 @@ using UnityEditor;
#endif #endif
namespace IsoTools { namespace IsoTools {
[ExecuteInEditMode] [ExecuteInEditMode, DisallowMultipleComponent]
[DisallowMultipleComponent]
public class IsoWorld : MonoBehaviour { public class IsoWorld : MonoBehaviour {
class ObjectInfo { class ObjectInfo {
@@ -49,9 +47,14 @@ namespace IsoTools {
Vector3 _objsMaxNumPos = Vector3.zero; Vector3 _objsMaxNumPos = Vector3.zero;
Vector3 _objsNumPosCount = Vector3.zero; Vector3 _objsNumPosCount = Vector3.zero;
// ------------------------------------------------------------------------
//
// Public
//
// ------------------------------------------------------------------------
[SerializeField] [SerializeField]
public float _tileSize = 32.0f; public float _tileSize = 32.0f;
/// <summary>Isometric tile size.</summary>
public float tileSize { public float tileSize {
get { return _tileSize; } get { return _tileSize; }
set { set {
@@ -62,7 +65,6 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _minDepth = 0.0f; public float _minDepth = 0.0f;
/// <summary>Min sorting depth value.</summary>
public float minDepth { public float minDepth {
get { return _minDepth; } get { return _minDepth; }
set { set {
@@ -73,7 +75,6 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _maxDepth = 100.0f; public float _maxDepth = 100.0f;
/// <summary>Max sorting depth value.</summary>
public float maxDepth { public float maxDepth {
get { return _maxDepth; } get { return _maxDepth; }
set { set {
@@ -82,48 +83,23 @@ namespace IsoTools {
} }
} }
// ------------------------------------------------------------------------
/// <summary>
/// Marks world for resorting.
/// </summary>
// ------------------------------------------------------------------------
public void MarkDirty() { public void MarkDirty() {
_dirty = true; _dirty = true;
MarkEditorWorldDirty(); MarkEditorWorldDirty();
} }
// ------------------------------------------------------------------------
/// <summary>
/// Marks world for resorting.
/// </summary>
/// <param name="iso_object">Isometric object for resorting.</param>
// ------------------------------------------------------------------------
public void MarkDirty(IsoObject iso_object) { public void MarkDirty(IsoObject iso_object) {
if ( !_dirty && iso_object && _visibles.Contains(iso_object) ) { if ( !_dirty && iso_object && _visibles.Contains(iso_object) ) {
MarkDirty(); MarkDirty();
} }
} }
// ------------------------------------------------------------------------
/// <summary>
/// Convert isometric coordinates to screen coordinates
/// </summary>
/// <returns>Screen coordinates</returns>
/// <param name="pos">Isometric coordinates.</param>
// ------------------------------------------------------------------------
public Vector2 IsoToScreen(Vector3 pos) { public Vector2 IsoToScreen(Vector3 pos) {
return new Vector2( return new Vector2(
(pos.x - pos.y), (pos.x - pos.y),
(pos.x + pos.y) * 0.5f + pos.z) * tileSize; (pos.x + pos.y) * 0.5f + pos.z) * tileSize;
} }
// ------------------------------------------------------------------------
/// <summary>
/// Convert screen coordinates to isometric coordinates
/// </summary>
/// <returns>Isometric coordinates</returns>
/// <param name="pos">Screen coordinates.</param>
// ------------------------------------------------------------------------
public Vector3 ScreenToIso(Vector2 pos) { public Vector3 ScreenToIso(Vector2 pos) {
return new Vector3( return new Vector3(
(pos.x * 0.5f + pos.y), (pos.x * 0.5f + pos.y),
@@ -131,14 +107,6 @@ namespace IsoTools {
0.0f) / tileSize; 0.0f) / tileSize;
} }
// ------------------------------------------------------------------------
/// <summary>
/// Convert screen coordinates to isometric coordinates with specified isometric height
/// </summary>
/// <returns>Isometric coordinates</returns>
/// <param name="pos">Screen coordinates.</param>
/// <param name="iso_z">Point isometric height.</param>
// ------------------------------------------------------------------------
public Vector3 ScreenToIso(Vector2 pos, float iso_z) { public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
return IsoUtils.Vec3ChangeZ( return IsoUtils.Vec3ChangeZ(
ScreenToIso(new Vector2(pos.x, pos.y - iso_z * tileSize)), ScreenToIso(new Vector2(pos.x, pos.y - iso_z * tileSize)),
@@ -172,9 +140,7 @@ namespace IsoTools {
void MarkEditorWorldDirty() { void MarkEditorWorldDirty() {
#if UNITY_EDITOR #if UNITY_EDITOR
if ( Application.isEditor ) {
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
}
#endif #endif
} }
@@ -388,6 +354,12 @@ namespace IsoTools {
} }
} }
// ------------------------------------------------------------------------
//
// Messages
//
// ------------------------------------------------------------------------
void Start() { void Start() {
ChangeSortingProperty(); ChangeSortingProperty();
StepSort(); StepSort();

View File

@@ -1,11 +1,9 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoObject.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
<Files> <Files>
<File FileName="Assets/IsoTools/Scripts/IsoFakeObject.cs" Line="1" Column="1" /> <File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="234" Column="4" />
<File FileName="Assets/IsoTools/Examples/Scripts/IsoEchoListener.cs" Line="1" Column="1" /> <File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="244" Column="35" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="1" Column="1" />
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="175" Column="4" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>