mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-14 00:40:30 +07:00
Editor alignment objects
This commit is contained in:
@@ -40,8 +40,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
||||
m_Name:
|
||||
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
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
@@ -40,8 +40,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 9a9c584f9a39449438abc7ba59a68778, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Size: {x: 3, y: 1, z: 1}
|
||||
Position: {x: 0, y: -2, z: 0}
|
||||
position: {x: 0, y: 0, z: 0}
|
||||
size: {x: 3, y: 1, z: 1}
|
||||
alignment: 1
|
||||
--- !u!212 &21281704
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
16327
Assets/Scenes/Scene1.unity
Normal file
16327
Assets/Scenes/Scene1.unity
Normal file
File diff suppressed because it is too large
Load Diff
4
Assets/Scenes/Scene1.unity.meta
Normal file
4
Assets/Scenes/Scene1.unity.meta
Normal file
@@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba348dbd0a176644f8cd7d75e22ebc66
|
||||
DefaultImporter:
|
||||
userData:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,75 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class IsoObject : MonoBehaviour {
|
||||
|
||||
public Vector3 Size = Vector3.one;
|
||||
public Vector3 Position = Vector3.zero;
|
||||
|
||||
void Start () {
|
||||
[SerializeField]
|
||||
private Vector3 position = Vector3.zero;
|
||||
public Vector3 Position
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,9 +79,8 @@ public class IsoWorld : MonoBehaviour {
|
||||
}
|
||||
|
||||
void _placeObject(IsoObject obj, float depth) {
|
||||
Vector3 pos = IsoToScreen(obj.Position);
|
||||
pos.z = depth;
|
||||
obj.gameObject.transform.position = pos;
|
||||
var pos = obj.gameObject.transform.position;
|
||||
obj.gameObject.transform.position = new Vector3(pos.x, pos.y, depth);
|
||||
}
|
||||
|
||||
void _placeObject(ObjectInfo info, ref float depth) {
|
||||
@@ -98,12 +97,6 @@ public class IsoWorld : MonoBehaviour {
|
||||
}
|
||||
|
||||
void Start () {
|
||||
if ( Application.isPlaying ) {
|
||||
Debug.Log("Application!");
|
||||
}
|
||||
if ( Application.isEditor ) {
|
||||
Debug.Log("Editor!");
|
||||
}
|
||||
}
|
||||
|
||||
void Update () {
|
||||
@@ -111,4 +104,4 @@ public class IsoWorld : MonoBehaviour {
|
||||
_scanDepends();
|
||||
_manualSort();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoWorld.cs">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\IsoObject.cs">
|
||||
<Files>
|
||||
<File FileName="Assets\Scripts\IsoWorld.cs" Line="56" Column="15" />
|
||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="16" Column="1" />
|
||||
<File FileName="Assets\Scripts\IsoController.cs" Line="23" Column="5" />
|
||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="74" Column="3" />
|
||||
<File FileName="Assets\Scripts\IsoWorld.cs" Line="100" Column="3" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user