mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-16 22:16:55 +07:00
Lazy sorting
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Assets\Scripts\IsoAutoController.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoController.cs" />
|
<Compile Include="Assets\Scripts\IsoController.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Assets\Scripts\IsoAutoController.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoController.cs" />
|
<Compile Include="Assets\Scripts\IsoController.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
||||||
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ MonoBehaviour:
|
|||||||
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
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ MonoBehaviour:
|
|||||||
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
File diff suppressed because it is too large
Load Diff
32
Assets/Scripts/IsoAutoController.cs
Normal file
32
Assets/Scripts/IsoAutoController.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class IsoAutoController : MonoBehaviour {
|
||||||
|
|
||||||
|
public float StepTicks = 0.5f;
|
||||||
|
public float StepRndTicks = 0.5f;
|
||||||
|
|
||||||
|
void Start() {
|
||||||
|
StartCoroutine("Move");
|
||||||
|
}
|
||||||
|
|
||||||
|
WaitForSeconds RndWait() {
|
||||||
|
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks));
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator Move() {
|
||||||
|
var iso_object = GetComponent<IsoObject>();
|
||||||
|
if ( iso_object ) {
|
||||||
|
for (;;) {
|
||||||
|
yield return RndWait();
|
||||||
|
iso_object.Position += new Vector3(1, 0, 0);
|
||||||
|
yield return RndWait();
|
||||||
|
iso_object.Position += new Vector3(0, 1, 0);
|
||||||
|
yield return RndWait();
|
||||||
|
iso_object.Position += new Vector3(-1, 0, 0);
|
||||||
|
yield return RndWait();
|
||||||
|
iso_object.Position += new Vector3(0, -1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Assets/Scripts/IsoAutoController.cs.meta
Normal file
8
Assets/Scripts/IsoAutoController.cs.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1840b23373986f942bf6e0c702745e63
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
@@ -2,10 +2,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class IsoController : MonoBehaviour {
|
public class IsoController : MonoBehaviour {
|
||||||
|
|
||||||
void Start () {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update () {
|
void Update () {
|
||||||
var iso_object = gameObject.GetComponent<IsoObject>();
|
var iso_object = gameObject.GetComponent<IsoObject>();
|
||||||
if ( iso_object ) {
|
if ( iso_object ) {
|
||||||
@@ -29,4 +25,4 @@ public class IsoController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,19 +5,23 @@ using System.Collections;
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class IsoObject : MonoBehaviour {
|
public class IsoObject : MonoBehaviour {
|
||||||
|
|
||||||
|
IsoWorld _iso_world = null;
|
||||||
|
Vector3 _lastPosition = Vector3.zero;
|
||||||
|
Vector3 _lastTransform = Vector3.zero;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Vector3 _position = Vector3.zero;
|
Vector3 _position = Vector3.zero;
|
||||||
private Vector3 _lastPosition = Vector3.zero;
|
public Vector3 Position {
|
||||||
public Vector3 Position {
|
|
||||||
get { return _position; }
|
get { return _position; }
|
||||||
set {
|
set {
|
||||||
if ( Alignment ) {
|
if ( Alignment ) {
|
||||||
_position.Set(Mathf.Round(value.x), Mathf.Round(value.y), value.z);
|
_position.Set(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z));
|
||||||
} else {
|
} else {
|
||||||
_position = value;
|
_position = value;
|
||||||
}
|
}
|
||||||
_lastPosition = _position;
|
|
||||||
FixTransform();
|
FixTransform();
|
||||||
|
GetIsoWorld().MarkDirty();
|
||||||
|
_lastPosition = _position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,36 +29,52 @@ public class IsoObject : MonoBehaviour {
|
|||||||
public bool Alignment = true;
|
public bool Alignment = true;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
|
GetIsoWorld().MarkDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if ( _lastPosition != _position ) {
|
if ( _lastPosition != _position ) {
|
||||||
Position = _position;
|
Position = _position;
|
||||||
}
|
}
|
||||||
|
if ( _lastTransform != gameObject.transform.position ) {
|
||||||
|
FixIsoPosition();
|
||||||
|
}
|
||||||
|
/*
|
||||||
if ( Selection.Contains(gameObject) ) {
|
if ( Selection.Contains(gameObject) ) {
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
} else {
|
} else {
|
||||||
FixTransform();
|
FixTransform();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRenderObject() {
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
IsoWorld GetIsoWorld() {
|
||||||
|
if ( !_iso_world ) {
|
||||||
|
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
}
|
}
|
||||||
|
if ( !_iso_world ) {
|
||||||
|
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||||
|
}
|
||||||
|
return _iso_world;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixTransform() {
|
void FixTransform() {
|
||||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
var pos = GetIsoWorld().IsoToScreen(Position);
|
||||||
if ( !iso_world ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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);
|
var trans = new Vector3(pos.x, pos.y, depth);
|
||||||
|
gameObject.transform.position = trans;
|
||||||
|
_lastPosition = trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixIsoPosition() {
|
void FixIsoPosition() {
|
||||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
var trans = gameObject.transform.position;
|
||||||
if ( !iso_world ) {
|
Position = GetIsoWorld().ScreenToIso(new Vector2(trans.x, trans.y), Position.z);
|
||||||
return;
|
_lastTransform = trans;
|
||||||
|
if ( Application.isEditor ) {
|
||||||
|
EditorUtility.SetDirty(this);
|
||||||
}
|
}
|
||||||
var pos = gameObject.transform.position;
|
|
||||||
Position = iso_world.ScreenToIso(new Vector2(pos.x, pos.y), Position.z);
|
|
||||||
EditorUtility.SetDirty(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,11 @@ using System.Collections.Generic;
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class IsoWorld : MonoBehaviour {
|
public class IsoWorld : MonoBehaviour {
|
||||||
|
|
||||||
private class ObjectInfo {
|
public float TileSize = 32.0f;
|
||||||
|
public float StartDepth = 0.0f;
|
||||||
|
public float StepDepth = 0.1f;
|
||||||
|
|
||||||
|
class ObjectInfo {
|
||||||
public IsoObject IsoObject;
|
public IsoObject IsoObject;
|
||||||
public bool Visited;
|
public bool Visited;
|
||||||
public int BeginDepend;
|
public int BeginDepend;
|
||||||
@@ -20,12 +24,13 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float TileSize = 32.0f;
|
bool _dirty = true;
|
||||||
public float StartDepth = 0.0f;
|
|
||||||
public float StepDepth = 0.1f;
|
|
||||||
|
|
||||||
List<int> _depends = new List<int>();
|
List<int> _depends = new List<int>();
|
||||||
List<ObjectInfo> _objects = new List<ObjectInfo>();
|
List<ObjectInfo> _objects = new List<ObjectInfo>();
|
||||||
|
|
||||||
|
public void MarkDirty() {
|
||||||
|
_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 IsoToScreen(Vector3 pos) {
|
public Vector2 IsoToScreen(Vector3 pos) {
|
||||||
return new Vector2(
|
return new Vector2(
|
||||||
@@ -102,12 +107,19 @@ public class IsoWorld : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start () {
|
void Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update () {
|
void Update() {
|
||||||
_scanObjects();
|
if ( _dirty ) {
|
||||||
_scanDepends();
|
_scanObjects();
|
||||||
_manualSort();
|
_scanDepends();
|
||||||
|
_manualSort();
|
||||||
|
_dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LateUpdate() {
|
||||||
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<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="29" Column="2" />
|
<File FileName="Assets\Scripts\IsoObject.cs" Line="14" Column="27" />
|
||||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="57" Column="1" />
|
<File FileName="Assets\Scripts\IsoWorld.cs" Line="32" Column="17" />
|
||||||
|
<File FileName="Assets\Scripts\IsoAutoController.cs" Line="33" Column="1" />
|
||||||
|
<File FileName="Assets\Scripts\IsoController.cs" Line="28" Column="2" />
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user