world refactor and new sort end

This commit is contained in:
2015-02-19 23:27:10 +06:00
parent d3d7792aa3
commit 71b781d0de
6 changed files with 1058 additions and 1063 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -8,11 +8,13 @@ namespace IsoTools {
[ExecuteInEditMode]
public class IsoObject : MonoBehaviour {
#if UNITY_EDITOR
Vector2 _lastTransform = Vector2.zero;
Vector3 _lastPosition = Vector3.zero;
Vector3 _lastSize = Vector3.zero;
bool _lastSorting = false;
bool _lastAlignment = false;
#endif
[SerializeField]
Vector3 _position = Vector3.zero;
@@ -105,11 +107,13 @@ namespace IsoTools {
}
void FixLastProperties() {
#if UNITY_EDITOR
_lastTransform = transform.position;
_lastPosition = Position;
_lastSize = Size;
_lastSorting = Sorting;
_lastAlignment = Alignment;
#endif
}
void MartDirtyIsoWorld() {
@@ -138,9 +142,8 @@ namespace IsoTools {
#if UNITY_EDITOR
void Update() {
if ( Application.isEditor ) {
var trans_pos = transform.position;
if ( !Mathf.Approximately(_lastTransform.x, trans_pos.x) ||
!Mathf.Approximately(_lastTransform.y, trans_pos.y) )
if ( !Mathf.Approximately(_lastTransform.x, transform.position.x) ||
!Mathf.Approximately(_lastTransform.y, transform.position.y) )
{
FixIsoPosition();
}

View File

@@ -118,7 +118,7 @@ namespace IsoTools {
pos.x,
pos.y + pos.z) * TileSize;
default:
throw new UnityException("IsoWorld. Type is wrong!");
throw new UnityException("IsoWorld. TileType is wrong!");
}
}
@@ -142,7 +142,7 @@ namespace IsoTools {
pos.y,
0.0f) / TileSize;
default:
throw new UnityException("IsoWorld. Type is wrong!");
throw new UnityException("IsoWorld. TileType is wrong!");
}
}
@@ -167,7 +167,7 @@ namespace IsoTools {
return iso_pos;
}
default:
throw new UnityException("IsoWorld. Type is wrong!");
throw new UnityException("IsoWorld. TileType is wrong!");
}
}
@@ -187,6 +187,20 @@ namespace IsoTools {
_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() {
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
var objects = new List<ObjectInfo>(iso_objects.Length);
@@ -201,18 +215,11 @@ namespace IsoTools {
foreach ( var obj_a in objects ) {
obj_a.Reset(depends.Count);
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 ) {
var obj_bo = objects[i].IsoObject;
if ( obj_ao != obj_bo ) {
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 ) {
depends.Add(i);
++obj_a.EndDepend;
}
}
if ( IsDepends(obj_ao, obj_bo) ) {
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) {
var min_depth = float.MinValue;
foreach ( var obj_b in objects ) {
@@ -270,8 +263,8 @@ namespace IsoTools {
}
void PlaceObject(IsoObject obj, float depth) {
var pos = obj.gameObject.transform.position;
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
var trans = obj.gameObject.transform;
trans.position = new Vector3(trans.position.x, trans.position.y, 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 ) {
var objects = ScanObjects().Where(p => p.IsoObject.Sorting).ToList();
if ( _dirty ) {
@@ -318,7 +311,7 @@ namespace IsoTools {
if ( !Mathf.Approximately(_lastMinDepth, _minDepth) ) MinDepth = _minDepth;
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth) ) MaxDepth = _maxDepth;
}
SmartSort();
StepSort();
}
void OnEnable() {

View File

@@ -17,7 +17,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

@@ -17,7 +17,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

@@ -1,10 +1,9 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoObject.cs">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
<Files>
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="22" Column="21" />
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="126" Column="9" />
<File FileName="Assets/IsoTools/Examples/Scripts/IsoAutoController.cs" Line="13" Column="28" />
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="139" Column="24" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="321" Column="21" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>