dirty only not overriden prefab properties. fix missed cached transform in IsoObject.

This commit is contained in:
2016-12-21 03:24:59 +07:00
parent a0ec6a93eb
commit f3ed1f3236
2 changed files with 45 additions and 36 deletions

View File

@@ -48,8 +48,8 @@ namespace IsoTools.Internal {
} }
void DrawDetachedInspector() { void DrawDetachedInspector() {
var single_iso_object = targets.Length == 1 ? target as IsoObject : null; var iso_object = targets.Length == 1 ? target as IsoObject : null;
if ( single_iso_object && single_iso_object.IsActive() && !single_iso_object.isoWorld ) { if ( iso_object && iso_object.IsActive() && !iso_object.isoWorld ) {
EditorGUILayout.HelpBox( EditorGUILayout.HelpBox(
"Detached IsoObject\nNeed to be a child of IsoWorld", "Detached IsoObject\nNeed to be a child of IsoWorld",
MessageType.Warning, MessageType.Warning,
@@ -148,10 +148,11 @@ namespace IsoTools.Internal {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void DirtyTargetPosition() { void DirtyTargetPositions() {
if ( targets.Length == 1 && (target is IsoObject) && (target as IsoObject).IsActive() ) { var iso_object = targets.Length == 1 ? target as IsoObject : null;
if ( iso_object && iso_object.IsActive() ) {
var position_prop = serializedObject.FindProperty("_position"); var position_prop = serializedObject.FindProperty("_position");
if ( position_prop != null ) { if ( position_prop != null && !position_prop.prefabOverride ) {
var last_value = position_prop.vector3Value; var last_value = position_prop.vector3Value;
position_prop.vector3Value = last_value + Vector3.one; position_prop.vector3Value = last_value + Vector3.one;
PrefabUtility.RecordPrefabInstancePropertyModifications(target); PrefabUtility.RecordPrefabInstancePropertyModifications(target);
@@ -183,7 +184,7 @@ namespace IsoTools.Internal {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
PrepareTargets(); PrepareTargets();
DirtyTargetPosition(); DirtyTargetPositions();
DrawDefaultInspector(); DrawDefaultInspector();
DrawCustomInspector(); DrawCustomInspector();
} }

View File

@@ -221,21 +221,23 @@ namespace IsoTools {
public void FixTransform() { public void FixTransform() {
var iso_world = isoWorld; var iso_world = isoWorld;
if ( iso_world ) { var cached_transform = FixCachedTransform();
Internal.Transform.position = IsoUtils.Vec3ChangeZ( if ( iso_world && cached_transform ) {
cached_transform.position = IsoUtils.Vec3ChangeZ(
iso_world.IsoToScreen(position), iso_world.IsoToScreen(position),
Internal.Transform.position.z); cached_transform.position.z);
FixScreenBounds(); FixScreenBounds();
FixLastTransform();
MartDirtyIsoWorld();
} }
FixLastProperties();
MartDirtyIsoWorld();
} }
public void FixIsoPosition() { public void FixIsoPosition() {
var iso_world = isoWorld; var iso_world = isoWorld;
if ( iso_world ) { var cached_transform = FixCachedTransform();
if ( iso_world && cached_transform ) {
position = iso_world.ScreenToIso( position = iso_world.ScreenToIso(
Internal.Transform.position, cached_transform.position,
positionZ); positionZ);
} }
} }
@@ -255,17 +257,21 @@ namespace IsoTools {
var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x; var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x;
var b = iso_world.IsoToScreen(position).y; var b = iso_world.IsoToScreen(position).y;
var t = iso_world.IsoToScreen(position + size).y; var t = iso_world.IsoToScreen(position + size).y;
Internal.ScreenBounds = new IsoRect(l, b, r, t); Internal.ScreenBounds.Set(l, b, r, t);
} else { } else {
Internal.ScreenBounds = IsoRect.zero; Internal.ScreenBounds.Set(0.0f, 0.0f, 0.0f, 0.0f);
} }
} }
void FixCachedProperties() { Transform FixCachedTransform() {
Internal.Transform = transform; var ret_value = Internal.Transform;
if ( !ret_value ) {
ret_value = Internal.Transform = transform;
}
return ret_value;
} }
void FixLastProperties() { void FixLastTransform() {
Internal.LastTrans = Internal.Transform.position; Internal.LastTrans = Internal.Transform.position;
} }
@@ -286,8 +292,8 @@ namespace IsoTools {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void Awake() { void Awake() {
FixCachedProperties(); FixCachedTransform();
FixLastProperties(); FixLastTransform();
FixIsoPosition(); FixIsoPosition();
} }
@@ -302,14 +308,13 @@ namespace IsoTools {
protected override void OnTransformParentChanged() { protected override void OnTransformParentChanged() {
base.OnTransformParentChanged(); base.OnTransformParentChanged();
FixCachedProperties(); FixCachedTransform();
FixLastProperties(); FixLastTransform();
FixTransform(); FixTransform();
} }
#if UNITY_EDITOR #if UNITY_EDITOR
void Reset() { void Reset() {
FixCachedProperties();
size = Vector3.one; size = Vector3.one;
position = Vector3.zero; position = Vector3.zero;
mode = Mode.Mode2d; mode = Mode.Mode2d;
@@ -317,7 +322,6 @@ namespace IsoTools {
} }
void OnValidate() { void OnValidate() {
FixCachedProperties();
size = _size; size = _size;
position = _position; position = _position;
mode = _mode; mode = _mode;
@@ -325,22 +329,26 @@ namespace IsoTools {
} }
void OnDrawGizmos() { void OnDrawGizmos() {
if ( isoWorld && isoWorld.isShowIsoBounds ) { var iso_world = isoWorld;
IsoUtils.DrawIsoCube( if ( iso_world ) {
isoWorld, if ( iso_world.isShowIsoBounds ) {
position + size * 0.5f, IsoUtils.DrawIsoCube(
size, iso_world,
Color.red); position + size * 0.5f,
} size,
if ( isoWorld && isoWorld.isShowScreenBounds ) { Color.red);
IsoUtils.DrawRect( }
Internal.ScreenBounds, if ( iso_world.isShowScreenBounds ) {
Color.green); IsoUtils.DrawRect(
Internal.ScreenBounds,
Color.green);
}
} }
} }
void OnDrawGizmosSelected() { void OnDrawGizmosSelected() {
if ( isoWorld && isoWorld.isShowDepends ) { var iso_world = isoWorld;
if ( iso_world && iso_world.isShowDepends ) {
for ( int i = 0, e = Internal.SelfDepends.Count; i < e; ++i ) { for ( int i = 0, e = Internal.SelfDepends.Count; i < e; ++i ) {
IsoUtils.DrawLine( IsoUtils.DrawLine(
Internal.ScreenBounds.center, Internal.ScreenBounds.center,