Editor alignment objects

This commit is contained in:
2015-01-04 00:49:11 +06:00
parent 510bcc5834
commit b7f057a00d
10 changed files with 16412 additions and 17899 deletions

View File

@@ -40,8 +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:
Size: {x: 1, y: 3, z: 1} position: {x: 0, y: 0, z: 0}
Position: {x: 0, y: 0, z: 0} size: {x: 1, y: 3, z: 1}
alignment: 1
--- !u!212 &21224792 --- !u!212 &21224792
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

View File

@@ -40,8 +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:
Size: {x: 3, y: 1, z: 1} position: {x: 0, y: 0, z: 0}
Position: {x: 0, y: -2, z: 0} size: {x: 3, y: 1, z: 1}
alignment: 1
--- !u!212 &21281704 --- !u!212 &21281704
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1

16327
Assets/Scenes/Scene1.unity Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: ba348dbd0a176644f8cd7d75e22ebc66
DefaultImporter:
userData:

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,75 @@
using UnityEngine; using UnityEngine;
using UnityEditor;
using System.Collections; using System.Collections;
[ExecuteInEditMode] [ExecuteInEditMode]
public class IsoObject : MonoBehaviour { public class IsoObject : MonoBehaviour {
public Vector3 Size = Vector3.one; [SerializeField]
public Vector3 Position = Vector3.zero; private Vector3 position = Vector3.zero;
public Vector3 Position
void Start () { {
get { return position; }
set {
position = value;
FixTransform();
}
} }
void Update () { [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();
}
}
void Start() {
}
void Update() {
if ( Selection.Contains(gameObject) ) {
FixIsoPosition();
} else {
FixTransform();
}
}
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);
}
}
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);
}
} }
} }

View File

@@ -79,9 +79,8 @@ public class IsoWorld : MonoBehaviour {
} }
void _placeObject(IsoObject obj, float depth) { void _placeObject(IsoObject obj, float depth) {
Vector3 pos = IsoToScreen(obj.Position); var pos = obj.gameObject.transform.position;
pos.z = depth; obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
obj.gameObject.transform.position = pos;
} }
void _placeObject(ObjectInfo info, ref float depth) { void _placeObject(ObjectInfo info, ref float depth) {
@@ -98,12 +97,6 @@ public class IsoWorld : MonoBehaviour {
} }
void Start () { void Start () {
if ( Application.isPlaying ) {
Debug.Log("Application!");
}
if ( Application.isEditor ) {
Debug.Log("Editor!");
}
} }
void Update () { void Update () {

View File

@@ -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

View File

@@ -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

View File

@@ -1,10 +1,9 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoWorld.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoObject.cs">
<Files> <Files>
<File FileName="Assets\Scripts\IsoWorld.cs" Line="56" Column="15" /> <File FileName="Assets\Scripts\IsoObject.cs" Line="74" Column="3" />
<File FileName="Assets\Scripts\IsoObject.cs" Line="16" Column="1" /> <File FileName="Assets\Scripts\IsoWorld.cs" Line="100" Column="3" />
<File FileName="Assets\Scripts\IsoController.cs" Line="23" Column="5" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>