mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
edit iso position from inspector.
move iso object from editor with z
This commit is contained in:
@@ -40,9 +40,9 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
position: {x: 0, y: 0, z: 0}
|
_position: {x: 0, y: 0, z: 0}
|
||||||
size: {x: 1, y: 3, z: 1}
|
_size: {x: 1, y: 3, z: 1}
|
||||||
alignment: 1
|
_alignment: 1
|
||||||
--- !u!212 &21224792
|
--- !u!212 &21224792
|
||||||
SpriteRenderer:
|
SpriteRenderer:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
position: {x: 0, y: 0, z: 0}
|
_position: {x: 0, y: 0, z: 0}
|
||||||
size: {x: 3, y: 1, z: 1}
|
_size: {x: 3, y: 1, z: 1}
|
||||||
alignment: 1
|
_alignment: 1
|
||||||
--- !u!212 &21281704
|
--- !u!212 &21281704
|
||||||
SpriteRenderer:
|
SpriteRenderer:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,42 +6,31 @@ using System.Collections;
|
|||||||
public class IsoObject : MonoBehaviour {
|
public class IsoObject : MonoBehaviour {
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Vector3 position = Vector3.zero;
|
private Vector3 _position = Vector3.zero;
|
||||||
public Vector3 Position
|
private Vector3 _lastPosition = Vector3.zero;
|
||||||
{
|
public Vector3 Position {
|
||||||
get { return position; }
|
get { return _position; }
|
||||||
set {
|
set {
|
||||||
position = value;
|
if ( Alignment ) {
|
||||||
|
_position.Set(Mathf.Round(value.x), Mathf.Round(value.y), value.z);
|
||||||
|
} else {
|
||||||
|
_position = value;
|
||||||
|
}
|
||||||
|
_lastPosition = _position;
|
||||||
FixTransform();
|
FixTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
public Vector3 Size = Vector3.one;
|
||||||
private Vector3 size = Vector3.one;
|
public bool Alignment = true;
|
||||||
public Vector3 Size
|
|
||||||
{
|
|
||||||
get { return size; }
|
|
||||||
set {
|
|
||||||
size = value;
|
|
||||||
FixTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private bool alignment = true;
|
|
||||||
public bool Alignment
|
|
||||||
{
|
|
||||||
get { return alignment; }
|
|
||||||
set {
|
|
||||||
alignment = value;
|
|
||||||
FixTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
|
if ( _lastPosition != _position ) {
|
||||||
|
Position = _position;
|
||||||
|
}
|
||||||
if ( Selection.Contains(gameObject) ) {
|
if ( Selection.Contains(gameObject) ) {
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
} else {
|
} else {
|
||||||
@@ -51,25 +40,21 @@ public class IsoObject : MonoBehaviour {
|
|||||||
|
|
||||||
void FixTransform() {
|
void FixTransform() {
|
||||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
if ( iso_world ) {
|
if ( !iso_world ) {
|
||||||
if ( Alignment ) {
|
return;
|
||||||
position = new Vector3(
|
|
||||||
Mathf.Round(Position.x),
|
|
||||||
Mathf.Round(Position.y),
|
|
||||||
Position.z);
|
|
||||||
}
|
}
|
||||||
var pos = iso_world.IsoToScreen(Position);
|
var pos = iso_world.IsoToScreen(Position);
|
||||||
var depth = gameObject.transform.position.z;
|
var depth = gameObject.transform.position.z;
|
||||||
gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void FixIsoPosition() {
|
void FixIsoPosition() {
|
||||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
if ( iso_world ) {
|
if ( !iso_world ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var pos = gameObject.transform.position;
|
var pos = gameObject.transform.position;
|
||||||
Position = iso_world.ScreenToIso(new Vector2(pos.x, pos.y));
|
Position = iso_world.ScreenToIso(new Vector2(pos.x, pos.y), Position.z);
|
||||||
EditorUtility.SetDirty(this);
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,12 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
0.0f) / TileSize;
|
0.0f) / TileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
|
||||||
|
var iso_pos = ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize));
|
||||||
|
iso_pos.z = iso_z;
|
||||||
|
return iso_pos;
|
||||||
|
}
|
||||||
|
|
||||||
void _scanObjects() {
|
void _scanObjects() {
|
||||||
_objects.Clear();
|
_objects.Clear();
|
||||||
IsoObject[] iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
IsoObject[] iso_objects = GameObject.FindObjectsOfType<IsoObject>();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoObject.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoWorld.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="74" Column="3" />
|
<File FileName="Assets\Scripts\IsoWorld.cs" Line="29" Column="2" />
|
||||||
<File FileName="Assets\Scripts\IsoWorld.cs" Line="100" Column="3" />
|
<File FileName="Assets\Scripts\IsoObject.cs" Line="57" Column="1" />
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user