mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
begin search for one object sorting
This commit is contained in:
@@ -9,7 +9,7 @@ namespace IsoTools {
|
|||||||
public class IsoObject : MonoBehaviour {
|
public class IsoObject : MonoBehaviour {
|
||||||
|
|
||||||
Transform _transform = null;
|
Transform _transform = null;
|
||||||
Vector3 _lastTransform = Vector3.zero;
|
Vector2 _lastTransform = Vector2.zero;
|
||||||
Vector3 _lastPosition = Vector3.zero;
|
Vector3 _lastPosition = Vector3.zero;
|
||||||
Vector3 _lastSize = Vector3.zero;
|
Vector3 _lastSize = Vector3.zero;
|
||||||
bool _lastSorting = false;
|
bool _lastSorting = false;
|
||||||
@@ -122,7 +122,7 @@ namespace IsoTools {
|
|||||||
void MartDirtyIsoWorld() {
|
void MartDirtyIsoWorld() {
|
||||||
var iso_world = GetIsoWorld();
|
var iso_world = GetIsoWorld();
|
||||||
if ( iso_world && Sorting ) {
|
if ( iso_world && Sorting ) {
|
||||||
iso_world.MarkDirty();
|
iso_world.MarkDirty(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if ( _lastTransform != _transform.position ) {
|
if ( _lastTransform.x != _transform.position.x || _lastTransform.y != _transform.position.y ) {
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
}
|
}
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>World tile type.</summary>
|
/// <summary>World tile type.</summary>
|
||||||
public TileTypes TileType = TileTypes.Isometric;
|
public TileTypes TileType = TileTypes.Isometric;
|
||||||
/// <summary>Isometric tile size.</summary>
|
/// <summary>Isometric tile size.</summary>
|
||||||
public float TileSize = 32.0f;
|
public float TileSize = 32.0f;
|
||||||
/// <summary>Start sorting depth value.</summary>
|
/// <summary>Start sorting depth value.</summary>
|
||||||
public float StartDepth = 0.0f;
|
public float MinDepth = 0.0f;
|
||||||
/// <summary>Step sorting depth value.</summary>
|
/// <summary>Step sorting depth value.</summary>
|
||||||
public float StepDepth = 0.1f;
|
public float MaxDepth = 100.0f;
|
||||||
|
|
||||||
class ObjectInfo {
|
class ObjectInfo {
|
||||||
public IsoObject IsoObject;
|
public IsoObject IsoObject;
|
||||||
@@ -48,6 +48,16 @@ namespace IsoTools {
|
|||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks world for resorting one object only
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Isometric object for resorting.</param>
|
||||||
|
public void MarkDirty(IsoObject obj) {
|
||||||
|
if ( !_dirty ) {
|
||||||
|
_manualSort(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert isometric coordinates to screen coordinates
|
/// Convert isometric coordinates to screen coordinates
|
||||||
@@ -127,17 +137,20 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _fixTileSize() {
|
void _fixTileSize() {
|
||||||
|
MarkDirty();
|
||||||
_fixAllTransforms();
|
_fixAllTransforms();
|
||||||
_lastTileSize = TileSize;
|
_lastTileSize = TileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fixTileType() {
|
void _fixTileType() {
|
||||||
|
MarkDirty();
|
||||||
_fixAllTransforms();
|
_fixAllTransforms();
|
||||||
_lastTileType = TileType;
|
_lastTileType = TileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fixDirty() {
|
void _fixDirty() {
|
||||||
_manualSort();
|
_manualSort();
|
||||||
|
Debug.Log("Resort!");
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +199,54 @@ namespace IsoTools {
|
|||||||
void _manualSort() {
|
void _manualSort() {
|
||||||
var objects = _scanObjects(true);
|
var objects = _scanObjects(true);
|
||||||
var depends = _scanDepends(objects);
|
var depends = _scanDepends(objects);
|
||||||
var depth = StartDepth;
|
var depth = MinDepth;
|
||||||
foreach ( var info in objects ) {
|
foreach ( var info in objects ) {
|
||||||
_placeObject(info, objects, depends, ref depth);
|
_placeObject(info, objects, depends, ref depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isDepends(IsoObject obj_ao, IsoObject obj_bo) {
|
||||||
|
if ( obj_ao != obj_bo ) {
|
||||||
|
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
||||||
|
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
||||||
|
if ( obj_bo.Position.x < max_ax && obj_bo.Position.y < max_ay ) {
|
||||||
|
var max_bz = obj_bo.Position.z + obj_bo.Size.z;
|
||||||
|
if ( obj_ao.Position.z < max_bz ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _manualSort(IsoObject obj) {
|
||||||
|
var objects = _scanObjects(true);
|
||||||
|
var min_depth = float.MinValue;
|
||||||
|
foreach ( var obj_b in objects ) {
|
||||||
|
if ( _isDepends(obj, obj_b.IsoObject) ) {
|
||||||
|
min_depth = Mathf.Max(min_depth, obj_b.IsoObject.transform.position.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var max_depth = float.MaxValue;
|
||||||
|
foreach ( var obj_a in objects ) {
|
||||||
|
if ( _isDepends(obj_a.IsoObject, obj) ) {
|
||||||
|
max_depth = Mathf.Min(max_depth, obj_a.IsoObject.transform.position.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( max_depth == float.MaxValue ) {
|
||||||
|
max_depth = MaxDepth;
|
||||||
|
}
|
||||||
|
if ( min_depth == float.MinValue ) {
|
||||||
|
min_depth = MinDepth;
|
||||||
|
}
|
||||||
|
//TODO: Epsilon!!!!!
|
||||||
|
if ( Mathf.Abs(max_depth - min_depth) <= Mathf.Epsilon ) {
|
||||||
|
MarkDirty();
|
||||||
|
} else {
|
||||||
|
_placeObject(obj, (min_depth + max_depth) / 2.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _placeObject(IsoObject obj, float depth) {
|
void _placeObject(IsoObject obj, float depth) {
|
||||||
var pos = obj.gameObject.transform.position;
|
var pos = obj.gameObject.transform.position;
|
||||||
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
||||||
@@ -206,7 +261,7 @@ namespace IsoTools {
|
|||||||
_placeObject(obj, objects, depends, ref depth);
|
_placeObject(obj, objects, depends, ref depth);
|
||||||
}
|
}
|
||||||
_placeObject(info.IsoObject, depth);
|
_placeObject(info.IsoObject, depth);
|
||||||
depth += StepDepth;
|
depth += (MaxDepth - MinDepth) / objects.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="27" Column="4" />
|
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="127" Column="1" />
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="186" Column="23" />
|
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="271" Column="16" />
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user