edit iso position from inspector.

move iso object from editor with z
This commit is contained in:
2015-01-04 02:27:38 +06:00
parent b7f057a00d
commit dd401d555d
8 changed files with 16266 additions and 56 deletions

View File

@@ -40,9 +40,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
m_Name:
m_EditorClassIdentifier:
position: {x: 0, y: 0, z: 0}
size: {x: 1, y: 3, z: 1}
alignment: 1
_position: {x: 0, y: 0, z: 0}
_size: {x: 1, y: 3, z: 1}
_alignment: 1
--- !u!212 &21224792
SpriteRenderer:
m_ObjectHideFlags: 1

View File

@@ -40,9 +40,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
m_Name:
m_EditorClassIdentifier:
position: {x: 0, y: 0, z: 0}
size: {x: 3, y: 1, z: 1}
alignment: 1
_position: {x: 0, y: 0, z: 0}
_size: {x: 3, y: 1, z: 1}
_alignment: 1
--- !u!212 &21281704
SpriteRenderer:
m_ObjectHideFlags: 1

File diff suppressed because it is too large Load Diff

View File

@@ -6,42 +6,31 @@ using System.Collections;
public class IsoObject : MonoBehaviour {
[SerializeField]
private Vector3 position = Vector3.zero;
public Vector3 Position
{
get { return position; }
private Vector3 _position = Vector3.zero;
private Vector3 _lastPosition = Vector3.zero;
public Vector3 Position {
get { return _position; }
set {
position = value;
if ( Alignment ) {
_position.Set(Mathf.Round(value.x), Mathf.Round(value.y), value.z);
} else {
_position = value;
}
_lastPosition = _position;
FixTransform();
}
}
[SerializeField]
private Vector3 size = Vector3.one;
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();
}
}
public Vector3 Size = Vector3.one;
public bool Alignment = true;
void Start() {
}
void Update() {
if ( _lastPosition != _position ) {
Position = _position;
}
if ( Selection.Contains(gameObject) ) {
FixIsoPosition();
} else {
@@ -51,25 +40,21 @@ public class IsoObject : MonoBehaviour {
void FixTransform() {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
if ( iso_world ) {
if ( Alignment ) {
position = new Vector3(
Mathf.Round(Position.x),
Mathf.Round(Position.y),
Position.z);
}
var pos = iso_world.IsoToScreen(Position);
var depth = gameObject.transform.position.z;
gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
if ( !iso_world ) {
return;
}
var pos = iso_world.IsoToScreen(Position);
var depth = gameObject.transform.position.z;
gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
}
void FixIsoPosition() {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
if ( iso_world ) {
var pos = gameObject.transform.position;
Position = iso_world.ScreenToIso(new Vector2(pos.x, pos.y));
EditorUtility.SetDirty(this);
if ( !iso_world ) {
return;
}
var pos = gameObject.transform.position;
Position = iso_world.ScreenToIso(new Vector2(pos.x, pos.y), Position.z);
EditorUtility.SetDirty(this);
}
}

View File

@@ -40,6 +40,12 @@ public class IsoWorld : MonoBehaviour {
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() {
_objects.Clear();
IsoObject[] iso_objects = GameObject.FindObjectsOfType<IsoObject>();

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,9 +1,9 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoObject.cs">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoWorld.cs">
<Files>
<File FileName="Assets\Scripts\IsoObject.cs" Line="74" Column="3" />
<File FileName="Assets\Scripts\IsoWorld.cs" Line="100" Column="3" />
<File FileName="Assets\Scripts\IsoWorld.cs" Line="29" Column="2" />
<File FileName="Assets\Scripts\IsoObject.cs" Line="57" Column="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>