diff --git a/Assets/IsoTools/Examples/Scenes/Test3.unity b/Assets/IsoTools/Examples/Scenes/Test3.unity index 8be6d75..8e7d194 100644 --- a/Assets/IsoTools/Examples/Scenes/Test3.unity +++ b/Assets/IsoTools/Examples/Scenes/Test3.unity @@ -188,4 +188,186 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: 3 +--- !u!1001 &1110096374 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.x + value: 15.9999981 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.y + value: 8 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.z + value: 1.10000002 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.x + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 117528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_Name + value: Cube_1x1x1 (1) + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _isShowBounds + value: 1 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + m_IsPrefabParent: 0 +--- !u!1001 &1345148404 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.x + value: -16 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.y + value: 7.99999905 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.z + value: 1.20000005 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 117528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_Name + value: Cube_1x1x1 (2) + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _isShowBounds + value: 1 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + m_IsPrefabParent: 0 +--- !u!1001 &2072542029 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalPosition.z + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _position.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + propertyPath: _isShowBounds + value: 1 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2} + m_IsPrefabParent: 0 diff --git a/Assets/IsoTools/Scripts/IsoObject.cs b/Assets/IsoTools/Scripts/IsoObject.cs index 261b7a3..3262865 100644 --- a/Assets/IsoTools/Scripts/IsoObject.cs +++ b/Assets/IsoTools/Scripts/IsoObject.cs @@ -166,6 +166,7 @@ namespace IsoTools { public class InternalState { public bool Dirty = false; public bool Visited = false; + public Rect IsoRect = new Rect(); public Bounds Bounds3d = new Bounds(); public float Offset3d = 0.0f; public Vector3 MinSector = Vector3.zero; @@ -227,6 +228,7 @@ namespace IsoTools { transform.position = IsoUtils.Vec3ChangeZ( isoWorld.IsoToScreen(position), transform.position.z); + FixInternalIsoRect(); } FixLastProperties(); MartDirtyIsoWorld(); @@ -240,6 +242,16 @@ namespace IsoTools { } } + void FixInternalIsoRect() { + if ( isoWorld ) { + var l = isoWorld.IsoToScreen(position + IsoUtils.Vec3FromY(size.y)).x; + var r = isoWorld.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x; + var b = isoWorld.IsoToScreen(position).y; + var t = isoWorld.IsoToScreen(position + size).y; + Internal.IsoRect = new Rect(l, t, r - l, t - b); + } + } + void FixLastProperties() { #if UNITY_EDITOR _lastSize = size; @@ -299,6 +311,7 @@ namespace IsoTools { void OnDrawGizmos() { if ( isShowBounds && isoWorld ) { IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red); + IsoUtils.DrawRect(isoWorld, Internal.IsoRect, transform.position.z, Color.green); } } diff --git a/Assets/IsoTools/Scripts/IsoUtils.cs b/Assets/IsoTools/Scripts/IsoUtils.cs index fe705f5..981e40b 100644 --- a/Assets/IsoTools/Scripts/IsoUtils.cs +++ b/Assets/IsoTools/Scripts/IsoUtils.cs @@ -454,6 +454,22 @@ namespace IsoTools { radius * iso_world.tileSize * 2.0f); } } + + public static void DrawRect(IsoWorld iso_world, Rect rect, float z, 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]); + } + } #endif } } \ No newline at end of file diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index c1aca9d..53afb01 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -140,6 +140,7 @@ namespace IsoTools { } public void RemoveIsoObject(IsoObject iso_object) { + ClearIsoObjectDepends(iso_object); _objects.Remove(iso_object); _visibles.Remove(iso_object); _oldVisibles.Remove(iso_object); @@ -236,7 +237,9 @@ namespace IsoTools { } bool IsIsoObjectDepends(IsoObject a, IsoObject b) { - return IsIsoObjectDepends(a.position, a.size, b.position, b.size); + return + a.Internal.IsoRect.Overlaps(b.Internal.IsoRect) && + IsIsoObjectDepends(a.position, a.size, b.position, b.size); } int SectorIndex(Vector3 num_pos) {