fix alignment. fix child renderer. physics wip

This commit is contained in:
2015-06-12 15:58:57 +06:00
parent f6b69c72b5
commit 33645632a6
19 changed files with 335 additions and 1872 deletions

View File

@@ -8,12 +8,6 @@ namespace IsoTools {
[ExecuteInEditMode]
public class IsoObject : MonoBehaviour {
#if UNITY_EDITOR
Vector3 _lastSize = Vector3.zero;
Vector3 _lastPosition = Vector3.zero;
Vector2 _lastTransform = Vector2.zero;
#endif
// ------------------------------------------------------------------------
//
// Size
@@ -161,6 +155,29 @@ namespace IsoTools {
get { return new Vector2(TilePositionX, TilePositionZ); }
}
// ------------------------------------------------------------------------
//
// For editor
//
// ------------------------------------------------------------------------
#if UNITY_EDITOR
Vector3 _lastSize = Vector3.zero;
Vector3 _lastPosition = Vector3.zero;
Vector2 _lastTransform = Vector2.zero;
[SerializeField] bool _alignment = true;
[SerializeField] bool _showBounds = false;
public bool Alignment {
get { return _alignment; }
}
public bool ShowBounds {
get { return _showBounds; }
}
#endif
// ------------------------------------------------------------------------
//
// Functions
@@ -185,6 +202,11 @@ namespace IsoTools {
}
public void FixTransform() {
#if UNITY_EDITOR
if ( Application.isEditor && !Application.isPlaying && Alignment ) {
_position = TilePosition;
}
#endif
transform.position = IsoUtils.Vec3ChangeZ(
IsoWorld.IsoToScreen(Position),
transform.position.z);
@@ -228,22 +250,23 @@ namespace IsoTools {
MartDirtyIsoWorld();
}
//TODO: now working for child sprites
void OnBecameVisible() {
MartDirtyIsoWorld();
#if UNITY_EDITOR
void OnDrawGizmos() {
if ( ShowBounds ) {
IsoUtils.DrawCube(Position, Size, Color.red);
}
}
#if UNITY_EDITOR
void Update() {
if ( Application.isEditor ) {
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
FixIsoPosition();
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
Size = _size;
}
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
Position = _position;
}
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
Size = _size;
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
FixIsoPosition();
}
}
}