mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-13 15:52:03 +07:00
IsoWorld refactoring wip
This commit is contained in:
@@ -177,7 +177,7 @@ Prefab:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 1
|
||||
value: 1.2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
|
||||
propertyPath: m_LocalRotation.x
|
||||
@@ -592,7 +592,7 @@ Prefab:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 1.2
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
|
||||
propertyPath: m_LocalRotation.x
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
using UnityEngine;
|
||||
using IsoTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
using UnityEngine.Profiling;
|
||||
#endif
|
||||
|
||||
namespace IsoTools {
|
||||
namespace IsoTools.Internal {
|
||||
public class IsoScreenSolver {
|
||||
public Vector2 minXY = Vector2.zero;
|
||||
public IsoAssocList<IsoObject> curVisibles = new IsoAssocList<IsoObject>();
|
||||
public IsoAssocList<IsoObject> oldVisibles = new IsoAssocList<IsoObject>();
|
||||
Vector2 _minIsoXY = Vector2.zero;
|
||||
IsoAssocList<IsoObject> _curVisibles = new IsoAssocList<IsoObject>();
|
||||
IsoAssocList<IsoObject> _oldVisibles = new IsoAssocList<IsoObject>();
|
||||
|
||||
class Sector {
|
||||
public IsoList<IsoObject> objects = new IsoList<IsoObject>();
|
||||
@@ -27,6 +26,24 @@ namespace IsoTools {
|
||||
|
||||
List<Renderer> _tmpRenderers = new List<Renderer>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public Vector2 minIsoXY {
|
||||
get { return _minIsoXY; }
|
||||
}
|
||||
|
||||
public IsoAssocList<IsoObject> curVisibles {
|
||||
get { return _curVisibles; }
|
||||
}
|
||||
|
||||
public IsoAssocList<IsoObject> oldVisibles {
|
||||
get { return _oldVisibles; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Callbacks
|
||||
@@ -37,13 +54,13 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
public void OnRemoveInstance(IsoObject iso_object) {
|
||||
oldVisibles.Remove(iso_object);
|
||||
curVisibles.Remove(iso_object);
|
||||
_oldVisibles.Remove(iso_object);
|
||||
_curVisibles.Remove(iso_object);
|
||||
ClearIsoObjectDepends(iso_object);
|
||||
}
|
||||
|
||||
public bool OnMarkDirtyInstance(IsoObject iso_object) {
|
||||
if ( !iso_object.Internal.Dirty && curVisibles.Contains(iso_object) ) {
|
||||
if ( !iso_object.Internal.Dirty && _curVisibles.Contains(iso_object) ) {
|
||||
iso_object.Internal.Dirty = true;
|
||||
return true;
|
||||
}
|
||||
@@ -57,8 +74,8 @@ namespace IsoTools {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> instances) {
|
||||
Profiler.BeginSample("ResolveNewVisibles");
|
||||
ResolveNewVisibles(instances);
|
||||
Profiler.BeginSample("ResolveVisibles");
|
||||
ResolveVisibles(instances);
|
||||
Profiler.EndSample();
|
||||
Profiler.BeginSample("ResolveSectors");
|
||||
ResolveSectors(iso_world);
|
||||
@@ -70,29 +87,52 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
curVisibles.Clear();
|
||||
oldVisibles.Clear();
|
||||
_curVisibles.Clear();
|
||||
_oldVisibles.Clear();
|
||||
_sectors.Clear();
|
||||
}
|
||||
|
||||
public void SetupIsoObjectDepends(IsoObject obj_a) {
|
||||
ClearIsoObjectDepends(obj_a);
|
||||
var min = obj_a.Internal.MinSector;
|
||||
var max = obj_a.Internal.MaxSector;
|
||||
for ( var y = min.y; y < max.y; ++y ) {
|
||||
for ( var x = min.x; x < max.x; ++x ) {
|
||||
LookUpSectorDepends(x, y, obj_a);
|
||||
LookUpSectorRDepends(x, y, obj_a);
|
||||
}}
|
||||
}
|
||||
|
||||
public void ClearIsoObjectDepends(IsoObject iso_object) {
|
||||
var their_depends = iso_object.Internal.TheirDepends;
|
||||
for ( int i = 0, e = their_depends.Count; i < e; ++i ) {
|
||||
var their_iso_object = their_depends[i];
|
||||
if ( !their_iso_object.Internal.Dirty ) {
|
||||
their_iso_object.Internal.SelfDepends.Remove(iso_object);
|
||||
}
|
||||
}
|
||||
iso_object.Internal.SelfDepends.Clear();
|
||||
iso_object.Internal.TheirDepends.Clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// ResolveVisibles
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void ResolveNewVisibles(IsoAssocList<IsoObject> instances) {
|
||||
oldVisibles.Clear();
|
||||
void ResolveVisibles(IsoAssocList<IsoObject> instances) {
|
||||
_oldVisibles.Clear();
|
||||
if ( instances.Count > 0 ) {
|
||||
minXY.Set(float.MaxValue, float.MaxValue);
|
||||
_minIsoXY.Set(float.MaxValue, float.MaxValue);
|
||||
for ( int i = 0, e = instances.Count; i < e; ++i ) {
|
||||
var iso_object = instances[i];
|
||||
var object_pos = iso_object.position;
|
||||
if ( minXY.x > object_pos.x ) {
|
||||
minXY.x = object_pos.x;
|
||||
if ( _minIsoXY.x > object_pos.x ) {
|
||||
_minIsoXY.x = object_pos.x;
|
||||
}
|
||||
if ( minXY.y > object_pos.y ) {
|
||||
minXY.y = object_pos.y;
|
||||
if ( _minIsoXY.y > object_pos.y ) {
|
||||
_minIsoXY.y = object_pos.y;
|
||||
}
|
||||
if ( !IsoUtils.Vec2Approximately(
|
||||
iso_object.Internal.LastTrans,
|
||||
@@ -102,21 +142,34 @@ namespace IsoTools {
|
||||
}
|
||||
if ( IsIsoObjectVisible(iso_object) ) {
|
||||
iso_object.Internal.Placed = false;
|
||||
oldVisibles.Add(iso_object);
|
||||
_oldVisibles.Add(iso_object);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
minXY.Set(0.0f, 0.0f);
|
||||
_minIsoXY.Set(0.0f, 0.0f);
|
||||
}
|
||||
var temp_visibles = curVisibles;
|
||||
curVisibles = oldVisibles;
|
||||
oldVisibles = temp_visibles;
|
||||
var temp_visibles = _curVisibles;
|
||||
_curVisibles = _oldVisibles;
|
||||
_oldVisibles = temp_visibles;
|
||||
}
|
||||
|
||||
void ResolveSectors(IsoWorld iso_world) {
|
||||
SetupSectorSize(iso_world);
|
||||
SetupObjectsSectors();
|
||||
SetupSectors();
|
||||
bool IsIsoObjectVisible(IsoObject iso_object) {
|
||||
var renderers = GetIsoObjectRenderers(iso_object);
|
||||
for ( int i = 0, e = renderers.Count; i < e; ++i ) {
|
||||
if ( renderers[i].isVisible ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
|
||||
if ( iso_object.cacheRenderers ) {
|
||||
return iso_object.Internal.Renderers;
|
||||
} else {
|
||||
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
|
||||
return _tmpRenderers;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -125,27 +178,34 @@ namespace IsoTools {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void ResolveSectors(IsoWorld iso_world) {
|
||||
SetupSectorSize(iso_world);
|
||||
SetupObjectSectors();
|
||||
SetupSectors();
|
||||
}
|
||||
|
||||
void SetupSectorSize(IsoWorld iso_world) {
|
||||
_sectorsSize = 0.0f;
|
||||
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) {
|
||||
var iso_internal = curVisibles[i].Internal;
|
||||
_sectorsSize += IsoUtils.Vec2MaxF(iso_internal.ScreenBounds.size);
|
||||
for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
|
||||
var iso_internal = _curVisibles[i].Internal;
|
||||
var size_x = iso_internal.ScreenBounds.x.max - iso_internal.ScreenBounds.x.min;
|
||||
var size_y = iso_internal.ScreenBounds.y.max - iso_internal.ScreenBounds.y.min;
|
||||
_sectorsSize += size_x > size_y ? size_x : size_y;
|
||||
}
|
||||
var min_sector_size_xy = iso_world.IsoToScreen(IsoUtils.vec3OneXY) - iso_world.IsoToScreen(Vector3.zero);
|
||||
var min_sector_size = Mathf.Max(min_sector_size_xy.x, min_sector_size_xy.y);
|
||||
_sectorsSize = curVisibles.Count > 0
|
||||
? Mathf.Round(Mathf.Max(min_sector_size, _sectorsSize / curVisibles.Count))
|
||||
var min_sector_size = IsoUtils.Vec2MaxF(
|
||||
iso_world.IsoToScreen(IsoUtils.vec3OneXY) -
|
||||
iso_world.IsoToScreen(Vector3.zero));
|
||||
_sectorsSize = _curVisibles.Count > 0
|
||||
? Mathf.Round(Mathf.Max(min_sector_size, _sectorsSize / _curVisibles.Count))
|
||||
: min_sector_size;
|
||||
}
|
||||
|
||||
void SetupObjectsSectors() {
|
||||
if ( curVisibles.Count > 0 ) {
|
||||
void SetupObjectSectors() {
|
||||
if ( _curVisibles.Count > 0 ) {
|
||||
_sectorsMinNumPos.Set(float.MaxValue, float.MaxValue);
|
||||
_sectorsMaxNumPos.Set(float.MinValue, float.MinValue);
|
||||
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) {
|
||||
var iso_internal = curVisibles[i].Internal;
|
||||
|
||||
// high performance tricks
|
||||
for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
|
||||
var iso_internal = _curVisibles[i].Internal;
|
||||
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;
|
||||
@@ -174,12 +234,17 @@ namespace IsoTools {
|
||||
_sectorsNumPosCount = _sectorsMaxNumPos - _sectorsMinNumPos;
|
||||
}
|
||||
|
||||
void SetupSectors() {
|
||||
ResizeSectors((int)(_sectorsNumPosCount.x * _sectorsNumPosCount.y));
|
||||
FillSectors();
|
||||
}
|
||||
|
||||
void ResizeSectors(int count) {
|
||||
if ( _sectors.Count < count ) {
|
||||
if ( _sectors.Capacity < count ) {
|
||||
_sectors.Capacity = count;
|
||||
_sectors.Capacity = count * 2;
|
||||
}
|
||||
while ( _sectors.Count < _sectors.Capacity ) {
|
||||
while ( _sectors.Count < count ) {
|
||||
_sectors.Add(new Sector());
|
||||
}
|
||||
}
|
||||
@@ -188,30 +253,25 @@ namespace IsoTools {
|
||||
}
|
||||
}
|
||||
|
||||
void TuneSectors() {
|
||||
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) {
|
||||
var iso_object = curVisibles[i];
|
||||
void FillSectors() {
|
||||
for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
|
||||
var iso_object = _curVisibles[i];
|
||||
iso_object.Internal.MinSector -= _sectorsMinNumPos;
|
||||
iso_object.Internal.MaxSector -= _sectorsMinNumPos;
|
||||
var min = iso_object.Internal.MinSector;
|
||||
var max = iso_object.Internal.MaxSector;
|
||||
for ( var y = min.y; y < max.y; ++y ) {
|
||||
for ( var x = min.x; x < max.x; ++x ) {
|
||||
var sector = FindSector(x, y);
|
||||
if ( sector != null ) {
|
||||
sector.objects.Add(iso_object);
|
||||
}
|
||||
}}
|
||||
for ( var x = min.x; x < max.x; ++x ) {
|
||||
var sector = FindSector(x, y);
|
||||
if ( sector != null ) {
|
||||
sector.objects.Add(iso_object);
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
void SetupSectors() {
|
||||
ResizeSectors((int)(_sectorsNumPosCount.x * _sectorsNumPosCount.y));
|
||||
TuneSectors();
|
||||
}
|
||||
|
||||
Sector FindSector(float num_pos_x, float num_pos_y) {
|
||||
if ( num_pos_x < 0 || num_pos_y < 0 ) {
|
||||
if ( num_pos_x < 0.0f || num_pos_y < 0.0f ) {
|
||||
return null;
|
||||
}
|
||||
if ( num_pos_x >= _sectorsNumPosCount.x || num_pos_y >= _sectorsNumPosCount.y ) {
|
||||
@@ -221,6 +281,44 @@ namespace IsoTools {
|
||||
return _sectors[sector_index];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// LookUpSectorDepends
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void LookUpSectorDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
|
||||
var sec = FindSector(num_pos_x, num_pos_y);
|
||||
if ( sec != null ) {
|
||||
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
|
||||
var obj_b = sec.objects[i];
|
||||
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_a, obj_b) ) {
|
||||
obj_a.Internal.SelfDepends.Add(obj_b);
|
||||
obj_b.Internal.TheirDepends.Add(obj_a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LookUpSectorRDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
|
||||
var sec = FindSector(num_pos_x, num_pos_y);
|
||||
if ( sec != null ) {
|
||||
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
|
||||
var obj_b = sec.objects[i];
|
||||
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_b, obj_a) ) {
|
||||
obj_b.Internal.SelfDepends.Add(obj_a);
|
||||
obj_a.Internal.TheirDepends.Add(obj_b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsIsoObjectDepends(IsoObject a, IsoObject b) {
|
||||
return
|
||||
a.Internal.ScreenBounds.Overlaps(b.Internal.ScreenBounds) &&
|
||||
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
|
||||
}
|
||||
|
||||
bool IsIsoObjectDepends(Vector3 a_min, Vector3 a_size, Vector3 b_min, Vector3 b_size) {
|
||||
var a_max = a_min + a_size;
|
||||
var b_max = b_min + b_size;
|
||||
@@ -256,85 +354,5 @@ namespace IsoTools {
|
||||
}
|
||||
return a_yesno;
|
||||
}
|
||||
|
||||
bool IsIsoObjectDepends(IsoObject a, IsoObject b) {
|
||||
return
|
||||
a.Internal.ScreenBounds.Overlaps(b.Internal.ScreenBounds) &&
|
||||
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
|
||||
}
|
||||
|
||||
void LookUpSectorDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
|
||||
var sec = FindSector(num_pos_x, num_pos_y);
|
||||
if ( sec != null ) {
|
||||
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
|
||||
var obj_b = sec.objects[i];
|
||||
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_a, obj_b) ) {
|
||||
obj_a.Internal.SelfDepends.Add(obj_b);
|
||||
obj_b.Internal.TheirDepends.Add(obj_a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LookUpSectorRDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
|
||||
var sec = FindSector(num_pos_x, num_pos_y);
|
||||
if ( sec != null ) {
|
||||
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
|
||||
var obj_b = sec.objects[i];
|
||||
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_b, obj_a) ) {
|
||||
obj_b.Internal.SelfDepends.Add(obj_a);
|
||||
obj_a.Internal.TheirDepends.Add(obj_b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupIsoObjectDepends(IsoObject obj_a) {
|
||||
ClearIsoObjectDepends(obj_a);
|
||||
var min = obj_a.Internal.MinSector;
|
||||
var max = obj_a.Internal.MaxSector;
|
||||
for ( var y = min.y; y < max.y; ++y ) {
|
||||
for ( var x = min.x; x < max.x; ++x ) {
|
||||
LookUpSectorDepends(x, y, obj_a);
|
||||
LookUpSectorRDepends(x, y, obj_a);
|
||||
}}
|
||||
}
|
||||
|
||||
public void ClearIsoObjectDepends(IsoObject iso_object) {
|
||||
var their_depends = iso_object.Internal.TheirDepends;
|
||||
for ( int i = 0, e = their_depends.Count; i < e; ++i ) {
|
||||
var their_iso_object = their_depends[i];
|
||||
if ( !their_iso_object.Internal.Dirty ) {
|
||||
their_iso_object.Internal.SelfDepends.Remove(iso_object);
|
||||
}
|
||||
}
|
||||
iso_object.Internal.SelfDepends.Clear();
|
||||
iso_object.Internal.TheirDepends.Clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Private
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public bool IsIsoObjectVisible(IsoObject iso_object) {
|
||||
var renderers = GetIsoObjectRenderers(iso_object);
|
||||
for ( int i = 0, e = renderers.Count; i < e; ++i ) {
|
||||
if ( renderers[i].isVisible ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
|
||||
if ( iso_object.cacheRenderers ) {
|
||||
return iso_object.Internal.Renderers;
|
||||
} else {
|
||||
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
|
||||
return _tmpRenderers;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
using UnityEngine;
|
||||
using IsoTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
using UnityEngine.Profiling;
|
||||
#endif
|
||||
|
||||
namespace IsoTools {
|
||||
namespace IsoTools.Internal {
|
||||
public class IsoSortingSolver {
|
||||
public float stepDepth = IsoWorld.DefStepDepth;
|
||||
public float startDepth = IsoWorld.DefStartDepth;
|
||||
|
||||
List<Renderer> _tmpRenderers = new List<Renderer>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -41,13 +37,13 @@ namespace IsoTools {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public bool StepSortingAction(IsoScreenSolver screen_solver){
|
||||
Profiler.BeginSample("CalculateSectors");
|
||||
public bool StepSortingAction(IsoWorld iso_world, IsoScreenSolver screen_solver) {
|
||||
Profiler.BeginSample("ResolveVisibles");
|
||||
var dirty = ResolveVisibles(screen_solver);
|
||||
Profiler.EndSample();
|
||||
if ( dirty ) {
|
||||
Profiler.BeginSample("PlaceAllVisibles");
|
||||
PlaceAllVisibles(screen_solver.curVisibles);
|
||||
PlaceAllVisibles(iso_world, screen_solver);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
return dirty;
|
||||
@@ -57,17 +53,20 @@ namespace IsoTools {
|
||||
_tmpRenderers.Clear();
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// ResolveVisibles
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
bool ResolveVisibles(IsoScreenSolver screen_solver){
|
||||
bool ResolveVisibles(IsoScreenSolver screen_solver) {
|
||||
var mark_dirty = false;
|
||||
var old_visibles = screen_solver.oldVisibles;
|
||||
var cur_visibles = screen_solver.curVisibles;
|
||||
|
||||
var mark_dirty = false;
|
||||
for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) {
|
||||
var iso_object = cur_visibles[i];
|
||||
if ( iso_object.Internal.Dirty || !old_visibles.Contains(iso_object) ) {
|
||||
@@ -79,6 +78,7 @@ namespace IsoTools {
|
||||
mark_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0, e = old_visibles.Count; i < e; ++i ) {
|
||||
var iso_object = old_visibles[i];
|
||||
if ( !cur_visibles.Contains(iso_object) ) {
|
||||
@@ -86,12 +86,13 @@ namespace IsoTools {
|
||||
screen_solver.ClearIsoObjectDepends(iso_object);
|
||||
}
|
||||
}
|
||||
|
||||
_tmpRenderers.Clear();
|
||||
return mark_dirty;
|
||||
}
|
||||
|
||||
bool UpdateIsoObjectBounds3d(IsoObject iso_object) {
|
||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
||||
if ( iso_object.mode != IsoObject.Mode.Mode3d ) {
|
||||
var minmax3d = IsoObjectMinMax3D(iso_object);
|
||||
var offset3d = iso_object.Internal.Transform.position.z - minmax3d.center;
|
||||
if ( iso_object.Internal.MinMax3d.Approximately(minmax3d) ||
|
||||
@@ -110,22 +111,22 @@ namespace IsoTools {
|
||||
var result = IsoMinMax.zero;
|
||||
var renderers = GetIsoObjectRenderers(iso_object);
|
||||
for ( int i = 0, e = renderers.Count; i < e; ++i ) {
|
||||
var bounds = renderers[i].bounds;
|
||||
var bounds = renderers[i].bounds;
|
||||
var extents = bounds.extents;
|
||||
if ( extents.x > 0.0f || extents.y > 0.0f || extents.z > 0.0f ) {
|
||||
var center = bounds.center.z;
|
||||
var minbounds = center - extents.z;
|
||||
var maxbounds = center + extents.z;
|
||||
if ( inited ) {
|
||||
if ( minbounds < result.min ) {
|
||||
if ( result.min > minbounds ) {
|
||||
result.min = minbounds;
|
||||
}
|
||||
if ( maxbounds > result.max ) {
|
||||
if ( result.max < maxbounds ) {
|
||||
result.max = maxbounds;
|
||||
}
|
||||
} else {
|
||||
inited = true;
|
||||
result = new IsoMinMax(minbounds, maxbounds);
|
||||
result.Set(minbounds, maxbounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,30 +148,32 @@ namespace IsoTools {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void PlaceAllVisibles(IsoAssocList<IsoObject> cur_visibles) {
|
||||
var depth = startDepth;
|
||||
void PlaceAllVisibles(IsoWorld iso_world, IsoScreenSolver screen_solver) {
|
||||
var start_depth = iso_world.startDepth;
|
||||
var cur_visibles = screen_solver.curVisibles;
|
||||
for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) {
|
||||
depth = RecursivePlaceIsoObject(cur_visibles[i], depth);
|
||||
start_depth = RecursivePlaceIsoObject(
|
||||
cur_visibles[i], start_depth, iso_world.stepDepth);
|
||||
}
|
||||
}
|
||||
|
||||
float RecursivePlaceIsoObject(IsoObject iso_object, float depth) {
|
||||
float RecursivePlaceIsoObject(IsoObject iso_object, float depth, float step_depth) {
|
||||
if ( iso_object.Internal.Placed ) {
|
||||
return depth;
|
||||
}
|
||||
iso_object.Internal.Placed = true;
|
||||
var self_depends = iso_object.Internal.SelfDepends;
|
||||
for ( int i = 0, e = self_depends.Count; i < e; ++i ) {
|
||||
depth = RecursivePlaceIsoObject(self_depends[i], depth);
|
||||
depth = RecursivePlaceIsoObject(self_depends[i], depth, step_depth);
|
||||
}
|
||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
||||
var zoffset = iso_object.Internal.Offset3d;
|
||||
var extents = iso_object.Internal.MinMax3d.size;
|
||||
PlaceIsoObject(iso_object, depth + extents * 0.5f + zoffset);
|
||||
return depth + extents + stepDepth;
|
||||
return depth + extents + step_depth;
|
||||
} else {
|
||||
PlaceIsoObject(iso_object, depth);
|
||||
return depth + stepDepth;
|
||||
return depth + step_depth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,8 +159,8 @@ namespace IsoTools {
|
||||
public Ray RayFromIsoCameraToIsoPoint(Vector3 iso_pnt) {
|
||||
var screen_pnt = IsoToScreen(iso_pnt);
|
||||
|
||||
var min_xy = _screenSolver.minXY;
|
||||
var min_screen_pnt = IsoToScreen(min_xy - Vector2.one);
|
||||
var min_iso_xy = _screenSolver.minIsoXY;
|
||||
var min_screen_pnt = IsoToScreen(min_iso_xy - Vector2.one);
|
||||
var max_screen_dist = screen_pnt.y - min_screen_pnt.y;
|
||||
|
||||
var screen_down_pnt = new Vector2(screen_pnt.x, screen_pnt.y - max_screen_dist);
|
||||
@@ -358,21 +358,15 @@ namespace IsoTools {
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSolverProperties() {
|
||||
_sortingSolver.stepDepth = stepDepth;
|
||||
_sortingSolver.startDepth = startDepth;
|
||||
}
|
||||
|
||||
void ChangeSortingProperty() {
|
||||
MarkDirty();
|
||||
UpdateIsoMatrix();
|
||||
FixInstanceTransforms();
|
||||
UpdateSolverProperties();
|
||||
}
|
||||
|
||||
void StepSortingProcess() {
|
||||
_screenSolver.StepSortingAction(this, GetInstances());
|
||||
if ( _sortingSolver.StepSortingAction(_screenSolver) ) {
|
||||
if ( _sortingSolver.StepSortingAction(this, _screenSolver) ) {
|
||||
MarkDirty();
|
||||
}
|
||||
_screenSolver.PostStepSortingAction();
|
||||
@@ -397,11 +391,13 @@ namespace IsoTools {
|
||||
protected override void OnEnable() {
|
||||
base.OnEnable();
|
||||
_screenSolver.Clear();
|
||||
_sortingSolver.Clear();
|
||||
}
|
||||
|
||||
protected override void OnDisable() {
|
||||
base.OnDisable();
|
||||
_screenSolver.Clear();
|
||||
_sortingSolver.Clear();
|
||||
}
|
||||
|
||||
protected override void OnAddInstanceToHolder(IsoObject instance) {
|
||||
|
||||
Reference in New Issue
Block a user