From 4eacdfa2055e86c1391e9046c7617ca251a5d2d6 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 21 Aug 2015 00:30:07 +0600 Subject: [PATCH] first frame bounds3d fix --- Assets/IsoTools/Scripts/IsoObject.cs | 22 +++++++++++-------- Assets/IsoTools/Scripts/IsoWorld.cs | 32 ++++++++++++++++------------ UnityIso-csharp.sln | 2 +- UnityIso.sln | 2 +- UnityIso.userprefs | 3 ++- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Assets/IsoTools/Scripts/IsoObject.cs b/Assets/IsoTools/Scripts/IsoObject.cs index 9bf50d7..3995ac2 100644 --- a/Assets/IsoTools/Scripts/IsoObject.cs +++ b/Assets/IsoTools/Scripts/IsoObject.cs @@ -208,20 +208,24 @@ namespace IsoTools { IsoWorld _isoWorld = null; public IsoWorld isoWorld { get { - if ( !_isoWorld ) { + if ( (object)_isoWorld == null ) { _isoWorld = GameObject.FindObjectOfType(); } return _isoWorld; } } + public void ResetWorld() { + _isoWorld = null; + } + public void FixTransform() { #if UNITY_EDITOR if ( !Application.isPlaying && isAlignment ) { _position = tilePosition; } #endif - if ( isoWorld ) { + if ( (object)isoWorld != null ) { transform.position = IsoUtils.Vec3ChangeZ( isoWorld.IsoToScreen(position), transform.position.z); @@ -231,7 +235,7 @@ namespace IsoTools { } public void FixIsoPosition() { - if ( isoWorld ) { + if ( (object)isoWorld != null ) { position = isoWorld.ScreenToIso( transform.position, positionZ); @@ -247,7 +251,7 @@ namespace IsoTools { } void MartDirtyIsoWorld() { - if ( isoWorld ) { + if ( (object)isoWorld != null ) { isoWorld.MarkDirty(this); } #if UNITY_EDITOR @@ -262,23 +266,23 @@ namespace IsoTools { // ------------------------------------------------------------------------ void Awake() { - Internal.SelfDepends = new HashSet(new IsoObject[19]); + Internal.SelfDepends = new HashSet(new IsoObject[47]); Internal.SelfDepends.Clear(); - Internal.TheirDepends = new HashSet(new IsoObject[19]); + Internal.TheirDepends = new HashSet(new IsoObject[47]); Internal.TheirDepends.Clear(); FixLastProperties(); FixIsoPosition(); } void OnEnable() { - if ( isoWorld ) { + if ( (object)isoWorld != null ) { isoWorld.AddIsoObject(this); } MartDirtyIsoWorld(); } void OnDisable() { - if ( isoWorld ) { + if ( (object)isoWorld != null ) { isoWorld.RemoveIsoObject(this); } } @@ -295,7 +299,7 @@ namespace IsoTools { } void OnDrawGizmos() { - if ( isShowBounds && isoWorld ) { + if ( isShowBounds && (object)isoWorld != null ) { IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red); } } diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index b84b35f..58f1945 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -9,7 +9,7 @@ namespace IsoTools { [ExecuteInEditMode, DisallowMultipleComponent] public class IsoWorld : MonoBehaviour { - bool _dirty = true; + bool _dirty = false; HashSet _objects = new HashSet(); HashSet _visibles = new HashSet(); HashSet _oldVisibles = new HashSet(); @@ -129,7 +129,7 @@ namespace IsoTools { } public void MarkDirty(IsoObject iso_object) { - if ( iso_object && _visibles.Contains(iso_object) ) { + if ( !iso_object.Internal.Dirty && _visibles.Contains(iso_object) ) { iso_object.Internal.Dirty = true; MarkDirty(); } @@ -163,6 +163,13 @@ namespace IsoTools { _isoRMatrix = _isoMatrix.inverse; } + void ResetAllWorlds() { + var objects_iter = _objects.GetEnumerator(); + while ( objects_iter.MoveNext() ) { + objects_iter.Current.ResetWorld(); + } + } + void FixAllTransforms() { var objects_iter = _objects.GetEnumerator(); while ( objects_iter.MoveNext() ) { @@ -176,7 +183,7 @@ namespace IsoTools { FixAllTransforms(); } - bool CheckIsoObjectChangeBounds3d(IsoObject iso_object) { + bool UpdateIsoObjectBounds3d(IsoObject iso_object) { if ( iso_object.mode == IsoObject.Mode.Mode3d ) { var bounds3d = IsoObject3DBounds(iso_object); var offset3d = iso_object.transform.position.z - bounds3d.center.z; @@ -455,20 +462,13 @@ namespace IsoTools { while ( visibles_iter.MoveNext() ) { var iso_object = visibles_iter.Current; if ( iso_object.Internal.Dirty || !_oldVisibles.Contains(iso_object) ) { - iso_object.Internal.Dirty = true; - } else if ( CheckIsoObjectChangeBounds3d(iso_object) ) { - MarkDirty(); - } - } - - visibles_iter = _visibles.GetEnumerator(); - while ( visibles_iter.MoveNext() ) { - var iso_object = visibles_iter.Current; - if ( iso_object.Internal.Dirty ) { MarkDirty(); SetupIsoObjectDepends(iso_object); iso_object.Internal.Dirty = false; } + if ( UpdateIsoObjectBounds3d(iso_object) ) { + MarkDirty(); + } } var old_visibles_iter = _oldVisibles.GetEnumerator(); @@ -484,7 +484,10 @@ namespace IsoTools { void ClearIsoObjectDepends(IsoObject iso_object) { var their_depends_iter = iso_object.Internal.TheirDepends.GetEnumerator(); while ( their_depends_iter.MoveNext() ) { - their_depends_iter.Current.Internal.SelfDepends.Remove(iso_object); + var their_iso_object = their_depends_iter.Current; + if ( !their_iso_object.Internal.Dirty ) { + their_depends_iter.Current.Internal.SelfDepends.Remove(iso_object); + } } iso_object.Internal.SelfDepends.Clear(); iso_object.Internal.TheirDepends.Clear(); @@ -560,6 +563,7 @@ namespace IsoTools { } void OnDisable() { + ResetAllWorlds(); _objects.Clear(); _visibles.Clear(); _sectors.Clear(); diff --git a/UnityIso-csharp.sln b/UnityIso-csharp.sln index 2d2a294..64b1521 100644 --- a/UnityIso-csharp.sln +++ b/UnityIso-csharp.sln @@ -23,7 +23,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution + GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Assembly-CSharp.csproj Policies = $0 $0.TextStylePolicy = $1 diff --git a/UnityIso.sln b/UnityIso.sln index 800ba17..1b74be0 100644 --- a/UnityIso.sln +++ b/UnityIso.sln @@ -23,7 +23,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution + GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Assembly-CSharp.csproj Policies = $0 $0.TextStylePolicy = $1 diff --git a/UnityIso.userprefs b/UnityIso.userprefs index e35178d..1fa408b 100644 --- a/UnityIso.userprefs +++ b/UnityIso.userprefs @@ -3,7 +3,8 @@ - + +