mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
first frame bounds3d fix
This commit is contained in:
@@ -208,20 +208,24 @@ namespace IsoTools {
|
|||||||
IsoWorld _isoWorld = null;
|
IsoWorld _isoWorld = null;
|
||||||
public IsoWorld isoWorld {
|
public IsoWorld isoWorld {
|
||||||
get {
|
get {
|
||||||
if ( !_isoWorld ) {
|
if ( (object)_isoWorld == null ) {
|
||||||
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
|
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
}
|
}
|
||||||
return _isoWorld;
|
return _isoWorld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetWorld() {
|
||||||
|
_isoWorld = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void FixTransform() {
|
public void FixTransform() {
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if ( !Application.isPlaying && isAlignment ) {
|
if ( !Application.isPlaying && isAlignment ) {
|
||||||
_position = tilePosition;
|
_position = tilePosition;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ( isoWorld ) {
|
if ( (object)isoWorld != null ) {
|
||||||
transform.position = IsoUtils.Vec3ChangeZ(
|
transform.position = IsoUtils.Vec3ChangeZ(
|
||||||
isoWorld.IsoToScreen(position),
|
isoWorld.IsoToScreen(position),
|
||||||
transform.position.z);
|
transform.position.z);
|
||||||
@@ -231,7 +235,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void FixIsoPosition() {
|
public void FixIsoPosition() {
|
||||||
if ( isoWorld ) {
|
if ( (object)isoWorld != null ) {
|
||||||
position = isoWorld.ScreenToIso(
|
position = isoWorld.ScreenToIso(
|
||||||
transform.position,
|
transform.position,
|
||||||
positionZ);
|
positionZ);
|
||||||
@@ -247,7 +251,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MartDirtyIsoWorld() {
|
void MartDirtyIsoWorld() {
|
||||||
if ( isoWorld ) {
|
if ( (object)isoWorld != null ) {
|
||||||
isoWorld.MarkDirty(this);
|
isoWorld.MarkDirty(this);
|
||||||
}
|
}
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
@@ -262,23 +266,23 @@ namespace IsoTools {
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
Internal.SelfDepends = new HashSet<IsoObject>(new IsoObject[19]);
|
Internal.SelfDepends = new HashSet<IsoObject>(new IsoObject[47]);
|
||||||
Internal.SelfDepends.Clear();
|
Internal.SelfDepends.Clear();
|
||||||
Internal.TheirDepends = new HashSet<IsoObject>(new IsoObject[19]);
|
Internal.TheirDepends = new HashSet<IsoObject>(new IsoObject[47]);
|
||||||
Internal.TheirDepends.Clear();
|
Internal.TheirDepends.Clear();
|
||||||
FixLastProperties();
|
FixLastProperties();
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
if ( isoWorld ) {
|
if ( (object)isoWorld != null ) {
|
||||||
isoWorld.AddIsoObject(this);
|
isoWorld.AddIsoObject(this);
|
||||||
}
|
}
|
||||||
MartDirtyIsoWorld();
|
MartDirtyIsoWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable() {
|
void OnDisable() {
|
||||||
if ( isoWorld ) {
|
if ( (object)isoWorld != null ) {
|
||||||
isoWorld.RemoveIsoObject(this);
|
isoWorld.RemoveIsoObject(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,7 +299,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmos() {
|
void OnDrawGizmos() {
|
||||||
if ( isShowBounds && isoWorld ) {
|
if ( isShowBounds && (object)isoWorld != null ) {
|
||||||
IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red);
|
IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace IsoTools {
|
|||||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||||
public class IsoWorld : MonoBehaviour {
|
public class IsoWorld : MonoBehaviour {
|
||||||
|
|
||||||
bool _dirty = true;
|
bool _dirty = false;
|
||||||
HashSet<IsoObject> _objects = new HashSet<IsoObject>();
|
HashSet<IsoObject> _objects = new HashSet<IsoObject>();
|
||||||
HashSet<IsoObject> _visibles = new HashSet<IsoObject>();
|
HashSet<IsoObject> _visibles = new HashSet<IsoObject>();
|
||||||
HashSet<IsoObject> _oldVisibles = new HashSet<IsoObject>();
|
HashSet<IsoObject> _oldVisibles = new HashSet<IsoObject>();
|
||||||
@@ -129,7 +129,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void MarkDirty(IsoObject iso_object) {
|
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;
|
iso_object.Internal.Dirty = true;
|
||||||
MarkDirty();
|
MarkDirty();
|
||||||
}
|
}
|
||||||
@@ -163,6 +163,13 @@ namespace IsoTools {
|
|||||||
_isoRMatrix = _isoMatrix.inverse;
|
_isoRMatrix = _isoMatrix.inverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResetAllWorlds() {
|
||||||
|
var objects_iter = _objects.GetEnumerator();
|
||||||
|
while ( objects_iter.MoveNext() ) {
|
||||||
|
objects_iter.Current.ResetWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FixAllTransforms() {
|
void FixAllTransforms() {
|
||||||
var objects_iter = _objects.GetEnumerator();
|
var objects_iter = _objects.GetEnumerator();
|
||||||
while ( objects_iter.MoveNext() ) {
|
while ( objects_iter.MoveNext() ) {
|
||||||
@@ -176,7 +183,7 @@ namespace IsoTools {
|
|||||||
FixAllTransforms();
|
FixAllTransforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckIsoObjectChangeBounds3d(IsoObject iso_object) {
|
bool UpdateIsoObjectBounds3d(IsoObject iso_object) {
|
||||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
||||||
var bounds3d = IsoObject3DBounds(iso_object);
|
var bounds3d = IsoObject3DBounds(iso_object);
|
||||||
var offset3d = iso_object.transform.position.z - bounds3d.center.z;
|
var offset3d = iso_object.transform.position.z - bounds3d.center.z;
|
||||||
@@ -455,20 +462,13 @@ namespace IsoTools {
|
|||||||
while ( visibles_iter.MoveNext() ) {
|
while ( visibles_iter.MoveNext() ) {
|
||||||
var iso_object = visibles_iter.Current;
|
var iso_object = visibles_iter.Current;
|
||||||
if ( iso_object.Internal.Dirty || !_oldVisibles.Contains(iso_object) ) {
|
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();
|
MarkDirty();
|
||||||
SetupIsoObjectDepends(iso_object);
|
SetupIsoObjectDepends(iso_object);
|
||||||
iso_object.Internal.Dirty = false;
|
iso_object.Internal.Dirty = false;
|
||||||
}
|
}
|
||||||
|
if ( UpdateIsoObjectBounds3d(iso_object) ) {
|
||||||
|
MarkDirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var old_visibles_iter = _oldVisibles.GetEnumerator();
|
var old_visibles_iter = _oldVisibles.GetEnumerator();
|
||||||
@@ -484,7 +484,10 @@ namespace IsoTools {
|
|||||||
void ClearIsoObjectDepends(IsoObject iso_object) {
|
void ClearIsoObjectDepends(IsoObject iso_object) {
|
||||||
var their_depends_iter = iso_object.Internal.TheirDepends.GetEnumerator();
|
var their_depends_iter = iso_object.Internal.TheirDepends.GetEnumerator();
|
||||||
while ( their_depends_iter.MoveNext() ) {
|
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.SelfDepends.Clear();
|
||||||
iso_object.Internal.TheirDepends.Clear();
|
iso_object.Internal.TheirDepends.Clear();
|
||||||
@@ -560,6 +563,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable() {
|
void OnDisable() {
|
||||||
|
ResetAllWorlds();
|
||||||
_objects.Clear();
|
_objects.Clear();
|
||||||
_visibles.Clear();
|
_visibles.Clear();
|
||||||
_sectors.Clear();
|
_sectors.Clear();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(MonoDevelopProperties) = preSolution
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
StartupItem = Assembly-CSharp.csproj
|
StartupItem = Assembly-CSharp.csproj
|
||||||
Policies = $0
|
Policies = $0
|
||||||
$0.TextStylePolicy = $1
|
$0.TextStylePolicy = $1
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoCollision.cs" Line="20" Column="24" />
|
<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>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user