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>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\IsoAutoController.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoController.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\IsoAutoController.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoController.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoObject.cs" />
|
||||
<Compile Include="Assets\Scripts\IsoWorld.cs" />
|
||||
|
||||
@@ -41,8 +41,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_position: {x: 0, y: 0, z: 0}
|
||||
_size: {x: 1, y: 3, z: 1}
|
||||
_alignment: 1
|
||||
Size: {x: 1, y: 3, z: 1}
|
||||
Alignment: 1
|
||||
--- !u!212 &21224792
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 1
|
||||
|
||||
@@ -41,8 +41,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_position: {x: 0, y: 0, z: 0}
|
||||
_size: {x: 3, y: 1, z: 1}
|
||||
_alignment: 1
|
||||
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
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;
|
||||
|
||||
public class IsoController : MonoBehaviour {
|
||||
|
||||
void Start () {
|
||||
}
|
||||
|
||||
void Update () {
|
||||
var iso_object = gameObject.GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
@@ -29,4 +25,4 @@ public class IsoController : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,23 @@ using System.Collections;
|
||||
[ExecuteInEditMode]
|
||||
public class IsoObject : MonoBehaviour {
|
||||
|
||||
IsoWorld _iso_world = null;
|
||||
Vector3 _lastPosition = Vector3.zero;
|
||||
Vector3 _lastTransform = Vector3.zero;
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 _position = Vector3.zero;
|
||||
private Vector3 _lastPosition = Vector3.zero;
|
||||
public Vector3 Position {
|
||||
Vector3 _position = Vector3.zero;
|
||||
public Vector3 Position {
|
||||
get { return _position; }
|
||||
set {
|
||||
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 {
|
||||
_position = value;
|
||||
}
|
||||
_lastPosition = _position;
|
||||
FixTransform();
|
||||
GetIsoWorld().MarkDirty();
|
||||
_lastPosition = _position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,36 +29,52 @@ public class IsoObject : MonoBehaviour {
|
||||
public bool Alignment = true;
|
||||
|
||||
void Start() {
|
||||
GetIsoWorld().MarkDirty();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if ( _lastPosition != _position ) {
|
||||
Position = _position;
|
||||
}
|
||||
if ( _lastTransform != gameObject.transform.position ) {
|
||||
FixIsoPosition();
|
||||
}
|
||||
/*
|
||||
if ( Selection.Contains(gameObject) ) {
|
||||
FixIsoPosition();
|
||||
} else {
|
||||
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() {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( !iso_world ) {
|
||||
return;
|
||||
}
|
||||
var pos = iso_world.IsoToScreen(Position);
|
||||
var pos = GetIsoWorld().IsoToScreen(Position);
|
||||
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() {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( !iso_world ) {
|
||||
return;
|
||||
var trans = gameObject.transform.position;
|
||||
Position = GetIsoWorld().ScreenToIso(new Vector2(trans.x, trans.y), Position.z);
|
||||
_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]
|
||||
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 bool Visited;
|
||||
public int BeginDepend;
|
||||
@@ -20,12 +24,13 @@ public class IsoWorld : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
public float TileSize = 32.0f;
|
||||
public float StartDepth = 0.0f;
|
||||
public float StepDepth = 0.1f;
|
||||
|
||||
bool _dirty = true;
|
||||
List<int> _depends = new List<int>();
|
||||
List<ObjectInfo> _objects = new List<ObjectInfo>();
|
||||
|
||||
public void MarkDirty() {
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public Vector2 IsoToScreen(Vector3 pos) {
|
||||
return new Vector2(
|
||||
@@ -102,12 +107,19 @@ public class IsoWorld : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void Start () {
|
||||
void Start() {
|
||||
}
|
||||
|
||||
void Update () {
|
||||
_scanObjects();
|
||||
_scanDepends();
|
||||
_manualSort();
|
||||
void Update() {
|
||||
if ( _dirty ) {
|
||||
_scanObjects();
|
||||
_scanDepends();
|
||||
_manualSort();
|
||||
_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate() {
|
||||
Update();
|
||||
}
|
||||
}
|
||||
@@ -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,9 +1,11 @@
|
||||
<Properties>
|
||||
<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>
|
||||
<File FileName="Assets\Scripts\IsoWorld.cs" Line="29" Column="2" />
|
||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="57" Column="1" />
|
||||
<File FileName="Assets\Scripts\IsoObject.cs" Line="14" Column="27" />
|
||||
<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>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user