mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
world refactor and new sort end
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -8,11 +8,13 @@ namespace IsoTools {
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class IsoObject : MonoBehaviour {
|
public class IsoObject : MonoBehaviour {
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
Vector2 _lastTransform = Vector2.zero;
|
Vector2 _lastTransform = Vector2.zero;
|
||||||
Vector3 _lastPosition = Vector3.zero;
|
Vector3 _lastPosition = Vector3.zero;
|
||||||
Vector3 _lastSize = Vector3.zero;
|
Vector3 _lastSize = Vector3.zero;
|
||||||
bool _lastSorting = false;
|
bool _lastSorting = false;
|
||||||
bool _lastAlignment = false;
|
bool _lastAlignment = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Vector3 _position = Vector3.zero;
|
Vector3 _position = Vector3.zero;
|
||||||
@@ -105,11 +107,13 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FixLastProperties() {
|
void FixLastProperties() {
|
||||||
|
#if UNITY_EDITOR
|
||||||
_lastTransform = transform.position;
|
_lastTransform = transform.position;
|
||||||
_lastPosition = Position;
|
_lastPosition = Position;
|
||||||
_lastSize = Size;
|
_lastSize = Size;
|
||||||
_lastSorting = Sorting;
|
_lastSorting = Sorting;
|
||||||
_lastAlignment = Alignment;
|
_lastAlignment = Alignment;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MartDirtyIsoWorld() {
|
void MartDirtyIsoWorld() {
|
||||||
@@ -138,9 +142,8 @@ namespace IsoTools {
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
void Update() {
|
void Update() {
|
||||||
if ( Application.isEditor ) {
|
if ( Application.isEditor ) {
|
||||||
var trans_pos = transform.position;
|
if ( !Mathf.Approximately(_lastTransform.x, transform.position.x) ||
|
||||||
if ( !Mathf.Approximately(_lastTransform.x, trans_pos.x) ||
|
!Mathf.Approximately(_lastTransform.y, transform.position.y) )
|
||||||
!Mathf.Approximately(_lastTransform.y, trans_pos.y) )
|
|
||||||
{
|
{
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace IsoTools {
|
|||||||
pos.x,
|
pos.x,
|
||||||
pos.y + pos.z) * TileSize;
|
pos.y + pos.z) * TileSize;
|
||||||
default:
|
default:
|
||||||
throw new UnityException("IsoWorld. Type is wrong!");
|
throw new UnityException("IsoWorld. TileType is wrong!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ namespace IsoTools {
|
|||||||
pos.y,
|
pos.y,
|
||||||
0.0f) / TileSize;
|
0.0f) / TileSize;
|
||||||
default:
|
default:
|
||||||
throw new UnityException("IsoWorld. Type is wrong!");
|
throw new UnityException("IsoWorld. TileType is wrong!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ namespace IsoTools {
|
|||||||
return iso_pos;
|
return iso_pos;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new UnityException("IsoWorld. Type is wrong!");
|
throw new UnityException("IsoWorld. TileType is wrong!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +186,20 @@ namespace IsoTools {
|
|||||||
_lastMinDepth = MinDepth;
|
_lastMinDepth = MinDepth;
|
||||||
_lastMaxDepth = MaxDepth;
|
_lastMaxDepth = MaxDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDepends(IsoObject obj_ao, IsoObject obj_bo) {
|
||||||
|
if ( obj_ao != obj_bo ) {
|
||||||
|
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
||||||
|
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
||||||
|
if ( obj_bo.Position.x < max_ax && obj_bo.Position.y < max_ay ) {
|
||||||
|
var max_bz = obj_bo.Position.z + obj_bo.Size.z;
|
||||||
|
if ( obj_ao.Position.z < max_bz ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IList<ObjectInfo> ScanObjects() {
|
IList<ObjectInfo> ScanObjects() {
|
||||||
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
||||||
@@ -201,18 +215,11 @@ namespace IsoTools {
|
|||||||
foreach ( var obj_a in objects ) {
|
foreach ( var obj_a in objects ) {
|
||||||
obj_a.Reset(depends.Count);
|
obj_a.Reset(depends.Count);
|
||||||
var obj_ao = obj_a.IsoObject;
|
var obj_ao = obj_a.IsoObject;
|
||||||
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
|
||||||
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
|
||||||
for ( int i = 0; i < objects.Count; ++i ) {
|
for ( int i = 0; i < objects.Count; ++i ) {
|
||||||
var obj_bo = objects[i].IsoObject;
|
var obj_bo = objects[i].IsoObject;
|
||||||
if ( obj_ao != obj_bo ) {
|
if ( IsDepends(obj_ao, obj_bo) ) {
|
||||||
if ( obj_bo.Position.x < max_ax && obj_bo.Position.y < max_ay ) {
|
depends.Add(i);
|
||||||
var max_bz = obj_bo.Position.z + obj_bo.Size.z;
|
++obj_a.EndDepend;
|
||||||
if ( obj_ao.Position.z < max_bz ) {
|
|
||||||
depends.Add(i);
|
|
||||||
++obj_a.EndDepend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,20 +234,6 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDepends(IsoObject obj_ao, IsoObject obj_bo) {
|
|
||||||
if ( obj_ao != obj_bo ) {
|
|
||||||
var max_ax = obj_ao.Position.x + obj_ao.Size.x;
|
|
||||||
var max_ay = obj_ao.Position.y + obj_ao.Size.y;
|
|
||||||
if ( obj_bo.Position.x < max_ax && obj_bo.Position.y < max_ay ) {
|
|
||||||
var max_bz = obj_bo.Position.z + obj_bo.Size.z;
|
|
||||||
if ( obj_ao.Position.z < max_bz ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ManualSort(IsoObject obj, IList<ObjectInfo> objects) {
|
void ManualSort(IsoObject obj, IList<ObjectInfo> objects) {
|
||||||
var min_depth = float.MinValue;
|
var min_depth = float.MinValue;
|
||||||
foreach ( var obj_b in objects ) {
|
foreach ( var obj_b in objects ) {
|
||||||
@@ -270,8 +263,8 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlaceObject(IsoObject obj, float depth) {
|
void PlaceObject(IsoObject obj, float depth) {
|
||||||
var pos = obj.gameObject.transform.position;
|
var trans = obj.gameObject.transform;
|
||||||
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
trans.position = new Vector3(trans.position.x, trans.position.y, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaceObject(ObjectInfo info, IList<ObjectInfo> objects, IList<int> depends, ref float depth) {
|
void PlaceObject(ObjectInfo info, IList<ObjectInfo> objects, IList<int> depends, ref float depth) {
|
||||||
@@ -287,7 +280,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartSort() {
|
void StepSort() {
|
||||||
if ( _dirty || _dirtyObjects.Count > 0 ) {
|
if ( _dirty || _dirtyObjects.Count > 0 ) {
|
||||||
var objects = ScanObjects().Where(p => p.IsoObject.Sorting).ToList();
|
var objects = ScanObjects().Where(p => p.IsoObject.Sorting).ToList();
|
||||||
if ( _dirty ) {
|
if ( _dirty ) {
|
||||||
@@ -318,7 +311,7 @@ namespace IsoTools {
|
|||||||
if ( !Mathf.Approximately(_lastMinDepth, _minDepth) ) MinDepth = _minDepth;
|
if ( !Mathf.Approximately(_lastMinDepth, _minDepth) ) MinDepth = _minDepth;
|
||||||
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth) ) MaxDepth = _maxDepth;
|
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth) ) MaxDepth = _maxDepth;
|
||||||
}
|
}
|
||||||
SmartSort();
|
StepSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
|
|||||||
@@ -17,7 +17,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
|
||||||
|
|||||||
@@ -17,7 +17,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
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoObject.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="22" Column="21" />
|
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="139" Column="24" />
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="126" Column="9" />
|
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="321" Column="21" />
|
||||||
<File FileName="Assets/IsoTools/Examples/Scripts/IsoAutoController.cs" Line="13" Column="28" />
|
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user