mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
fix change iso world on fly
This commit is contained in:
@@ -20,7 +20,7 @@ public class IsoObject : MonoBehaviour {
|
|||||||
} else {
|
} else {
|
||||||
FixTransform();
|
FixTransform();
|
||||||
}
|
}
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
EditorUtility.SetDirty(this);
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ public class IsoObject : MonoBehaviour {
|
|||||||
} else {
|
} else {
|
||||||
FixTransform();
|
FixTransform();
|
||||||
}
|
}
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
EditorUtility.SetDirty(this);
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class IsoObject : MonoBehaviour {
|
|||||||
} else {
|
} else {
|
||||||
FixTransform();
|
FixTransform();
|
||||||
}
|
}
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
EditorUtility.SetDirty(this);
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
@@ -64,16 +64,18 @@ public class IsoObject : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IsoWorld _iso_world = null;
|
IsoWorld _iso_world = null;
|
||||||
public IsoWorld IsoWorld {
|
public IsoWorld GetIsoWorld() {
|
||||||
get {
|
if ( !_iso_world ) {
|
||||||
if ( !_iso_world ) {
|
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
|
||||||
}
|
|
||||||
if ( !_iso_world ) {
|
|
||||||
throw new UnityException("IsoObject. IsoWorld not found!");
|
|
||||||
}
|
|
||||||
return _iso_world;
|
|
||||||
}
|
}
|
||||||
|
if ( !_iso_world ) {
|
||||||
|
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||||
|
}
|
||||||
|
return _iso_world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetIsoWorld() {
|
||||||
|
_iso_world = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixAlignment() {
|
public void FixAlignment() {
|
||||||
@@ -82,31 +84,44 @@ public class IsoObject : MonoBehaviour {
|
|||||||
Mathf.Round(_position.y),
|
Mathf.Round(_position.y),
|
||||||
Mathf.Round(_position.z));
|
Mathf.Round(_position.z));
|
||||||
FixTransform();
|
FixTransform();
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
EditorUtility.SetDirty(this);
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixTransform() {
|
public void FixTransform() {
|
||||||
Vector3 trans = IsoWorld.IsoToScreen(Position);
|
var iso_world = GetIsoWorld();
|
||||||
trans.z = _transform.position.z;
|
if ( iso_world && _transform ) {
|
||||||
_transform.position = trans;
|
Vector3 trans = iso_world.IsoToScreen(Position);
|
||||||
_lastPosition = Position;
|
trans.z = _transform.position.z;
|
||||||
_lastTransform = trans;
|
_transform.position = trans;
|
||||||
|
_lastPosition = Position;
|
||||||
|
_lastTransform = trans;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixIsoPosition() {
|
public void FixIsoPosition() {
|
||||||
Vector2 trans = _transform.position;
|
var iso_world = GetIsoWorld();
|
||||||
Position = IsoWorld.ScreenToIso(trans, Position.z);
|
if ( iso_world && _transform ) {
|
||||||
FixTransform();
|
Vector2 trans = _transform.position;
|
||||||
|
Position = iso_world.ScreenToIso(trans, Position.z);
|
||||||
|
FixTransform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MartDirtyIsoWorld() {
|
||||||
|
var iso_world = GetIsoWorld();
|
||||||
|
if ( iso_world ) {
|
||||||
|
iso_world.MarkDirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
_transform = gameObject.transform;
|
_transform = gameObject.transform;
|
||||||
_lastPosition = Position;
|
_lastPosition = Position;
|
||||||
_lastTransform = _transform.position;
|
_lastTransform = _transform.position;
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
@@ -119,6 +134,6 @@ public class IsoObject : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
IsoWorld.MarkDirty();
|
MartDirtyIsoWorld();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +67,14 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
_manualSort();
|
_manualSort();
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _fixDisable() {
|
||||||
|
_scanObjects();
|
||||||
|
foreach ( var obj in _objects ) {
|
||||||
|
obj.IsoObject.ResetIsoWorld();
|
||||||
|
}
|
||||||
|
_objects.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
void _scanObjects() {
|
void _scanObjects() {
|
||||||
_objects.Clear();
|
_objects.Clear();
|
||||||
@@ -127,7 +135,8 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
_lastTileSize = TileSize;
|
_fixTileSize();
|
||||||
|
_fixDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LateUpdate() {
|
void LateUpdate() {
|
||||||
@@ -138,4 +147,8 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
_fixDirty();
|
_fixDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDisable() {
|
||||||
|
_fixDisable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user