mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
debug show depends
This commit is contained in:
@@ -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) {
|
public static void DrawRect(IsoRect rect, Color color) {
|
||||||
Handles.color = color;
|
Handles.color = color;
|
||||||
var point0 = new Vector2(rect.x.min, rect.y.min);
|
var point0 = new Vector2(rect.x.min, rect.y.min);
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ namespace IsoTools {
|
|||||||
public class InternalState {
|
public class InternalState {
|
||||||
public bool Dirty = false;
|
public bool Dirty = false;
|
||||||
public bool Placed = false;
|
public bool Placed = false;
|
||||||
public IsoRect ScreenRect = IsoRect.zero;
|
public IsoRect ScreenBounds = IsoRect.zero;
|
||||||
public IsoMinMax MinMax3d = IsoMinMax.zero;
|
public IsoMinMax MinMax3d = IsoMinMax.zero;
|
||||||
public float Offset3d = 0.0f;
|
public float Offset3d = 0.0f;
|
||||||
public Vector2 MinSector = Vector2.zero;
|
public Vector2 MinSector = Vector2.zero;
|
||||||
@@ -215,12 +215,26 @@ namespace IsoTools {
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
[Space(10)]
|
[Header("Editor Only")]
|
||||||
[SerializeField] bool _isShowBounds = false;
|
[SerializeField] bool _showIsoBounds = false;
|
||||||
|
public bool isShowIsoBounds {
|
||||||
public bool isShowBounds {
|
get { return _showIsoBounds; }
|
||||||
get { return _isShowBounds; }
|
set { _showIsoBounds = value; }
|
||||||
set { _isShowBounds = 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
|
#endif
|
||||||
|
|
||||||
@@ -246,7 +260,7 @@ namespace IsoTools {
|
|||||||
Internal.Transform.position = IsoUtils.Vec3ChangeZ(
|
Internal.Transform.position = IsoUtils.Vec3ChangeZ(
|
||||||
iso_world.IsoToScreen(position),
|
iso_world.IsoToScreen(position),
|
||||||
Internal.Transform.position.z);
|
Internal.Transform.position.z);
|
||||||
FixScreenRect();
|
FixScreenBounds();
|
||||||
}
|
}
|
||||||
FixLastProperties();
|
FixLastProperties();
|
||||||
MartDirtyIsoWorld();
|
MartDirtyIsoWorld();
|
||||||
@@ -269,14 +283,14 @@ namespace IsoTools {
|
|||||||
Internal.Renderers.Clear();
|
Internal.Renderers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixScreenRect() {
|
void FixScreenBounds() {
|
||||||
var iso_world = isoWorld;
|
var iso_world = isoWorld;
|
||||||
if ( iso_world ) {
|
if ( iso_world ) {
|
||||||
var l = iso_world.IsoToScreen(position + IsoUtils.Vec3FromY(size.y)).x;
|
var l = iso_world.IsoToScreen(position + IsoUtils.Vec3FromY(size.y)).x;
|
||||||
var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x;
|
var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x;
|
||||||
var b = iso_world.IsoToScreen(position).y;
|
var b = iso_world.IsoToScreen(position).y;
|
||||||
var t = iso_world.IsoToScreen(position + size).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() {
|
void OnDrawGizmos() {
|
||||||
if ( isShowBounds && isoWorld ) {
|
if ( isShowIsoBounds && isoWorld ) {
|
||||||
IsoUtils.DrawIsoCube(isoWorld, position + size * 0.5f, size, Color.red);
|
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
|
#endif
|
||||||
|
|||||||
@@ -466,7 +466,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.ScreenBounds.Overlaps(b.Internal.ScreenBounds) &&
|
||||||
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
|
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +511,7 @@ namespace IsoTools {
|
|||||||
_sectorsSize = 0.0f;
|
_sectorsSize = 0.0f;
|
||||||
for ( int i = 0, e = _visibles.Count; i < e; ++i ) {
|
for ( int i = 0, e = _visibles.Count; i < e; ++i ) {
|
||||||
var iso_internal = _visibles[i].Internal;
|
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_xy = IsoToScreen(IsoUtils.vec3OneXY) - IsoToScreen(Vector3.zero);
|
||||||
var min_sector_size = Mathf.Max(min_sector_size_xy.x, min_sector_size_xy.y);
|
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;
|
var iso_internal = _visibles[i].Internal;
|
||||||
|
|
||||||
// high performance tricks
|
// high performance tricks
|
||||||
var min_x = iso_internal.ScreenRect.x.min / _sectorsSize;
|
var min_x = iso_internal.ScreenBounds.x.min / _sectorsSize;
|
||||||
var min_y = iso_internal.ScreenRect.y.min / _sectorsSize;
|
var min_y = iso_internal.ScreenBounds.y.min / _sectorsSize;
|
||||||
var max_x = iso_internal.ScreenRect.x.max / _sectorsSize;
|
var max_x = iso_internal.ScreenBounds.x.max / _sectorsSize;
|
||||||
var max_y = iso_internal.ScreenRect.y.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.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.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);
|
iso_internal.MaxSector.x = (int)(max_x >= 0.0f ? max_x + 1.0f : max_x);
|
||||||
|
|||||||
Reference in New Issue
Block a user