mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-13 15:52:03 +07:00
Fix parent move
This commit is contained in:
@@ -44,7 +44,6 @@ MonoBehaviour:
|
||||
_position: {x: 0, y: 0, z: 0}
|
||||
_mode: 0
|
||||
_cacheRenderers: 1
|
||||
_isAlignment: 1
|
||||
_isShowBounds: 0
|
||||
--- !u!212 &21263702
|
||||
SpriteRenderer:
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace IsoTools.Internal {
|
||||
Vector3 _center = Vector3.zero;
|
||||
Vector3 _viewCenter = Vector3.zero;
|
||||
|
||||
static public readonly float SnappingDistance = 0.2f;
|
||||
static public readonly float FloatBeautifierEpsilon = 1e-5f;
|
||||
static public readonly float SnappingDistance = 0.2f;
|
||||
static public readonly int FloatBeautifierDigits = 4;
|
||||
|
||||
static bool IsSnappingEnabled() {
|
||||
return !Event.current.control;
|
||||
@@ -59,8 +59,7 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
|
||||
float FloatBeautifier(float v) {
|
||||
var rv = Mathf.Round(v);
|
||||
return Mathf.Abs(rv - v) < FloatBeautifierEpsilon ? rv : v;
|
||||
return (float)System.Math.Round(v, FloatBeautifierDigits);
|
||||
}
|
||||
|
||||
Vector2 Vector2Beautifier(Vector2 v) {
|
||||
|
||||
@@ -199,6 +199,8 @@ namespace IsoTools {
|
||||
public float Offset3d = 0.0f;
|
||||
public Vector2 MinSector = Vector2.zero;
|
||||
public Vector2 MaxSector = Vector2.zero;
|
||||
public Transform Transform = null;
|
||||
public Vector2 LastTrans = Vector2.zero;
|
||||
public List<Renderer> Renderers = new List<Renderer>();
|
||||
public IsoAssocList<IsoObject> SelfDepends = new IsoAssocList<IsoObject>(47);
|
||||
public IsoAssocList<IsoObject> TheirDepends = new IsoAssocList<IsoObject>(47);
|
||||
@@ -213,12 +215,6 @@ namespace IsoTools {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Vector3 _lastSize = Vector3.zero;
|
||||
Vector3 _lastPosition = Vector3.zero;
|
||||
Vector2 _lastTransPos = Vector2.zero;
|
||||
Mode _lastMode = Mode.Mode2d;
|
||||
bool _lastCacheRenderers = false;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] bool _isShowBounds = false;
|
||||
|
||||
@@ -246,9 +242,10 @@ namespace IsoTools {
|
||||
|
||||
public void FixTransform() {
|
||||
if ( isoWorld ) {
|
||||
transform.position = IsoUtils.Vec3ChangeZ(
|
||||
FixInternalTransform();
|
||||
Internal.Transform.position = IsoUtils.Vec3ChangeZ(
|
||||
isoWorld.IsoToScreen(position),
|
||||
transform.position.z);
|
||||
Internal.Transform.position.z);
|
||||
FixScreenRect();
|
||||
}
|
||||
FixLastProperties();
|
||||
@@ -257,8 +254,9 @@ namespace IsoTools {
|
||||
|
||||
public void FixIsoPosition() {
|
||||
if ( isoWorld ) {
|
||||
FixInternalTransform();
|
||||
position = isoWorld.ScreenToIso(
|
||||
transform.position,
|
||||
Internal.Transform.position,
|
||||
positionZ);
|
||||
}
|
||||
}
|
||||
@@ -282,13 +280,14 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
void FixLastProperties() {
|
||||
#if UNITY_EDITOR
|
||||
_lastSize = size;
|
||||
_lastPosition = position;
|
||||
_lastTransPos = transform.position;
|
||||
_lastMode = mode;
|
||||
_lastCacheRenderers = cacheRenderers;
|
||||
#endif
|
||||
FixInternalTransform();
|
||||
Internal.LastTrans = Internal.Transform.position;
|
||||
}
|
||||
|
||||
void FixInternalTransform() {
|
||||
if ( !Internal.Transform ) {
|
||||
Internal.Transform = transform;
|
||||
}
|
||||
}
|
||||
|
||||
void MartDirtyIsoWorld() {
|
||||
@@ -344,24 +343,6 @@ namespace IsoTools {
|
||||
IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red);
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
|
||||
size = _size;
|
||||
}
|
||||
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
|
||||
position = _position;
|
||||
}
|
||||
if ( !IsoUtils.Vec2Approximately(_lastTransPos, transform.position) ) {
|
||||
FixIsoPosition();
|
||||
}
|
||||
if ( _lastCacheRenderers != _cacheRenderers ) {
|
||||
cacheRenderers = _cacheRenderers;
|
||||
}
|
||||
if ( _lastMode != _mode ) {
|
||||
mode = _mode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ namespace IsoTools {
|
||||
bool UpdateIsoObjectBounds3d(IsoObject iso_object) {
|
||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
||||
var minmax3d = IsoObjectMinMax3D(iso_object);
|
||||
var offset3d = iso_object.transform.position.z - minmax3d.center;
|
||||
var offset3d = iso_object.Internal.Transform.position.z - minmax3d.center;
|
||||
if ( iso_object.Internal.MinMax3d.Approximately(minmax3d) ||
|
||||
!Mathf.Approximately(iso_object.Internal.Offset3d, offset3d) )
|
||||
{
|
||||
@@ -603,6 +603,12 @@ namespace IsoTools {
|
||||
_oldVisibles.Clear();
|
||||
for ( int i = 0, e = _objects.Count; i < e; ++i ) {
|
||||
var iso_object = _objects[i];
|
||||
if ( !IsoUtils.Vec2Approximately(
|
||||
iso_object.Internal.LastTrans,
|
||||
iso_object.Internal.Transform.position) )
|
||||
{
|
||||
iso_object.FixIsoPosition();
|
||||
}
|
||||
if ( IsIsoObjectVisible(iso_object) ) {
|
||||
iso_object.Internal.Placed = false;
|
||||
_oldVisibles.Add(iso_object);
|
||||
@@ -686,7 +692,7 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
void PlaceIsoObject(IsoObject iso_object, float depth) {
|
||||
var trans = iso_object.transform;
|
||||
var trans = iso_object.Internal.Transform;
|
||||
trans.position = IsoUtils.Vec3ChangeZ(trans.position, depth);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user