first frame bounds3d fix

This commit is contained in:
2015-08-21 00:30:07 +06:00
parent 8513938f3f
commit 4eacdfa205
5 changed files with 35 additions and 26 deletions

View File

@@ -208,20 +208,24 @@ namespace IsoTools {
IsoWorld _isoWorld = null;
public IsoWorld isoWorld {
get {
if ( !_isoWorld ) {
if ( (object)_isoWorld == null ) {
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
}
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<IsoObject>(new IsoObject[19]);
Internal.SelfDepends = new HashSet<IsoObject>(new IsoObject[47]);
Internal.SelfDepends.Clear();
Internal.TheirDepends = new HashSet<IsoObject>(new IsoObject[19]);
Internal.TheirDepends = new HashSet<IsoObject>(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);
}
}

View File

@@ -9,7 +9,7 @@ namespace IsoTools {
[ExecuteInEditMode, DisallowMultipleComponent]
public class IsoWorld : MonoBehaviour {
bool _dirty = true;
bool _dirty = false;
HashSet<IsoObject> _objects = new HashSet<IsoObject>();
HashSet<IsoObject> _visibles = new HashSet<IsoObject>();
HashSet<IsoObject> _oldVisibles = new HashSet<IsoObject>();
@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -3,7 +3,8 @@
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
<Files>
<File FileName="Assets/IsoTools/Scripts/IsoCollision.cs" Line="20" Column="24" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="14" Column="25" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="535" Column="39" />
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="234" Column="17" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>