mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-14 17:09:31 +07:00
alignment flag dynamic change fix.
alignment work in editor only. mini code refactoring.
This commit is contained in:
1100
Assets/IsoTools/Examples/Scenes/Scene3.unity
Normal file
1100
Assets/IsoTools/Examples/Scenes/Scene3.unity
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/IsoTools/Examples/Scenes/Scene3.unity.meta
Normal file
8
Assets/IsoTools/Examples/Scenes/Scene3.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ea09039680944f5a209ed6ed266880
|
||||
timeCreated: 1424000856
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,161 +5,155 @@ using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace IsoTools {
|
||||
[ExecuteInEditMode]
|
||||
public class IsoObject : MonoBehaviour {
|
||||
|
||||
Transform _transform = null;
|
||||
Vector3 _lastPosition = Vector3.zero;
|
||||
Vector3 _lastTransform = Vector3.zero;
|
||||
[ExecuteInEditMode]
|
||||
public class IsoObject : MonoBehaviour {
|
||||
|
||||
Transform _transform = null;
|
||||
Vector3 _lastTransform = Vector3.zero;
|
||||
Vector3 _lastPosition = Vector3.zero;
|
||||
Vector3 _lastSize = Vector3.zero;
|
||||
bool _lastSorting = false;
|
||||
bool _lastAlignment = false;
|
||||
|
||||
[SerializeField]
|
||||
Vector3 _position = Vector3.zero;
|
||||
/// <summary>Isometric object position.</summary>
|
||||
public Vector3 Position {
|
||||
get { return _position; }
|
||||
set {
|
||||
_position = value;
|
||||
if ( Alignment ) {
|
||||
FixAlignment();
|
||||
} else {
|
||||
[SerializeField]
|
||||
Vector3 _position = Vector3.zero;
|
||||
/// <summary>Isometric object position.</summary>
|
||||
public Vector3 Position {
|
||||
get { return _position; }
|
||||
set {
|
||||
_position = value;
|
||||
FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
Vector3 _size = Vector3.one;
|
||||
/// <summary>Isometric object size.</summary>
|
||||
public Vector3 Size {
|
||||
get { return _size; }
|
||||
set {
|
||||
_size = value;
|
||||
FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool _sorting = true;
|
||||
/// <summary>Auto sorting tile.</summary>
|
||||
public bool Sorting {
|
||||
get { return _sorting; }
|
||||
set {
|
||||
_sorting = value;
|
||||
FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool _alignment = true;
|
||||
/// <summary>Auto alignment position by isometric tile size.</summary>
|
||||
public bool Alignment {
|
||||
get { return _alignment; }
|
||||
set {
|
||||
_alignment = value;
|
||||
FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
[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));
|
||||
}
|
||||
set {
|
||||
Position = value;
|
||||
}
|
||||
}
|
||||
|
||||
IsoWorld _iso_world = null;
|
||||
public IsoWorld GetIsoWorld() {
|
||||
if ( !_iso_world ) {
|
||||
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
}
|
||||
if ( !_iso_world ) {
|
||||
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||
}
|
||||
return _iso_world;
|
||||
}
|
||||
|
||||
public void ResetIsoWorld() {
|
||||
_iso_world = null;
|
||||
}
|
||||
|
||||
public void FixTransform() {
|
||||
if ( Application.isEditor && Alignment ) {
|
||||
_position = TilePosition;
|
||||
}
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && _transform ) {
|
||||
Vector3 trans = iso_world.IsoToScreen(Position);
|
||||
trans.z = _transform.position.z;
|
||||
_transform.position = trans;
|
||||
FixLastProperties(trans);
|
||||
}
|
||||
MartDirtyIsoWorld();
|
||||
MarkEditorObjectDirty();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
Vector3 _size = Vector3.one;
|
||||
/// <summary>Isometric object size.</summary>
|
||||
public Vector3 Size {
|
||||
get { return _size; }
|
||||
set {
|
||||
_size = value;
|
||||
if ( Alignment ) {
|
||||
FixAlignment();
|
||||
} else {
|
||||
FixTransform();
|
||||
public void FixIsoPosition() {
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && _transform ) {
|
||||
Vector2 trans = _transform.position;
|
||||
Position = iso_world.ScreenToIso(trans, Position.z);
|
||||
}
|
||||
MartDirtyIsoWorld();
|
||||
MarkEditorObjectDirty();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool _alignment = true;
|
||||
/// <summary>Auto alignment position by isometric tile size.</summary>
|
||||
public bool Alignment {
|
||||
get { return _alignment; }
|
||||
set {
|
||||
_alignment = value;
|
||||
if ( Alignment ) {
|
||||
FixAlignment();
|
||||
} else {
|
||||
FixTransform();
|
||||
}
|
||||
MartDirtyIsoWorld();
|
||||
MarkEditorObjectDirty();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool _sorting = true;
|
||||
/// <summary>Auto sorting tile.</summary>
|
||||
public bool Sorting {
|
||||
get { return _sorting; }
|
||||
set {
|
||||
_sorting = value;
|
||||
MartDirtyIsoWorld();
|
||||
MarkEditorObjectDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 TilePosition {
|
||||
get {
|
||||
return new Vector3(
|
||||
Mathf.Round(Position.x),
|
||||
Mathf.Round(Position.y),
|
||||
Mathf.Round(Position.z));
|
||||
}
|
||||
}
|
||||
|
||||
IsoWorld _iso_world = null;
|
||||
public IsoWorld GetIsoWorld() {
|
||||
if ( !_iso_world ) {
|
||||
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
}
|
||||
if ( !_iso_world ) {
|
||||
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||
}
|
||||
return _iso_world;
|
||||
}
|
||||
|
||||
public void ResetIsoWorld() {
|
||||
_iso_world = null;
|
||||
}
|
||||
|
||||
public void FixAlignment() {
|
||||
_position = TilePosition;
|
||||
FixTransform();
|
||||
MartDirtyIsoWorld();
|
||||
MarkEditorObjectDirty();
|
||||
}
|
||||
|
||||
public void FixTransform() {
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && _transform ) {
|
||||
Vector3 trans = iso_world.IsoToScreen(Position);
|
||||
trans.z = _transform.position.z;
|
||||
_transform.position = trans;
|
||||
_lastPosition = Position;
|
||||
void FixLastProperties(Vector3 trans) {
|
||||
_lastTransform = trans;
|
||||
_lastPosition = Position;
|
||||
_lastSize = Size;
|
||||
_lastSorting = Sorting;
|
||||
_lastAlignment = Alignment;
|
||||
}
|
||||
}
|
||||
|
||||
public void FixIsoPosition() {
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && _transform ) {
|
||||
Vector2 trans = _transform.position;
|
||||
Position = iso_world.ScreenToIso(trans, Position.z);
|
||||
FixTransform();
|
||||
void MartDirtyIsoWorld() {
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && Sorting ) {
|
||||
iso_world.MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MartDirtyIsoWorld() {
|
||||
var iso_world = GetIsoWorld();
|
||||
if ( iso_world && Sorting ) {
|
||||
iso_world.MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void MarkEditorObjectDirty() {
|
||||
void MarkEditorObjectDirty() {
|
||||
#if UNITY_EDITOR
|
||||
if ( Application.isEditor ) {
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
if ( Application.isEditor ) {
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Awake() {
|
||||
_transform = gameObject.transform;
|
||||
_lastPosition = Position;
|
||||
_lastTransform = _transform.position;
|
||||
FixIsoPosition();
|
||||
MartDirtyIsoWorld();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if ( _lastPosition != _position ) {
|
||||
Position = _position;
|
||||
}
|
||||
if ( _lastTransform != _transform.position ) {
|
||||
|
||||
void Awake() {
|
||||
_transform = gameObject.transform;
|
||||
FixLastProperties(_transform.position);
|
||||
FixIsoPosition();
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if ( _lastTransform != _transform.position ) {
|
||||
FixIsoPosition();
|
||||
}
|
||||
if ( Application.isEditor ) {
|
||||
if ( _lastPosition != _position ) Position = _position;
|
||||
if ( _lastSize != _size ) Size = _size;
|
||||
if ( _lastSorting != _sorting ) Sorting = _sorting;
|
||||
if ( _lastAlignment != _alignment ) Alignment = _alignment;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
MartDirtyIsoWorld();
|
||||
void OnEnable() {
|
||||
MartDirtyIsoWorld();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace IsoTools
|
||||
@@ -2,234 +2,234 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IsoTools {
|
||||
[ExecuteInEditMode]
|
||||
public class IsoWorld : MonoBehaviour {
|
||||
|
||||
/// <summary>World tile types.</summary>
|
||||
public enum TileTypes {
|
||||
Isometric,
|
||||
UpDown
|
||||
}
|
||||
|
||||
/// <summary>World tile type.</summary>
|
||||
public TileTypes TileType = TileTypes.Isometric;
|
||||
/// <summary>Isometric tile size.</summary>
|
||||
public float TileSize = 32.0f;
|
||||
/// <summary>Start sorting depth value.</summary>
|
||||
public float StartDepth = 0.0f;
|
||||
/// <summary>Step sorting depth value.</summary>
|
||||
public float StepDepth = 0.1f;
|
||||
[ExecuteInEditMode]
|
||||
public class IsoWorld : MonoBehaviour {
|
||||
|
||||
/// <summary>World tile types.</summary>
|
||||
public enum TileTypes {
|
||||
Isometric,
|
||||
UpDown
|
||||
}
|
||||
|
||||
/// <summary>World tile type.</summary>
|
||||
public TileTypes TileType = TileTypes.Isometric;
|
||||
/// <summary>Isometric tile size.</summary>
|
||||
public float TileSize = 32.0f;
|
||||
/// <summary>Start sorting depth value.</summary>
|
||||
public float StartDepth = 0.0f;
|
||||
/// <summary>Step sorting depth value.</summary>
|
||||
public float StepDepth = 0.1f;
|
||||
|
||||
class ObjectInfo {
|
||||
public IsoObject IsoObject;
|
||||
public bool Visited;
|
||||
public int BeginDepend;
|
||||
public int EndDepend;
|
||||
public ObjectInfo(IsoObject obj) {
|
||||
IsoObject = obj;
|
||||
}
|
||||
public void Reset(int first_depend) {
|
||||
Visited = false;
|
||||
BeginDepend = first_depend;
|
||||
EndDepend = first_depend;
|
||||
}
|
||||
}
|
||||
|
||||
bool _dirty = true;
|
||||
float _lastTileSize = 0.0f;
|
||||
TileTypes _lastTileType = TileTypes.Isometric;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Marks world for resorting.
|
||||
/// </summary>
|
||||
// ------------------------------------------------------------------------
|
||||
public void MarkDirty() {
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert isometric coordinates to screen coordinates
|
||||
/// </summary>
|
||||
/// <returns>Screen coordinates</returns>
|
||||
/// <param name="pos">Isometric coordinates.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector2 IsoToScreen(Vector3 pos) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric:
|
||||
return new Vector2(
|
||||
(pos.x - pos.y),
|
||||
(pos.x + pos.y) * 0.5f + pos.z) * TileSize;
|
||||
case TileTypes.UpDown:
|
||||
return new Vector2(
|
||||
pos.x,
|
||||
pos.y + pos.z) * TileSize;
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert screen coordinates to isometric coordinates
|
||||
/// </summary>
|
||||
/// <returns>Isometric coordinates</returns>
|
||||
/// <param name="pos">Screen coordinates.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector3 ScreenToIso(Vector2 pos) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric:
|
||||
return new Vector3(
|
||||
(pos.x * 0.5f + pos.y),
|
||||
(pos.y - pos.x * 0.5f),
|
||||
0.0f) / TileSize;
|
||||
case TileTypes.UpDown:
|
||||
return new Vector3(
|
||||
pos.x,
|
||||
pos.y,
|
||||
0.0f) / TileSize;
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert screen coordinates to isometric coordinates with specified isometric height
|
||||
/// </summary>
|
||||
/// <returns>Isometric coordinates</returns>
|
||||
/// <param name="pos">Screen coordinates.</param>
|
||||
/// <param name="iso_z">Point isometric height.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric: {
|
||||
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
|
||||
iso_pos.z = iso_z;
|
||||
return iso_pos;
|
||||
class ObjectInfo {
|
||||
public IsoObject IsoObject;
|
||||
public bool Visited;
|
||||
public int BeginDepend;
|
||||
public int EndDepend;
|
||||
public ObjectInfo(IsoObject obj) {
|
||||
IsoObject = obj;
|
||||
}
|
||||
case TileTypes.UpDown: {
|
||||
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
|
||||
iso_pos.z = iso_z;
|
||||
return iso_pos;
|
||||
}
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
void _fixAllTransforms() {
|
||||
var objects = _scanObjects(false);
|
||||
foreach ( var obj in objects ) {
|
||||
obj.IsoObject.FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
void _fixTileSize() {
|
||||
_fixAllTransforms();
|
||||
_lastTileSize = TileSize;
|
||||
}
|
||||
|
||||
void _fixTileType() {
|
||||
_fixAllTransforms();
|
||||
_lastTileType = TileType;
|
||||
}
|
||||
|
||||
void _fixDirty() {
|
||||
_manualSort();
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
void _fixDisable() {
|
||||
var objects = _scanObjects(false);
|
||||
foreach ( var obj in objects ) {
|
||||
obj.IsoObject.ResetIsoWorld();
|
||||
}
|
||||
}
|
||||
|
||||
IList<ObjectInfo> _scanObjects(bool onlySorting) {
|
||||
IsoObject[] iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
||||
var objects = new List<ObjectInfo>(iso_objects.Length);
|
||||
foreach ( var iso_object in iso_objects ) {
|
||||
if ( !onlySorting || iso_object.Sorting ) {
|
||||
var info = new ObjectInfo(iso_object);
|
||||
objects.Add(info);
|
||||
public void Reset(int first_depend) {
|
||||
Visited = false;
|
||||
BeginDepend = first_depend;
|
||||
EndDepend = first_depend;
|
||||
}
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
IList<int> _scanDepends(IList<ObjectInfo> objects) {
|
||||
var depends = new List<int>(objects.Count);
|
||||
foreach ( var obj_a in objects ) {
|
||||
obj_a.Reset(depends.Count);
|
||||
var obj_ao = obj_a.IsoObject;
|
||||
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
||||
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
||||
for ( int i = 0; i < objects.Count; ++i ) {
|
||||
var obj_bo = objects[i].IsoObject;
|
||||
if ( obj_ao != obj_bo ) {
|
||||
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 ) {
|
||||
depends.Add(i);
|
||||
++obj_a.EndDepend;
|
||||
bool _dirty = true;
|
||||
float _lastTileSize = 0.0f;
|
||||
TileTypes _lastTileType = TileTypes.Isometric;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Marks world for resorting.
|
||||
/// </summary>
|
||||
// ------------------------------------------------------------------------
|
||||
public void MarkDirty() {
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert isometric coordinates to screen coordinates
|
||||
/// </summary>
|
||||
/// <returns>Screen coordinates</returns>
|
||||
/// <param name="pos">Isometric coordinates.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector2 IsoToScreen(Vector3 pos) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric:
|
||||
return new Vector2(
|
||||
(pos.x - pos.y),
|
||||
(pos.x + pos.y) * 0.5f + pos.z) * TileSize;
|
||||
case TileTypes.UpDown:
|
||||
return new Vector2(
|
||||
pos.x,
|
||||
pos.y + pos.z) * TileSize;
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert screen coordinates to isometric coordinates
|
||||
/// </summary>
|
||||
/// <returns>Isometric coordinates</returns>
|
||||
/// <param name="pos">Screen coordinates.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector3 ScreenToIso(Vector2 pos) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric:
|
||||
return new Vector3(
|
||||
(pos.x * 0.5f + pos.y),
|
||||
(pos.y - pos.x * 0.5f),
|
||||
0.0f) / TileSize;
|
||||
case TileTypes.UpDown:
|
||||
return new Vector3(
|
||||
pos.x,
|
||||
pos.y,
|
||||
0.0f) / TileSize;
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert screen coordinates to isometric coordinates with specified isometric height
|
||||
/// </summary>
|
||||
/// <returns>Isometric coordinates</returns>
|
||||
/// <param name="pos">Screen coordinates.</param>
|
||||
/// <param name="iso_z">Point isometric height.</param>
|
||||
// ------------------------------------------------------------------------
|
||||
public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
|
||||
switch ( TileType ) {
|
||||
case TileTypes.Isometric: {
|
||||
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
|
||||
iso_pos.z = iso_z;
|
||||
return iso_pos;
|
||||
}
|
||||
case TileTypes.UpDown: {
|
||||
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
|
||||
iso_pos.z = iso_z;
|
||||
return iso_pos;
|
||||
}
|
||||
default:
|
||||
throw new UnityException("IsoWorld. Type is wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
void _fixAllTransforms() {
|
||||
var objects = _scanObjects(false);
|
||||
foreach ( var obj in objects ) {
|
||||
obj.IsoObject.FixTransform();
|
||||
}
|
||||
}
|
||||
|
||||
void _fixTileSize() {
|
||||
_fixAllTransforms();
|
||||
_lastTileSize = TileSize;
|
||||
}
|
||||
|
||||
void _fixTileType() {
|
||||
_fixAllTransforms();
|
||||
_lastTileType = TileType;
|
||||
}
|
||||
|
||||
void _fixDirty() {
|
||||
_manualSort();
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
void _fixDisable() {
|
||||
var objects = _scanObjects(false);
|
||||
foreach ( var obj in objects ) {
|
||||
obj.IsoObject.ResetIsoWorld();
|
||||
}
|
||||
}
|
||||
|
||||
IList<ObjectInfo> _scanObjects(bool onlySorting) {
|
||||
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
||||
var objects = new List<ObjectInfo>(iso_objects.Length);
|
||||
foreach ( var iso_object in iso_objects ) {
|
||||
if ( !onlySorting || iso_object.Sorting ) {
|
||||
var info = new ObjectInfo(iso_object);
|
||||
objects.Add(info);
|
||||
}
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
IList<int> _scanDepends(IList<ObjectInfo> objects) {
|
||||
var depends = new List<int>(objects.Count);
|
||||
foreach ( var obj_a in objects ) {
|
||||
obj_a.Reset(depends.Count);
|
||||
var obj_ao = obj_a.IsoObject;
|
||||
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
||||
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
||||
for ( int i = 0; i < objects.Count; ++i ) {
|
||||
var obj_bo = objects[i].IsoObject;
|
||||
if ( obj_ao != obj_bo ) {
|
||||
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 ) {
|
||||
depends.Add(i);
|
||||
++obj_a.EndDepend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return depends;
|
||||
}
|
||||
return depends;
|
||||
}
|
||||
|
||||
void _manualSort() {
|
||||
var objects = _scanObjects(true);
|
||||
var depends = _scanDepends(objects);
|
||||
var depth = StartDepth;
|
||||
foreach ( var info in objects ) {
|
||||
_placeObject(info, objects, depends, ref depth);
|
||||
}
|
||||
}
|
||||
|
||||
void _placeObject(IsoObject obj, float depth) {
|
||||
var pos = obj.gameObject.transform.position;
|
||||
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
||||
}
|
||||
|
||||
void _placeObject(ObjectInfo info, IList<ObjectInfo> objects, IList<int> depends, ref float depth) {
|
||||
if ( !info.Visited ) {
|
||||
info.Visited = true;
|
||||
for ( int i = info.BeginDepend; i < info.EndDepend && i < depends.Count; ++i ) {
|
||||
var object_index = depends[i];
|
||||
var obj = objects[object_index];
|
||||
_placeObject(obj, objects, depends, ref depth);
|
||||
void _manualSort() {
|
||||
var objects = _scanObjects(true);
|
||||
var depends = _scanDepends(objects);
|
||||
var depth = StartDepth;
|
||||
foreach ( var info in objects ) {
|
||||
_placeObject(info, objects, depends, ref depth);
|
||||
}
|
||||
_placeObject(info.IsoObject, depth);
|
||||
depth += StepDepth;
|
||||
}
|
||||
}
|
||||
|
||||
void Start() {
|
||||
_fixTileSize();
|
||||
_fixTileType();
|
||||
_fixDirty();
|
||||
}
|
||||
void _placeObject(IsoObject obj, float depth) {
|
||||
var pos = obj.gameObject.transform.position;
|
||||
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
||||
}
|
||||
|
||||
void LateUpdate() {
|
||||
if ( _lastTileSize != TileSize ) {
|
||||
void _placeObject(ObjectInfo info, IList<ObjectInfo> objects, IList<int> depends, ref float depth) {
|
||||
if ( !info.Visited ) {
|
||||
info.Visited = true;
|
||||
for ( int i = info.BeginDepend; i < info.EndDepend && i < depends.Count; ++i ) {
|
||||
var object_index = depends[i];
|
||||
var obj = objects[object_index];
|
||||
_placeObject(obj, objects, depends, ref depth);
|
||||
}
|
||||
_placeObject(info.IsoObject, depth);
|
||||
depth += StepDepth;
|
||||
}
|
||||
}
|
||||
|
||||
void Start() {
|
||||
_fixTileSize();
|
||||
}
|
||||
if ( _lastTileType != TileType ) {
|
||||
_fixTileType();
|
||||
}
|
||||
if ( _dirty ) {
|
||||
_fixDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_fixDisable();
|
||||
void LateUpdate() {
|
||||
if ( _lastTileSize != TileSize ) {
|
||||
_fixTileSize();
|
||||
}
|
||||
if ( _lastTileType != TileType ) {
|
||||
_fixTileType();
|
||||
}
|
||||
if ( _dirty ) {
|
||||
_fixDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_fixDisable();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace IsoTools
|
||||
Reference in New Issue
Block a user