mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
remove Sorting flag.
alignment for all from separate window.
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Assets\IsoTools\Editor\IsoAlignmentWindow.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Assets\IsoTools\Editor\IsoAlignmentWindow.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||||
|
|||||||
39
Assets/IsoTools/Editor/IsoAlignmentWindow.cs
Normal file
39
Assets/IsoTools/Editor/IsoAlignmentWindow.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace IsoTools {
|
||||||
|
public class IsoAlignmentWindow : EditorWindow {
|
||||||
|
|
||||||
|
public static bool Alignment { get; private set; }
|
||||||
|
|
||||||
|
void AlignmentSelection() {
|
||||||
|
var iso_objects = Selection.gameObjects
|
||||||
|
.Where(p => p.GetComponent<IsoObject>())
|
||||||
|
.Select(p => p.GetComponent<IsoObject>());
|
||||||
|
foreach ( var iso_object in iso_objects ) {
|
||||||
|
iso_object.Position = iso_object.TilePosition;
|
||||||
|
iso_object.FixTransform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem("IsoTools/Alignment")]
|
||||||
|
static void Init() {
|
||||||
|
var window = EditorWindow.GetWindow<IsoAlignmentWindow>();
|
||||||
|
window.title = "IsoAlignment";
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
static IsoAlignmentWindow() {
|
||||||
|
Alignment = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGUI() {
|
||||||
|
GUILayout.Space(5);
|
||||||
|
Alignment = EditorGUILayout.Toggle("Auto alignment", Alignment);
|
||||||
|
if ( GUILayout.Button("Alignment selection objects") || Alignment ) {
|
||||||
|
AlignmentSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/IsoTools/Editor/IsoAlignmentWindow.cs.meta
Normal file
12
Assets/IsoTools/Editor/IsoAlignmentWindow.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bc6645583f19a4c99b26459ef98d0d9c
|
||||||
|
timeCreated: 1431871954
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -26,6 +26,13 @@ namespace IsoTools {
|
|||||||
}) / _positions.Count;
|
}) / _positions.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AlignmentIsoObject(IsoObject iso_object) {
|
||||||
|
if ( IsoAlignmentWindow.Alignment ) {
|
||||||
|
iso_object.Position = iso_object.TilePosition;
|
||||||
|
iso_object.FixTransform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float ZMoveIsoObjects(float delta) {
|
float ZMoveIsoObjects(float delta) {
|
||||||
Undo.RecordObjects(_iso_zpositions.Keys.ToArray(), "Move");
|
Undo.RecordObjects(_iso_zpositions.Keys.ToArray(), "Move");
|
||||||
return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => {
|
return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => {
|
||||||
@@ -33,6 +40,7 @@ namespace IsoTools {
|
|||||||
var iso_orig_z = pair.Value;
|
var iso_orig_z = pair.Value;
|
||||||
iso_object.PositionZ = iso_orig_z + delta;
|
iso_object.PositionZ = iso_orig_z + delta;
|
||||||
iso_object.FixTransform();
|
iso_object.FixTransform();
|
||||||
|
AlignmentIsoObject(iso_object);
|
||||||
var z_delta = iso_object.Position.z - iso_orig_z;
|
var z_delta = iso_object.Position.z - iso_orig_z;
|
||||||
return Mathf.Abs(z_delta) > Mathf.Abs(AccIn) ? z_delta : AccIn;
|
return Mathf.Abs(z_delta) > Mathf.Abs(AccIn) ? z_delta : AccIn;
|
||||||
});
|
});
|
||||||
@@ -45,6 +53,7 @@ namespace IsoTools {
|
|||||||
var iso_orig_p = pair.Value;
|
var iso_orig_p = pair.Value;
|
||||||
iso_object.transform.position = iso_orig_p + delta;
|
iso_object.transform.position = iso_orig_p + delta;
|
||||||
iso_object.FixIsoPosition();
|
iso_object.FixIsoPosition();
|
||||||
|
AlignmentIsoObject(iso_object);
|
||||||
var pos_delta = iso_object.transform.position - iso_orig_p;
|
var pos_delta = iso_object.transform.position - iso_orig_p;
|
||||||
return pos_delta.magnitude > AccIn.magnitude ? pos_delta : AccIn;
|
return pos_delta.magnitude > AccIn.magnitude ? pos_delta : AccIn;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ namespace IsoTools {
|
|||||||
Vector2 _lastTransform = Vector2.zero;
|
Vector2 _lastTransform = Vector2.zero;
|
||||||
Vector3 _lastPosition = Vector3.zero;
|
Vector3 _lastPosition = Vector3.zero;
|
||||||
Vector3 _lastSize = Vector3.zero;
|
Vector3 _lastSize = Vector3.zero;
|
||||||
bool _lastSorting = false;
|
|
||||||
bool _lastAlignment = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -76,28 +74,6 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
bool _sorting = true;
|
|
||||||
/// <summary>Auto sorting tile.</summary>
|
|
||||||
public bool Sorting {
|
|
||||||
get { return _sorting; }
|
|
||||||
set {
|
|
||||||
_sorting = value;
|
|
||||||
FixTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
bool _alignment = true;
|
|
||||||
/// <summary>Auto alignment position by isometric tile size.</summary>
|
|
||||||
public bool Alignment {
|
|
||||||
get { return _alignment; }
|
|
||||||
set {
|
|
||||||
_alignment = value;
|
|
||||||
FixTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
/// <summary>Isometric object tile position.</summary>
|
/// <summary>Isometric object tile position.</summary>
|
||||||
public Vector3 TilePosition {
|
public Vector3 TilePosition {
|
||||||
@@ -128,9 +104,6 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void FixTransform() {
|
public void FixTransform() {
|
||||||
if ( Application.isEditor && Alignment ) {
|
|
||||||
_position = TilePosition;
|
|
||||||
}
|
|
||||||
Vector3 trans = IsoWorld.IsoToScreen(Position);
|
Vector3 trans = IsoWorld.IsoToScreen(Position);
|
||||||
trans.z = transform.position.z;
|
trans.z = transform.position.z;
|
||||||
transform.position = trans;
|
transform.position = trans;
|
||||||
@@ -149,8 +122,6 @@ namespace IsoTools {
|
|||||||
_lastTransform = transform.position;
|
_lastTransform = transform.position;
|
||||||
_lastPosition = Position;
|
_lastPosition = Position;
|
||||||
_lastSize = Size;
|
_lastSize = Size;
|
||||||
_lastSorting = Sorting;
|
|
||||||
_lastAlignment = Alignment;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,10 +158,8 @@ namespace IsoTools {
|
|||||||
{
|
{
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
}
|
}
|
||||||
if ( _lastPosition != _position ) Position = _position;
|
if ( _lastPosition != _position ) Position = _position;
|
||||||
if ( _lastSize != _size ) Size = _size;
|
if ( _lastSize != _size ) Size = _size;
|
||||||
if ( _lastSorting != _sorting ) Sorting = _sorting;
|
|
||||||
if ( _lastAlignment != _alignment ) Alignment = _alignment;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace IsoTools {
|
|||||||
/// <param name="obj">Isometric object for resorting.</param>
|
/// <param name="obj">Isometric object for resorting.</param>
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
public void MarkDirty(IsoObject obj) {
|
public void MarkDirty(IsoObject obj) {
|
||||||
if ( obj && obj.Sorting ) {
|
if ( obj ) {
|
||||||
var renderer = obj.GetComponent<Renderer>();
|
var renderer = obj.GetComponent<Renderer>();
|
||||||
if ( renderer && renderer.isVisible ) {
|
if ( renderer && renderer.isVisible ) {
|
||||||
MarkDirty();
|
MarkDirty();
|
||||||
|
|||||||
@@ -23,7 +23,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
|
||||||
|
|||||||
@@ -23,7 +23,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
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Editor/IsoObjectEditor.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/Editor/IsoObjectEditor.cs" Line="106" Column="25" />
|
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="1" 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