physics wip

This commit is contained in:
2015-05-26 11:08:33 +06:00
parent 5fd2f46ab8
commit b638117c89
23 changed files with 802 additions and 521 deletions

View File

@@ -6,6 +6,7 @@ using UnityEditor;
namespace IsoTools {
[ExecuteInEditMode]
[RequireComponent(typeof(SpriteRenderer))]
public class IsoObject : MonoBehaviour {
#if UNITY_EDITOR
@@ -17,24 +18,6 @@ namespace IsoTools {
[SerializeField]
Vector3 _position = Vector3.zero;
/// <summary>Isometric object position X.</summary>
public float PositionX {
get { return Position.x; }
set { Position = IsoUtils.Vec3ChangeX(Position, value); }
}
/// <summary>Isometric object position Y.</summary>
public float PositionY {
get { return Position.y; }
set { Position = IsoUtils.Vec3ChangeY(Position, value); }
}
/// <summary>Isometric object position Z.</summary>
public float PositionZ {
get { return Position.z; }
set { Position = IsoUtils.Vec3ChangeZ(Position, value); }
}
/// <summary>Isometric object position.</summary>
public Vector3 Position {
get { return _position; }
@@ -44,9 +27,51 @@ namespace IsoTools {
}
}
/// <summary>Isometric object position X.</summary>
public float PositionX {
get { return Position.x; }
set { Position = IsoUtils.Vec3ChangeX(Position, value); }
}
/// <summary>Isometric object position Y.</summary>
public float PositionY {
get { return Position.y; }
set { Position = IsoUtils.Vec3ChangeY(Position, value); }
}
/// <summary>Isometric object position Z.</summary>
public float PositionZ {
get { return Position.z; }
set { Position = IsoUtils.Vec3ChangeZ(Position, value); }
}
/// <summary>Isometric object position XY.</summary>
public Vector2 PositionXY {
get { return new Vector2(PositionX, PositionY); }
}
/// <summary>Isometric object position YZ.</summary>
public Vector2 PositionYZ {
get { return new Vector2(PositionY, PositionZ); }
}
/// <summary>Isometric object position XZ.</summary>
public Vector2 PositionXZ {
get { return new Vector2(PositionX, PositionZ); }
}
[SerializeField]
Vector3 _size = Vector3.one;
/// <summary>Isometric object size.</summary>
public Vector3 Size {
get { return _size; }
set {
_size = IsoUtils.Vec3Max(value, Vector3.zero);
FixTransform();
}
}
/// <summary>Isometric object size X.</summary>
public float SizeX {
get { return Size.x; }
@@ -65,27 +90,60 @@ namespace IsoTools {
set { Size = IsoUtils.Vec3ChangeZ(Size, value); }
}
/// <summary>Isometric object size.</summary>
public Vector3 Size {
get { return _size; }
set {
_size = IsoUtils.Vec3Max(value, Vector3.zero);
FixTransform();
}
/// <summary>Isometric object size XY.</summary>
public Vector2 SizeXY {
get { return new Vector2(SizeX, SizeY); }
}
/// <summary>Isometric object size YZ.</summary>
public Vector2 SizeYZ {
get { return new Vector2(SizeY, SizeZ); }
}
/// <summary>Isometric object size XZ.</summary>
public Vector2 SizeXZ {
get { return new Vector2(SizeX, SizeZ); }
}
[SerializeField]
/// <summary>Isometric object tile position.</summary>
public Vector3 TilePosition {
get {
return new Vector3(
Mathf.Round(Position.x),
Mathf.Round(Position.y),
Mathf.Round(Position.z));
}
get { return IsoUtils.Vec3Round(Position); }
set { Position = value; }
}
/// <summary>Isometric object tile position X.</summary>
public float TilePositionX {
get { return TilePosition.x; }
set { TilePosition = IsoUtils.Vec3ChangeX(TilePosition, value); }
}
/// <summary>Isometric object tile position Y.</summary>
public float TilePositionY {
get { return TilePosition.y; }
set { TilePosition = IsoUtils.Vec3ChangeY(TilePosition, value); }
}
/// <summary>Isometric object tile position Z.</summary>
public float TilePositionZ {
get { return TilePosition.z; }
set { TilePosition = IsoUtils.Vec3ChangeZ(TilePosition, value); }
}
/// <summary>Isometric object tile position XY.</summary>
public Vector2 TilePositionXY {
get { return new Vector2(TilePositionX, TilePositionY); }
}
/// <summary>Isometric object tile position YZ.</summary>
public Vector2 TilePositionYZ {
get { return new Vector2(TilePositionY, TilePositionZ); }
}
/// <summary>Isometric object tile position XZ.</summary>
public Vector2 TilePositionXZ {
get { return new Vector2(TilePositionX, TilePositionZ); }
}
IsoWorld _iso_world = null;
public IsoWorld IsoWorld {
get {
@@ -104,24 +162,25 @@ namespace IsoTools {
}
public void FixTransform() {
Vector3 trans = IsoWorld.IsoToScreen(Position);
trans.z = transform.position.z;
transform.position = trans;
transform.position = IsoUtils.Vec3ChangeZ(
IsoWorld.IsoToScreen(Position),
transform.position.z);
FixLastProperties();
MartDirtyIsoWorld();
MarkEditorObjectDirty();
}
public void FixIsoPosition() {
Vector2 trans = transform.position;
Position = IsoWorld.ScreenToIso(trans, Position.z);
Position = IsoWorld.ScreenToIso(
transform.position,
PositionZ);
}
void FixLastProperties() {
#if UNITY_EDITOR
_lastTransform = transform.position;
_lastPosition = Position;
_lastSize = Size;
_lastPosition = Position;
_lastSize = Size;
#endif
}
@@ -153,9 +212,7 @@ namespace IsoTools {
#if UNITY_EDITOR
void Update() {
if ( Application.isEditor ) {
if ( !Mathf.Approximately(_lastTransform.x, transform.position.x) ||
!Mathf.Approximately(_lastTransform.y, transform.position.y))
{
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
FixIsoPosition();
}
if ( _lastPosition != _position ) Position = _position;

View File

@@ -0,0 +1,55 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace IsoTools {
[RequireComponent(typeof(IsoObject))]
public class IsoRigidbody : MonoBehaviour {
public bool IsTrigger = false;
public bool IsKinematic = false;
public RigidbodyInterpolation Interpolation = RigidbodyInterpolation.None;
public CollisionDetectionMode CollisionMode = CollisionDetectionMode.Discrete;
public PhysicMaterial PhysicMaterial = null;
IsoObject _iso_object = null;
GameObject _fake_object = null;
Rigidbody _rigid_body = null;
BoxCollider _box_collider = null;
public Rigidbody Rigidbody {
get { return _rigid_body; }
}
void Awake() {
_iso_object = GetComponent<IsoObject>();
if ( !_iso_object ) {
throw new UnityException("IsoRigidbody. IsoObject not found!");
}
_fake_object = new GameObject();
_fake_object.name = "_Fake" + gameObject.name;
_rigid_body = _fake_object.AddComponent<Rigidbody>();
_rigid_body.freezeRotation = true;
_rigid_body.isKinematic = IsKinematic;
_rigid_body.interpolation = Interpolation;
_rigid_body.collisionDetectionMode = CollisionMode;
_box_collider = _fake_object.AddComponent<BoxCollider>();
_box_collider.center = IsoUtils.Vec3SwapYZ(_iso_object.Size / 2.0f);
_box_collider.size = IsoUtils.Vec3SwapYZ(_iso_object.Size);
_box_collider.isTrigger = IsTrigger;
_box_collider.material = PhysicMaterial;
_fake_object.transform.position = IsoUtils.Vec3SwapYZ(_iso_object.Position);
}
void FixedUpdate() {
if ( _iso_object ) {
_iso_object.Position = IsoUtils.Vec3SwapYZ(_fake_object.transform.position);
}
}
}
} // namespace IsoTools

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b6f23cf97dc1d49d89a2556193c4f2e2
timeCreated: 1431879880
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,66 +2,63 @@
using System;
namespace IsoTools {
public class IsoUtils {
public static Vector3 Vec2OneX {
get { return new Vector2(1.0f, 0.0f); }
}
public static class IsoUtils {
public static Vector3 Vec2OneY {
get { return new Vector2(0.0f, 1.0f); }
}
// ------------------------------------------------------------------------
//
// Consts
//
// ------------------------------------------------------------------------
public static Vector3 Vec3OneX {
get { return new Vector3(1.0f, 0.0f, 0.0f); }
}
public static Vector3 Vec2OneX { get { return new Vector2(1.0f, 0.0f); } }
public static Vector3 Vec2OneY { get { return new Vector2(0.0f, 1.0f); } }
public static Vector3 Vec2OneXY { get { return new Vector2(1.0f, 1.0f); } }
public static Vector3 Vec3OneY {
get { return new Vector3(0.0f, 1.0f, 0.0f); }
}
public static Vector3 Vec3OneX { get { return new Vector3(1.0f, 0.0f, 0.0f); } }
public static Vector3 Vec3OneY { get { return new Vector3(0.0f, 1.0f, 0.0f); } }
public static Vector3 Vec3OneZ { get { return new Vector3(0.0f, 0.0f, 1.0f); } }
public static Vector3 Vec3OneXY { get { return new Vector3(1.0f, 1.0f, 0.0f); } }
public static Vector3 Vec3OneYZ { get { return new Vector3(0.0f, 1.0f, 1.0f); } }
public static Vector3 Vec3OneXZ { get { return new Vector3(1.0f, 0.0f, 1.0f); } }
public static Vector3 Vec3OneZ {
get { return new Vector3(0.0f, 0.0f, 1.0f); }
}
// ------------------------------------------------------------------------
//
// Swap
//
// ------------------------------------------------------------------------
public static Vector2 Vec2FromX(float x) {
return new Vector2(x, 0.0f);
public static Vector2 Vec2SwapXY(Vector2 v) {
return new Vector2(v.y, v.x);
}
public static Vector2 Vec2FromY(float y) {
return new Vector2(0.0f, y);
public static Vector3 Vec3SwapXY(Vector3 v) {
return new Vector3(v.y, v.x, v.z);
}
public static Vector3 Vec3SwapYZ(Vector3 v) {
return new Vector3(v.x, v.z, v.y);
}
public static Vector3 Vec3SwapXZ(Vector3 v) {
return new Vector3(v.z, v.y, v.x);
}
public static Vector3 Vec3FromX(float x) {
return new Vector3(x, 0.0f, 0.0f);
// ------------------------------------------------------------------------
//
// Abs/Min/Max
//
// ------------------------------------------------------------------------
public static Vector2 Vec2Abs(Vector2 v) {
return new Vector2(
Mathf.Abs(v.x),
Mathf.Abs(v.y));
}
public static Vector3 Vec3FromY(float y) {
return new Vector3(0.0f, y, 0.0f);
}
public static Vector3 Vec3FromZ(float z) {
return new Vector3(0.0f, 0.0f, z);
}
public static int Sign<T>(float v) {
return v > 0.0f ? 1 : (v == 0.0f ? 0 : -1);
}
public static void LookUpCube(Vector3 min, Vector3 max, Action<Vector3> act) {
for ( var z = min.z; z < max.z; ++z ) {
for ( var y = min.y; y < max.y; ++y ) {
for ( var x = min.x; x < max.x; ++x ) {
act(new Vector3(x, y, z));
}
}
}
}
public static bool Vec3Approximately(Vector3 a, Vector3 b) {
return
Mathf.Approximately(a.x, b.x) &&
Mathf.Approximately(a.y, b.y) &&
Mathf.Approximately(a.z, b.z);
public static Vector2 Vec2Min(Vector2 a, Vector2 b) {
return new Vector2(
Mathf.Min(a.x, b.x),
Mathf.Min(a.y, b.y));
}
public static Vector3 Vec3Abs(Vector3 v) {
@@ -71,20 +68,46 @@ namespace IsoTools {
Mathf.Abs(v.z));
}
public static Vector3 Vec3Min(Vector3 a, Vector3 b) {
return new Vector3(
Mathf.Min(a.x, b.x),
Mathf.Min(a.y, b.y),
Mathf.Min(a.z, b.z));
}
public static Vector2 Vec2Max(Vector2 a, Vector2 b) {
return new Vector2(
Mathf.Max(a.x, b.x),
Mathf.Max(a.y, b.y));
}
public static Vector3 Vec3Max(Vector3 a, Vector3 b) {
return new Vector3(
Mathf.Max(a.x, b.x),
Mathf.Max(a.y, b.y),
Mathf.Max(a.z, b.z));
}
// ------------------------------------------------------------------------
//
// Ceil/Floor/Round
//
// ------------------------------------------------------------------------
public static Vector3 Vec3Ceil(Vector3 v) {
return new Vector3(
Mathf.Ceil(v.x),
Mathf.Ceil(v.y),
Mathf.Ceil(v.z));
}
public static Vector3 Vec3Floor(Vector3 v) {
return new Vector3(
Mathf.Floor(v.x),
Mathf.Floor(v.y),
Mathf.Floor(v.z));
}
public static Vector3 Vec3Round(Vector3 v) {
return new Vector3(
Mathf.Round(v.x),
@@ -92,13 +115,19 @@ namespace IsoTools {
Mathf.Round(v.z));
}
// ------------------------------------------------------------------------
//
// Div/DivCeil/DivFloor/DivRound
//
// ------------------------------------------------------------------------
public static Vector3 Vec3Div(Vector3 a, float b) {
return new Vector3(
a.x / b,
a.y / b,
a.z / b);
}
public static Vector3 Vec3Div(Vector3 a, Vector3 b) {
return new Vector3(
a.x / b.x,
@@ -113,63 +142,134 @@ namespace IsoTools {
public static Vector3 Vec3DivCeil(Vector3 a, Vector3 b) {
return Vec3Ceil(Vec3Div(a, b));
}
public static Vector3 Vec3DivFloor(Vector3 a, float b) {
return Vec3Floor(Vec3Div(a, b));
}
public static Vector3 Vec3DivFloor(Vector3 a, Vector3 b) {
return Vec3Floor(Vec3Div(a, b));
}
public static Vector3 Vec3DivRound(Vector3 a, float b) {
return Vec3Round(Vec3Div(a, b));
}
public static Vector3 Vec3DivRound(Vector3 a, Vector3 b) {
return Vec3Round(Vec3Div(a, b));
}
public static Vector3 Vec3Min(Vector3 a, Vector3 b) {
return new Vector3(
Mathf.Min(a.x, b.x),
Mathf.Min(a.y, b.y),
Mathf.Min(a.z, b.z));
// ------------------------------------------------------------------------
//
// FromX
//
// ------------------------------------------------------------------------
public static Vector2 Vec2FromX(float x) {
return new Vector2(x, 0.0f);
}
public static Vector3 Vec3Max(Vector3 a, Vector3 b) {
return new Vector3(
Mathf.Max(a.x, b.x),
Mathf.Max(a.y, b.y),
Mathf.Max(a.z, b.z));
public static Vector2 Vec2FromY(float y) {
return new Vector2(0.0f, y);
}
public static Vector2 Vec2FromXY(float x, float y) {
return new Vector2(x, y);
}
public static Vector3 Vec3FromX(float x) {
return new Vector3(x, 0.0f, 0.0f);
}
public static Vector3 Vec3FromY(float y) {
return new Vector3(0.0f, y, 0.0f);
}
public static Vector3 Vec3FromZ(float z) {
return new Vector3(0.0f, 0.0f, z);
}
public static Vector3 Vec3FromXY(float x, float y) {
return new Vector3(x, y, 0.0f);
}
public static Vector3 Vec3FromYZ(float y, float z) {
return new Vector3(0.0f, y, z);
}
public static Vector3 Vec3FromXZ(float x, float z) {
return new Vector3(x, 0.0f, z);
}
// ------------------------------------------------------------------------
//
// ChangeX
//
// ------------------------------------------------------------------------
public static Vector2 Vec2ChangeX(Vector2 v, float x) {
return new Vector2(x, v.y);
}
public static Vector2 Vec2ChangeY(Vector2 v, float y) {
return new Vector2(v.x, y);
}
public static Vector3 Vec3ChangeX(Vector3 v, float x) {
return new Vector3(x, v.y, v.z);
}
public static Vector3 Vec3ChangeY(Vector3 v, float y) {
return new Vector3(v.x, y, v.z);
}
public static Vector3 Vec3ChangeZ(Vector3 v, float z) {
return new Vector3(v.x, v.y, z);
}
public static Color ColorChangeR(Color c, float r) {
return new Color(r, c.g, c.b, c.a);
public static Vector3 Vec3ChangeXY(Vector3 v, float x, float y) {
return new Vector3(x, y, v.z);
}
public static Vector3 Vec3ChangeYZ(Vector3 v, float y, float z) {
return new Vector3(v.x, y, z);
}
public static Vector3 Vec3ChangeXZ(Vector3 v, float x, float z) {
return new Vector3(x, v.y, z);
}
public static Color ColorChangeG(Color c, float g) {
return new Color(c.r, g, c.b, c.a);
// ------------------------------------------------------------------------
//
// Approximately
//
// -----------------------------------------------------------------------
public static bool Vec2Approximately(Vector2 a, Vector2 b) {
return
Mathf.Approximately(a.x, b.x) &&
Mathf.Approximately(a.y, b.y);
}
public static Color ColorChangeB(Color c, float b) {
return new Color(c.r, c.g, b, c.a);
public static bool Vec3Approximately(Vector3 a, Vector3 b) {
return
Mathf.Approximately(a.x, b.x) &&
Mathf.Approximately(a.y, b.y) &&
Mathf.Approximately(a.z, b.z);
}
public static Color ColorChangeA(Color c, float a) {
return new Color(c.r, c.g, c.b, a);
// ------------------------------------------------------------------------
//
// LookUpCube
//
// ------------------------------------------------------------------------
public static void LookUpCube(Vector3 min, Vector3 max, Action<Vector3> act) {
for ( var z = min.z; z < max.z; ++z ) {
for ( var y = min.y; y < max.y; ++y ) {
for ( var x = min.x; x < max.x; ++x ) {
act(new Vector3(x, y, z));
}}}
}
}
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System;
using System.Linq;
using System.Collections.Generic;
#if UNITY_EDITOR
@@ -39,6 +40,7 @@ namespace IsoTools {
}
bool _dirty = true;
float _lastTileSize = 0.0f;
List<SectorInfo> _sectors = new List<SectorInfo>();
List<ObjectInfo> _objects = new List<ObjectInfo>();
@@ -48,10 +50,6 @@ namespace IsoTools {
Vector3 _objsMaxNumPos = Vector3.zero;
Vector3 _objsNumPosCount = Vector3.zero;
float _lastTileSize = 0.0f;
float _lastMinDepth = 0.0f;
float _lastMaxDepth = 0.0f;
[SerializeField]
public float _tileSize = 32.0f;
/// <summary>Isometric tile size.</summary>
@@ -62,28 +60,6 @@ namespace IsoTools {
ChangeSortingProperty();
}
}
[SerializeField]
public float _minDepth = 0.0f;
/// <summary>Min sorting depth value.</summary>
public float MinDepth {
get { return _minDepth; }
set {
_minDepth = value;
ChangeSortingProperty();
}
}
[SerializeField]
public float _maxDepth = 100.0f;
/// <summary>Max sorting depth value.</summary>
public float MaxDepth {
get { return _maxDepth; }
set {
_maxDepth = value;
ChangeSortingProperty();
}
}
// ------------------------------------------------------------------------
/// <summary>
@@ -103,7 +79,7 @@ namespace IsoTools {
// ------------------------------------------------------------------------
public void MarkDirty(IsoObject obj) {
if ( obj ) {
var renderer = obj.GetComponent<Renderer>();
var renderer = obj.GetComponent<SpriteRenderer>();
if ( renderer && renderer.isVisible ) {
MarkDirty();
}
@@ -146,9 +122,9 @@ namespace IsoTools {
/// <param name="iso_z">Point isometric height.</param>
// ------------------------------------------------------------------------
public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
iso_pos.z = iso_z;
return iso_pos;
return IsoUtils.Vec3ChangeZ(
ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize)),
iso_z);
}
void MarkEditorWorldDirty() {
@@ -174,8 +150,6 @@ namespace IsoTools {
MarkDirty();
FixAllTransforms();
_lastTileSize = TileSize;
_lastMinDepth = MinDepth;
_lastMaxDepth = MaxDepth;
}
int SectorIndex(Vector3 num_pos) {
@@ -206,7 +180,6 @@ namespace IsoTools {
var ms = FindSector(num_pos);
if ( ms != null ) {
act(ms);
var s1 = FindSector(num_pos + new Vector3(-1, 0, 0));
var s2 = FindSector(num_pos + new Vector3( 0, -1, 0));
var s3 = FindSector(num_pos + new Vector3(-1, -1, 0));
@@ -235,14 +208,44 @@ namespace IsoTools {
bool IsDepends(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;
return a_max.x > b_min.x && a_max.y > b_min.y && b_max.z > a_min.z;
var a_yesno = a_max.x > b_min.x && a_max.y > b_min.y && b_max.z > a_min.z;
var b_yesno = b_max.x > a_min.x && b_max.y > a_min.y && a_max.z > b_min.z;
if ( a_yesno && b_yesno ) {
var da_p = new Vector3(a_max.x - b_min.x, a_max.y - b_min.y, a_max.z - b_min.z);
var db_p = new Vector3(b_max.x - a_min.x, b_max.y - a_min.y, b_max.z - a_min.z);
var dd_p = IsoUtils.Vec3Abs(da_p - db_p);
Debug.LogFormat("CoefDB: {0}:::{1}:::{2}", dd_p.x, dd_p.y, dd_p.z);
Debug.LogFormat("----------------------------");
if ( dd_p.z > dd_p.x || dd_p.z > dd_p.y ) {
Debug.Log("by z");
return da_p.z < db_p.z;
} else if ( dd_p.x > dd_p.y && dd_p.x > dd_p.z ) {
Debug.Log("by x");
return da_p.x > db_p.x;
} else if ( dd_p.y > dd_p.x && dd_p.y > dd_p.z) {
Debug.Log("by y");
return da_p.y > db_p.y;
}
/*
if ( dd_p.x < dd_p.y ) {
Debug.Log("by y");
return da_p.y > db_p.y;
} else {
Debug.Log("by x");
return da_p.x > db_p.x;
}*/
}
return a_yesno;
}
void SetupSectorSize(IsoObject[] iso_objects) {
_objsSectorSize = 0.0f;
var objsSum = 0;
foreach ( var obj in iso_objects ) {
var renderer = obj.GetComponent<Renderer>();
var renderer = obj.GetComponent<SpriteRenderer>();
if ( renderer && renderer.isVisible ) {
++objsSum;
_objsSectorSize += Mathf.Max(obj.Size.x, obj.Size.y, obj.Size.z);
@@ -256,7 +259,7 @@ namespace IsoTools {
_objsMinNumPos = Vector3.zero;
_objsMaxNumPos = Vector3.one;
foreach ( var obj in iso_objects ) {
var renderer = obj.GetComponent<Renderer>();
var renderer = obj.GetComponent<SpriteRenderer>();
if ( renderer && renderer.isVisible ) {
var max_size = IsoUtils.Vec3Max(Vector3.one, obj.Size);
var min_npos = IsoUtils.Vec3DivFloor(obj.Position, _objsSectorSize);
@@ -307,7 +310,7 @@ namespace IsoTools {
}
void PlaceAllObjects() {
var depth = MinDepth;
var depth = 0;
foreach ( var info in _objects ) {
depth = PlaceObject(info, depth);
}
@@ -316,12 +319,16 @@ namespace IsoTools {
_depends.Clear();
}
void PlaceObject(IsoObject obj, float depth) {
var trans = obj.gameObject.transform;
trans.position = new Vector3(trans.position.x, trans.position.y, depth);
void PlaceObject(IsoObject obj, int depth) {
//var trans = obj.gameObject.transform;
//trans.position = new Vector3(trans.position.x, trans.position.y, depth);
var renderer = obj.GetComponent<SpriteRenderer>();
if ( renderer ) {
renderer.sortingOrder = depth;
}
}
float PlaceObject(ObjectInfo info, float depth) {
int PlaceObject(ObjectInfo info, int depth) {
if ( info.Visited ) {
return depth;
}
@@ -332,7 +339,7 @@ namespace IsoTools {
depth = PlaceObject(obj, depth);
}
PlaceObject(info.IsoObject, depth);
return depth + (MaxDepth - MinDepth) / _objects.Count;
return depth - 1;
}
void StepSort() {
@@ -355,8 +362,6 @@ namespace IsoTools {
void LateUpdate() {
if ( Application.isEditor ) {
if ( !Mathf.Approximately(_lastTileSize, _tileSize) ) TileSize = _tileSize;
if ( !Mathf.Approximately(_lastMinDepth, _minDepth) ) MinDepth = _minDepth;
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth) ) MaxDepth = _maxDepth;
}
StepSort();
}