From b79a1adcd49e2e1ac56a8b9bf3b776e8f7ef625f Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 15 Dec 2016 00:40:17 +0700 Subject: [PATCH] debug show depends --- Assets/IsoTools/Scripts/Internal/IsoUtils.cs | 11 ++++ Assets/IsoTools/Scripts/IsoObject.cs | 67 ++++++++++++++++---- Assets/IsoTools/Scripts/IsoWorld.cs | 12 ++-- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Assets/IsoTools/Scripts/Internal/IsoUtils.cs b/Assets/IsoTools/Scripts/Internal/IsoUtils.cs index 3b62072..55e504a 100644 --- a/Assets/IsoTools/Scripts/Internal/IsoUtils.cs +++ b/Assets/IsoTools/Scripts/Internal/IsoUtils.cs @@ -520,6 +520,17 @@ namespace IsoTools.Internal { } } + public static void DrawLine(Vector2 begin, Vector2 end, Color color) { + Handles.color = color; + Handles.DrawLine(begin, end); + } + + public static void DrawLine(Vector2 begin, Vector2 end, Color begin_color, Color end_color, float color_ratio) { + var ratio_point = begin + (end - begin) * color_ratio; + DrawLine(begin, ratio_point, begin_color); + DrawLine(ratio_point, end, end_color); + } + public static void DrawRect(IsoRect rect, Color color) { Handles.color = color; var point0 = new Vector2(rect.x.min, rect.y.min); diff --git a/Assets/IsoTools/Scripts/IsoObject.cs b/Assets/IsoTools/Scripts/IsoObject.cs index ea2de28..05a5747 100644 --- a/Assets/IsoTools/Scripts/IsoObject.cs +++ b/Assets/IsoTools/Scripts/IsoObject.cs @@ -194,7 +194,7 @@ namespace IsoTools { public class InternalState { public bool Dirty = false; public bool Placed = false; - public IsoRect ScreenRect = IsoRect.zero; + public IsoRect ScreenBounds = IsoRect.zero; public IsoMinMax MinMax3d = IsoMinMax.zero; public float Offset3d = 0.0f; public Vector2 MinSector = Vector2.zero; @@ -215,12 +215,26 @@ namespace IsoTools { // --------------------------------------------------------------------- #if UNITY_EDITOR - [Space(10)] - [SerializeField] bool _isShowBounds = false; - - public bool isShowBounds { - get { return _isShowBounds; } - set { _isShowBounds = value; } + [Header("Editor Only")] + [SerializeField] bool _showIsoBounds = false; + public bool isShowIsoBounds { + get { return _showIsoBounds; } + set { _showIsoBounds = value; } + } + [SerializeField] bool _showScreenBounds = false; + public bool isShowScreenBounds { + get { return _showScreenBounds; } + set { _showScreenBounds = value; } + } + [SerializeField] bool _showSelfDepends = false; + public bool isShowSelfDepends { + get { return _showSelfDepends; } + set { _showSelfDepends = value; } + } + [SerializeField] bool _showTheirDepends = false; + public bool isShowTheirDepends { + get { return _showTheirDepends; } + set { _showTheirDepends = value; } } #endif @@ -246,7 +260,7 @@ namespace IsoTools { Internal.Transform.position = IsoUtils.Vec3ChangeZ( iso_world.IsoToScreen(position), Internal.Transform.position.z); - FixScreenRect(); + FixScreenBounds(); } FixLastProperties(); MartDirtyIsoWorld(); @@ -269,14 +283,14 @@ namespace IsoTools { Internal.Renderers.Clear(); } - void FixScreenRect() { + void FixScreenBounds() { var iso_world = isoWorld; if ( iso_world ) { var l = iso_world.IsoToScreen(position + IsoUtils.Vec3FromY(size.y)).x; var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x; var b = iso_world.IsoToScreen(position).y; var t = iso_world.IsoToScreen(position + size).y; - Internal.ScreenRect = new IsoRect(l, b, r, t); + Internal.ScreenBounds = new IsoRect(l, b, r, t); } } @@ -343,8 +357,37 @@ namespace IsoTools { } void OnDrawGizmos() { - if ( isShowBounds && isoWorld ) { - IsoUtils.DrawIsoCube(isoWorld, position + size * 0.5f, size, Color.red); + if ( isShowIsoBounds && isoWorld ) { + IsoUtils.DrawIsoCube( + isoWorld, + position + size * 0.5f, + size, + Color.red); + } + if ( isShowScreenBounds ) { + IsoUtils.DrawRect( + Internal.ScreenBounds, + Color.green); + } + if ( isShowSelfDepends ) { + for ( int i = 0, e = Internal.SelfDepends.Count; i < e; ++i ) { + IsoUtils.DrawLine( + Internal.ScreenBounds.center, + Internal.SelfDepends[i].Internal.ScreenBounds.center, + Color.blue, + Color.red, + 0.75f); + } + } + if ( isShowTheirDepends ) { + for ( int i = 0, e = Internal.TheirDepends.Count; i < e; ++i ) { + IsoUtils.DrawLine( + Internal.ScreenBounds.center, + Internal.TheirDepends[i].Internal.ScreenBounds.center, + Color.cyan, + Color.red, + 0.75f); + } } } #endif diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index a103e7c..70ba8c5 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -466,7 +466,7 @@ namespace IsoTools { bool IsIsoObjectDepends(IsoObject a, IsoObject b) { return - a.Internal.ScreenRect.Overlaps(b.Internal.ScreenRect) && + a.Internal.ScreenBounds.Overlaps(b.Internal.ScreenBounds) && IsIsoObjectDepends(a.position, a.size, b.position, b.size); } @@ -511,7 +511,7 @@ namespace IsoTools { _sectorsSize = 0.0f; for ( int i = 0, e = _visibles.Count; i < e; ++i ) { var iso_internal = _visibles[i].Internal; - _sectorsSize += IsoUtils.Vec2MaxF(iso_internal.ScreenRect.size); + _sectorsSize += IsoUtils.Vec2MaxF(iso_internal.ScreenBounds.size); } var min_sector_size_xy = IsoToScreen(IsoUtils.vec3OneXY) - IsoToScreen(Vector3.zero); var min_sector_size = Mathf.Max(min_sector_size_xy.x, min_sector_size_xy.y); @@ -528,10 +528,10 @@ namespace IsoTools { var iso_internal = _visibles[i].Internal; // high performance tricks - var min_x = iso_internal.ScreenRect.x.min / _sectorsSize; - var min_y = iso_internal.ScreenRect.y.min / _sectorsSize; - var max_x = iso_internal.ScreenRect.x.max / _sectorsSize; - var max_y = iso_internal.ScreenRect.y.max / _sectorsSize; + var min_x = iso_internal.ScreenBounds.x.min / _sectorsSize; + var min_y = iso_internal.ScreenBounds.y.min / _sectorsSize; + var max_x = iso_internal.ScreenBounds.x.max / _sectorsSize; + var max_y = iso_internal.ScreenBounds.y.max / _sectorsSize; iso_internal.MinSector.x = (int)(min_x >= 0.0f ? min_x : min_x - 1.0f); iso_internal.MinSector.y = (int)(min_y >= 0.0f ? min_y : min_y - 1.0f); iso_internal.MaxSector.x = (int)(max_x >= 0.0f ? max_x + 1.0f : max_x);