mini iso object refactor

This commit is contained in:
2015-02-17 23:49:18 +06:00
parent de2271c0b2
commit 568c5489a0
5 changed files with 65 additions and 71 deletions

View File

@@ -163,7 +163,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.50000024
value: 93.75
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -294,8 +294,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
TileType: 0
TileSize: 16
StartDepth: 0
StepDepth: .100000001
MinDepth: 0
MaxDepth: 100
--- !u!1001 &300381428
Prefab:
m_ObjectHideFlags: 0
@@ -309,11 +309,11 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.y
value: -24
value: -8
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.z
value: 0
value: 12.5
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.x
@@ -337,11 +337,11 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.x
value: -1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.y
value: -2
value: -1
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _alignment
@@ -375,7 +375,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: .900000095
value: 87.5
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -395,7 +395,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 8
value: 9
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -429,7 +429,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.30000019
value: 81.25
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -449,7 +449,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 12
value: 13
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -483,7 +483,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.40000021
value: 75
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -503,7 +503,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 13
value: 15
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -537,7 +537,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalPosition.z
value: .400000006
value: 28.125
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalRotation.x
@@ -557,7 +557,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_RootOrder
value: 3
value: 4
objectReference: {fileID: 0}
- target: {fileID: 11453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: _position.x
@@ -587,7 +587,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.10000014
value: 68.75
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -607,7 +607,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 10
value: 11
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -641,7 +641,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.z
value: .5
value: 62.5
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.x
@@ -661,7 +661,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_RootOrder
value: 2
value: 3
objectReference: {fileID: 0}
- target: {fileID: 11453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: _position.x
@@ -691,7 +691,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.z
value: .300000012
value: 56.25
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.x
@@ -711,7 +711,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_RootOrder
value: 1
value: 2
objectReference: {fileID: 0}
- target: {fileID: 11453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: _position.x
@@ -745,7 +745,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalPosition.z
value: .600000024
value: 50
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalRotation.x
@@ -765,7 +765,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_RootOrder
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 11463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: _position.x
@@ -795,7 +795,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.20000017
value: 43.75
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -815,7 +815,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 11
value: 12
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -849,7 +849,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: 1.00000012
value: 37.5
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -869,7 +869,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 9
value: 10
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -903,7 +903,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: .700000048
value: 31.25
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -923,7 +923,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 6
value: 7
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -957,7 +957,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalPosition.z
value: .200000003
value: 18.75
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalRotation.x
@@ -1007,7 +1007,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalPosition.z
value: .800000072
value: 25
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_LocalRotation.x
@@ -1027,7 +1027,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: m_RootOrder
value: 7
value: 8
objectReference: {fileID: 0}
- target: {fileID: 11418276, guid: 31944869327494e44ad0bf31bbbaa122, type: 2}
propertyPath: _position.x
@@ -1061,7 +1061,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.z
value: .100000001
value: 6.25
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.x

View File

@@ -7,8 +7,7 @@ using UnityEditor;
namespace IsoTools {
[ExecuteInEditMode]
public class IsoObject : MonoBehaviour {
Transform _transform = null;
Vector2 _lastTransform = Vector2.zero;
Vector3 _lastPosition = Vector3.zero;
Vector3 _lastSize = Vector3.zero;
@@ -68,20 +67,20 @@ namespace IsoTools {
Mathf.Round(Position.y),
Mathf.Round(Position.z));
}
set {
Position = value;
}
set { Position = value; }
}
IsoWorld _iso_world = null;
public IsoWorld GetIsoWorld() {
if ( !_iso_world ) {
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
public IsoWorld IsoWorld {
get {
if ( !_iso_world ) {
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
}
if ( !_iso_world ) {
throw new UnityException("IsoObject. IsoWorld not found!");
}
return _iso_world;
}
if ( !_iso_world ) {
throw new UnityException("IsoObject. IsoWorld not found!");
}
return _iso_world;
}
public void ResetIsoWorld() {
@@ -92,27 +91,21 @@ namespace IsoTools {
if ( Application.isEditor && Alignment ) {
_position = TilePosition;
}
var iso_world = GetIsoWorld();
if ( iso_world && _transform ) {
Vector3 trans = iso_world.IsoToScreen(Position);
trans.z = _transform.position.z;
_transform.position = trans;
FixLastProperties(trans);
}
Vector3 trans = IsoWorld.IsoToScreen(Position);
trans.z = transform.position.z;
transform.position = trans;
FixLastProperties();
MartDirtyIsoWorld();
MarkEditorObjectDirty();
}
public void FixIsoPosition() {
var iso_world = GetIsoWorld();
if ( iso_world && _transform ) {
Vector2 trans = _transform.position;
Position = iso_world.ScreenToIso(trans, Position.z);
}
Vector2 trans = transform.position;
Position = IsoWorld.ScreenToIso(trans, Position.z);
}
void FixLastProperties(Vector3 trans) {
_lastTransform = trans;
void FixLastProperties() {
_lastTransform = transform.position;
_lastPosition = Position;
_lastSize = Size;
_lastSorting = Sorting;
@@ -120,28 +113,29 @@ namespace IsoTools {
}
void MartDirtyIsoWorld() {
var iso_world = GetIsoWorld();
if ( iso_world && Sorting ) {
iso_world.MarkDirty(this);
if ( Sorting ) {
IsoWorld.MarkDirty(this);
}
}
void MarkEditorObjectDirty() {
#if UNITY_EDITOR
#if UNITY_EDITOR
if ( Application.isEditor ) {
EditorUtility.SetDirty(this);
}
#endif
#endif
}
void Awake() {
_transform = gameObject.transform;
FixLastProperties(_transform.position);
FixLastProperties();
FixIsoPosition();
}
void Update() {
if ( _lastTransform.x != _transform.position.x || _lastTransform.y != _transform.position.y ) {
var trans_pos = transform.position;
if ( !Mathf.Approximately(_lastTransform.x, trans_pos.x) ||
!Mathf.Approximately(_lastTransform.y, trans_pos.y) )
{
FixIsoPosition();
}
if ( Application.isEditor ) {

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

@@ -2,8 +2,8 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
<Files>
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="127" Column="1" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="271" Column="16" />
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="269" Column="19" />
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="136" Column="34" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>