diff --git a/FallUnity/Assets/IsoSorting/IsoHandler.cs b/FallUnity/Assets/IsoSorting/IsoHandler.cs index eb22685..13baaed 100644 --- a/FallUnity/Assets/IsoSorting/IsoHandler.cs +++ b/FallUnity/Assets/IsoSorting/IsoHandler.cs @@ -77,7 +77,7 @@ private Vector3 camUp; private Vector3 camPos; private List ordered = new List(); - private HashSet usedChunks = new HashSet(); + //private HashSet usedChunks = new HashSet(); void LateUpdate() { camForward = mainCamera.transform.forward; @@ -117,9 +117,13 @@ Ray inRay = new Ray(); inRay.direction = -camForward; - usedChunks.Clear(); + int layerIn = LayerMask.GetMask("iso_piece", "leaf", "player_controller"); + int layerOut = LayerMask.GetMask("iso_piece"); + RaycastHit hitInfo = new RaycastHit(); - for (int i = 0; i < spriteList.Count; i++) + //usedChunks.Clear(); + int count = spriteList.Count; + for (int i = 0; i < count; i++) { IsoItem item = spriteList[i]; Vector3 screenSpace = mainCamera.WorldToViewportPoint(item.transform.position); @@ -127,9 +131,11 @@ //item.CameraSpace.y = worldBottomLeft.y + screenSpace.y * worldSizeH; //item.CameraSpace.z = screenSpace.z; item.CameraSpace = screenSpace; + + /* if (item.IsoRadius > 0) { - float scale = Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); + float scale = 1; // Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); float radiusCamX = item.IsoRadius / worldSizeW * scale; float radiusCamY = item.IsoRadius / worldSizeH * scale; int leftBucket = Mathf.Max(0, Mathf.Min(ChunksX - 1, (int)Mathf.Floor((screenSpace.x - radiusCamX) * ChunksX))); @@ -150,16 +156,8 @@ if (item.CameraSpace.z > chunk[j].CameraSpace.z) { chunk.Insert(j, item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ + + placed = true; break; } @@ -167,27 +165,24 @@ if (!placed) { chunk.Add(item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ } - usedChunks.Add(chunkIndex); + //usedChunks.Add(chunkIndex); } } } + */ - int layer = LayerMask.GetMask("iso_piece"); - RaycastHit hitInfo = new RaycastHit(); + //if (item.Moved) + //{ outRay.origin = inRay.origin = item.transform.position; - - if (Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layer)) + + bool hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // inRay.origin += inRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -196,7 +191,13 @@ } } - if (Physics.Raycast(outRay, out hitInfo, 50, layer)) + hit = Physics.Raycast(outRay, out hitInfo, 50, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // outRay.origin += outRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -204,26 +205,23 @@ otherItem.Behind.Add(item); } } - + //} + } - foreach (int i in usedChunks) + /* + //foreach (int i in usedChunks) + //{ + for (int i = 0; i < numChunks; i++) { List chunk = chunks[i]; for (int j = 0; j < chunk.Count - 1; j++) { - chunk[j].Behind.Add(chunk[j + 1]); - - /* - if (chunk[j].CameraSpace.z < chunk[j + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - */ + chunk[j].Behind.Add(chunk[j + 1]);/ } chunk.Clear(); } + */ for (int i = 0; i < objectList.Count; i++) { @@ -238,14 +236,18 @@ } int nextUnmarked = 0; - while (nextUnmarked < allList.Count) + int total = allList.Count; + while (nextUnmarked < total) { - if (!allList[nextUnmarked].MarkPerm) - { - IsoItem item = allList[nextUnmarked]; - Visit(item); - } + IsoItem item = allList[nextUnmarked]; + Visit(item); + nextUnmarked++; + + while (nextUnmarked < total && allList[nextUnmarked].MarkPerm) + { + nextUnmarked++; + } } } @@ -254,16 +256,20 @@ if (item.MarkPerm) return; if (item.MarkTemp) { - //Debug.LogError("CYCLICAL RENDER GRAPH"); + Debug.LogError("CYCLICAL RENDER GRAPH"); item.MarkTemp = false; item.MarkPerm = true; //remaining.Remove(item); return; } item.MarkTemp = true; - foreach (IsoItem newItem in item.Behind) + //for (int i = 0; i < item.Behind.Count; i++) + //{ + // Visit(item.Behind[i]); + //} + foreach (IsoItem nextItem in item.Behind) { - Visit(newItem); + Visit(nextItem); } item.MarkTemp = false; item.MarkPerm = true; diff --git a/FallUnity/Assets/IsoSorting/IsoHandler.cs b/FallUnity/Assets/IsoSorting/IsoHandler.cs index eb22685..13baaed 100644 --- a/FallUnity/Assets/IsoSorting/IsoHandler.cs +++ b/FallUnity/Assets/IsoSorting/IsoHandler.cs @@ -77,7 +77,7 @@ private Vector3 camUp; private Vector3 camPos; private List ordered = new List(); - private HashSet usedChunks = new HashSet(); + //private HashSet usedChunks = new HashSet(); void LateUpdate() { camForward = mainCamera.transform.forward; @@ -117,9 +117,13 @@ Ray inRay = new Ray(); inRay.direction = -camForward; - usedChunks.Clear(); + int layerIn = LayerMask.GetMask("iso_piece", "leaf", "player_controller"); + int layerOut = LayerMask.GetMask("iso_piece"); + RaycastHit hitInfo = new RaycastHit(); - for (int i = 0; i < spriteList.Count; i++) + //usedChunks.Clear(); + int count = spriteList.Count; + for (int i = 0; i < count; i++) { IsoItem item = spriteList[i]; Vector3 screenSpace = mainCamera.WorldToViewportPoint(item.transform.position); @@ -127,9 +131,11 @@ //item.CameraSpace.y = worldBottomLeft.y + screenSpace.y * worldSizeH; //item.CameraSpace.z = screenSpace.z; item.CameraSpace = screenSpace; + + /* if (item.IsoRadius > 0) { - float scale = Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); + float scale = 1; // Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); float radiusCamX = item.IsoRadius / worldSizeW * scale; float radiusCamY = item.IsoRadius / worldSizeH * scale; int leftBucket = Mathf.Max(0, Mathf.Min(ChunksX - 1, (int)Mathf.Floor((screenSpace.x - radiusCamX) * ChunksX))); @@ -150,16 +156,8 @@ if (item.CameraSpace.z > chunk[j].CameraSpace.z) { chunk.Insert(j, item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ + + placed = true; break; } @@ -167,27 +165,24 @@ if (!placed) { chunk.Add(item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ } - usedChunks.Add(chunkIndex); + //usedChunks.Add(chunkIndex); } } } + */ - int layer = LayerMask.GetMask("iso_piece"); - RaycastHit hitInfo = new RaycastHit(); + //if (item.Moved) + //{ outRay.origin = inRay.origin = item.transform.position; - - if (Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layer)) + + bool hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // inRay.origin += inRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -196,7 +191,13 @@ } } - if (Physics.Raycast(outRay, out hitInfo, 50, layer)) + hit = Physics.Raycast(outRay, out hitInfo, 50, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // outRay.origin += outRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -204,26 +205,23 @@ otherItem.Behind.Add(item); } } - + //} + } - foreach (int i in usedChunks) + /* + //foreach (int i in usedChunks) + //{ + for (int i = 0; i < numChunks; i++) { List chunk = chunks[i]; for (int j = 0; j < chunk.Count - 1; j++) { - chunk[j].Behind.Add(chunk[j + 1]); - - /* - if (chunk[j].CameraSpace.z < chunk[j + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - */ + chunk[j].Behind.Add(chunk[j + 1]);/ } chunk.Clear(); } + */ for (int i = 0; i < objectList.Count; i++) { @@ -238,14 +236,18 @@ } int nextUnmarked = 0; - while (nextUnmarked < allList.Count) + int total = allList.Count; + while (nextUnmarked < total) { - if (!allList[nextUnmarked].MarkPerm) - { - IsoItem item = allList[nextUnmarked]; - Visit(item); - } + IsoItem item = allList[nextUnmarked]; + Visit(item); + nextUnmarked++; + + while (nextUnmarked < total && allList[nextUnmarked].MarkPerm) + { + nextUnmarked++; + } } } @@ -254,16 +256,20 @@ if (item.MarkPerm) return; if (item.MarkTemp) { - //Debug.LogError("CYCLICAL RENDER GRAPH"); + Debug.LogError("CYCLICAL RENDER GRAPH"); item.MarkTemp = false; item.MarkPerm = true; //remaining.Remove(item); return; } item.MarkTemp = true; - foreach (IsoItem newItem in item.Behind) + //for (int i = 0; i < item.Behind.Count; i++) + //{ + // Visit(item.Behind[i]); + //} + foreach (IsoItem nextItem in item.Behind) { - Visit(newItem); + Visit(nextItem); } item.MarkTemp = false; item.MarkPerm = true; diff --git a/FallUnity/Assets/IsoSorting/IsoItem.cs b/FallUnity/Assets/IsoSorting/IsoItem.cs index 275a33c..ef70a5d 100644 --- a/FallUnity/Assets/IsoSorting/IsoItem.cs +++ b/FallUnity/Assets/IsoSorting/IsoItem.cs @@ -6,10 +6,12 @@ { public Vector3 CameraSpace; public float SetDepth; - internal List Behind = new List(); + internal HashSet Behind = new HashSet(); public GameObject LinkedImage; + public Vector3 lastPos = new Vector3(); + public float IsoRadius = 0; public bool IsoPerspective = false; @@ -17,6 +19,8 @@ internal bool MarkTemp = false; internal bool MarkPerm = false; + public bool AllowMovedFlag = false; + public enum IsoTypes { Sprite, @@ -59,6 +63,6 @@ // Update is called once per frame void Update () { - + } } diff --git a/FallUnity/Assets/IsoSorting/IsoHandler.cs b/FallUnity/Assets/IsoSorting/IsoHandler.cs index eb22685..13baaed 100644 --- a/FallUnity/Assets/IsoSorting/IsoHandler.cs +++ b/FallUnity/Assets/IsoSorting/IsoHandler.cs @@ -77,7 +77,7 @@ private Vector3 camUp; private Vector3 camPos; private List ordered = new List(); - private HashSet usedChunks = new HashSet(); + //private HashSet usedChunks = new HashSet(); void LateUpdate() { camForward = mainCamera.transform.forward; @@ -117,9 +117,13 @@ Ray inRay = new Ray(); inRay.direction = -camForward; - usedChunks.Clear(); + int layerIn = LayerMask.GetMask("iso_piece", "leaf", "player_controller"); + int layerOut = LayerMask.GetMask("iso_piece"); + RaycastHit hitInfo = new RaycastHit(); - for (int i = 0; i < spriteList.Count; i++) + //usedChunks.Clear(); + int count = spriteList.Count; + for (int i = 0; i < count; i++) { IsoItem item = spriteList[i]; Vector3 screenSpace = mainCamera.WorldToViewportPoint(item.transform.position); @@ -127,9 +131,11 @@ //item.CameraSpace.y = worldBottomLeft.y + screenSpace.y * worldSizeH; //item.CameraSpace.z = screenSpace.z; item.CameraSpace = screenSpace; + + /* if (item.IsoRadius > 0) { - float scale = Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); + float scale = 1; // Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); float radiusCamX = item.IsoRadius / worldSizeW * scale; float radiusCamY = item.IsoRadius / worldSizeH * scale; int leftBucket = Mathf.Max(0, Mathf.Min(ChunksX - 1, (int)Mathf.Floor((screenSpace.x - radiusCamX) * ChunksX))); @@ -150,16 +156,8 @@ if (item.CameraSpace.z > chunk[j].CameraSpace.z) { chunk.Insert(j, item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ + + placed = true; break; } @@ -167,27 +165,24 @@ if (!placed) { chunk.Add(item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ } - usedChunks.Add(chunkIndex); + //usedChunks.Add(chunkIndex); } } } + */ - int layer = LayerMask.GetMask("iso_piece"); - RaycastHit hitInfo = new RaycastHit(); + //if (item.Moved) + //{ outRay.origin = inRay.origin = item.transform.position; - - if (Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layer)) + + bool hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // inRay.origin += inRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -196,7 +191,13 @@ } } - if (Physics.Raycast(outRay, out hitInfo, 50, layer)) + hit = Physics.Raycast(outRay, out hitInfo, 50, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // outRay.origin += outRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -204,26 +205,23 @@ otherItem.Behind.Add(item); } } - + //} + } - foreach (int i in usedChunks) + /* + //foreach (int i in usedChunks) + //{ + for (int i = 0; i < numChunks; i++) { List chunk = chunks[i]; for (int j = 0; j < chunk.Count - 1; j++) { - chunk[j].Behind.Add(chunk[j + 1]); - - /* - if (chunk[j].CameraSpace.z < chunk[j + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - */ + chunk[j].Behind.Add(chunk[j + 1]);/ } chunk.Clear(); } + */ for (int i = 0; i < objectList.Count; i++) { @@ -238,14 +236,18 @@ } int nextUnmarked = 0; - while (nextUnmarked < allList.Count) + int total = allList.Count; + while (nextUnmarked < total) { - if (!allList[nextUnmarked].MarkPerm) - { - IsoItem item = allList[nextUnmarked]; - Visit(item); - } + IsoItem item = allList[nextUnmarked]; + Visit(item); + nextUnmarked++; + + while (nextUnmarked < total && allList[nextUnmarked].MarkPerm) + { + nextUnmarked++; + } } } @@ -254,16 +256,20 @@ if (item.MarkPerm) return; if (item.MarkTemp) { - //Debug.LogError("CYCLICAL RENDER GRAPH"); + Debug.LogError("CYCLICAL RENDER GRAPH"); item.MarkTemp = false; item.MarkPerm = true; //remaining.Remove(item); return; } item.MarkTemp = true; - foreach (IsoItem newItem in item.Behind) + //for (int i = 0; i < item.Behind.Count; i++) + //{ + // Visit(item.Behind[i]); + //} + foreach (IsoItem nextItem in item.Behind) { - Visit(newItem); + Visit(nextItem); } item.MarkTemp = false; item.MarkPerm = true; diff --git a/FallUnity/Assets/IsoSorting/IsoItem.cs b/FallUnity/Assets/IsoSorting/IsoItem.cs index 275a33c..ef70a5d 100644 --- a/FallUnity/Assets/IsoSorting/IsoItem.cs +++ b/FallUnity/Assets/IsoSorting/IsoItem.cs @@ -6,10 +6,12 @@ { public Vector3 CameraSpace; public float SetDepth; - internal List Behind = new List(); + internal HashSet Behind = new HashSet(); public GameObject LinkedImage; + public Vector3 lastPos = new Vector3(); + public float IsoRadius = 0; public bool IsoPerspective = false; @@ -17,6 +19,8 @@ internal bool MarkTemp = false; internal bool MarkPerm = false; + public bool AllowMovedFlag = false; + public enum IsoTypes { Sprite, @@ -59,6 +63,6 @@ // Update is called once per frame void Update () { - + } } diff --git a/FallUnity/Assets/Leaves/Leaf.prefab b/FallUnity/Assets/Leaves/Leaf.prefab index 804d87d..8131250 100755 --- a/FallUnity/Assets/Leaves/Leaf.prefab +++ b/FallUnity/Assets/Leaves/Leaf.prefab @@ -378,6 +378,8 @@ CameraSpace: {x: 0, y: 0, z: 0} SetDepth: 0 LinkedImage: {fileID: 1906529563300476} + lastPos: {x: 0, y: 0, z: 0} IsoRadius: 0.4 IsoPerspective: 0 + AllowMovedFlag: 1 IsoType: 0 diff --git a/FallUnity/Assets/IsoSorting/IsoHandler.cs b/FallUnity/Assets/IsoSorting/IsoHandler.cs index eb22685..13baaed 100644 --- a/FallUnity/Assets/IsoSorting/IsoHandler.cs +++ b/FallUnity/Assets/IsoSorting/IsoHandler.cs @@ -77,7 +77,7 @@ private Vector3 camUp; private Vector3 camPos; private List ordered = new List(); - private HashSet usedChunks = new HashSet(); + //private HashSet usedChunks = new HashSet(); void LateUpdate() { camForward = mainCamera.transform.forward; @@ -117,9 +117,13 @@ Ray inRay = new Ray(); inRay.direction = -camForward; - usedChunks.Clear(); + int layerIn = LayerMask.GetMask("iso_piece", "leaf", "player_controller"); + int layerOut = LayerMask.GetMask("iso_piece"); + RaycastHit hitInfo = new RaycastHit(); - for (int i = 0; i < spriteList.Count; i++) + //usedChunks.Clear(); + int count = spriteList.Count; + for (int i = 0; i < count; i++) { IsoItem item = spriteList[i]; Vector3 screenSpace = mainCamera.WorldToViewportPoint(item.transform.position); @@ -127,9 +131,11 @@ //item.CameraSpace.y = worldBottomLeft.y + screenSpace.y * worldSizeH; //item.CameraSpace.z = screenSpace.z; item.CameraSpace = screenSpace; + + /* if (item.IsoRadius > 0) { - float scale = Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); + float scale = 1; // Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); float radiusCamX = item.IsoRadius / worldSizeW * scale; float radiusCamY = item.IsoRadius / worldSizeH * scale; int leftBucket = Mathf.Max(0, Mathf.Min(ChunksX - 1, (int)Mathf.Floor((screenSpace.x - radiusCamX) * ChunksX))); @@ -150,16 +156,8 @@ if (item.CameraSpace.z > chunk[j].CameraSpace.z) { chunk.Insert(j, item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ + + placed = true; break; } @@ -167,27 +165,24 @@ if (!placed) { chunk.Add(item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ } - usedChunks.Add(chunkIndex); + //usedChunks.Add(chunkIndex); } } } + */ - int layer = LayerMask.GetMask("iso_piece"); - RaycastHit hitInfo = new RaycastHit(); + //if (item.Moved) + //{ outRay.origin = inRay.origin = item.transform.position; - - if (Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layer)) + + bool hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // inRay.origin += inRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -196,7 +191,13 @@ } } - if (Physics.Raycast(outRay, out hitInfo, 50, layer)) + hit = Physics.Raycast(outRay, out hitInfo, 50, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // outRay.origin += outRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -204,26 +205,23 @@ otherItem.Behind.Add(item); } } - + //} + } - foreach (int i in usedChunks) + /* + //foreach (int i in usedChunks) + //{ + for (int i = 0; i < numChunks; i++) { List chunk = chunks[i]; for (int j = 0; j < chunk.Count - 1; j++) { - chunk[j].Behind.Add(chunk[j + 1]); - - /* - if (chunk[j].CameraSpace.z < chunk[j + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - */ + chunk[j].Behind.Add(chunk[j + 1]);/ } chunk.Clear(); } + */ for (int i = 0; i < objectList.Count; i++) { @@ -238,14 +236,18 @@ } int nextUnmarked = 0; - while (nextUnmarked < allList.Count) + int total = allList.Count; + while (nextUnmarked < total) { - if (!allList[nextUnmarked].MarkPerm) - { - IsoItem item = allList[nextUnmarked]; - Visit(item); - } + IsoItem item = allList[nextUnmarked]; + Visit(item); + nextUnmarked++; + + while (nextUnmarked < total && allList[nextUnmarked].MarkPerm) + { + nextUnmarked++; + } } } @@ -254,16 +256,20 @@ if (item.MarkPerm) return; if (item.MarkTemp) { - //Debug.LogError("CYCLICAL RENDER GRAPH"); + Debug.LogError("CYCLICAL RENDER GRAPH"); item.MarkTemp = false; item.MarkPerm = true; //remaining.Remove(item); return; } item.MarkTemp = true; - foreach (IsoItem newItem in item.Behind) + //for (int i = 0; i < item.Behind.Count; i++) + //{ + // Visit(item.Behind[i]); + //} + foreach (IsoItem nextItem in item.Behind) { - Visit(newItem); + Visit(nextItem); } item.MarkTemp = false; item.MarkPerm = true; diff --git a/FallUnity/Assets/IsoSorting/IsoItem.cs b/FallUnity/Assets/IsoSorting/IsoItem.cs index 275a33c..ef70a5d 100644 --- a/FallUnity/Assets/IsoSorting/IsoItem.cs +++ b/FallUnity/Assets/IsoSorting/IsoItem.cs @@ -6,10 +6,12 @@ { public Vector3 CameraSpace; public float SetDepth; - internal List Behind = new List(); + internal HashSet Behind = new HashSet(); public GameObject LinkedImage; + public Vector3 lastPos = new Vector3(); + public float IsoRadius = 0; public bool IsoPerspective = false; @@ -17,6 +19,8 @@ internal bool MarkTemp = false; internal bool MarkPerm = false; + public bool AllowMovedFlag = false; + public enum IsoTypes { Sprite, @@ -59,6 +63,6 @@ // Update is called once per frame void Update () { - + } } diff --git a/FallUnity/Assets/Leaves/Leaf.prefab b/FallUnity/Assets/Leaves/Leaf.prefab index 804d87d..8131250 100755 --- a/FallUnity/Assets/Leaves/Leaf.prefab +++ b/FallUnity/Assets/Leaves/Leaf.prefab @@ -378,6 +378,8 @@ CameraSpace: {x: 0, y: 0, z: 0} SetDepth: 0 LinkedImage: {fileID: 1906529563300476} + lastPos: {x: 0, y: 0, z: 0} IsoRadius: 0.4 IsoPerspective: 0 + AllowMovedFlag: 1 IsoType: 0 diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 7dda907..2d8d1b1 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -122,5 +122,10 @@ body.AddForce(new Vector3(-body.velocity.x, 0, -body.velocity.z) * SideRestitution); } + + if (transform.position.y < -5) + { + Destroy(this); + } } } \ No newline at end of file diff --git a/FallUnity/Assets/IsoSorting/IsoHandler.cs b/FallUnity/Assets/IsoSorting/IsoHandler.cs index eb22685..13baaed 100644 --- a/FallUnity/Assets/IsoSorting/IsoHandler.cs +++ b/FallUnity/Assets/IsoSorting/IsoHandler.cs @@ -77,7 +77,7 @@ private Vector3 camUp; private Vector3 camPos; private List ordered = new List(); - private HashSet usedChunks = new HashSet(); + //private HashSet usedChunks = new HashSet(); void LateUpdate() { camForward = mainCamera.transform.forward; @@ -117,9 +117,13 @@ Ray inRay = new Ray(); inRay.direction = -camForward; - usedChunks.Clear(); + int layerIn = LayerMask.GetMask("iso_piece", "leaf", "player_controller"); + int layerOut = LayerMask.GetMask("iso_piece"); + RaycastHit hitInfo = new RaycastHit(); - for (int i = 0; i < spriteList.Count; i++) + //usedChunks.Clear(); + int count = spriteList.Count; + for (int i = 0; i < count; i++) { IsoItem item = spriteList[i]; Vector3 screenSpace = mainCamera.WorldToViewportPoint(item.transform.position); @@ -127,9 +131,11 @@ //item.CameraSpace.y = worldBottomLeft.y + screenSpace.y * worldSizeH; //item.CameraSpace.z = screenSpace.z; item.CameraSpace = screenSpace; + + /* if (item.IsoRadius > 0) { - float scale = Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); + float scale = 1; // Mathf.Max(item.LinkedImage.transform.lossyScale.x, Mathf.Max(item.LinkedImage.transform.lossyScale.y, item.LinkedImage.transform.lossyScale.z)); float radiusCamX = item.IsoRadius / worldSizeW * scale; float radiusCamY = item.IsoRadius / worldSizeH * scale; int leftBucket = Mathf.Max(0, Mathf.Min(ChunksX - 1, (int)Mathf.Floor((screenSpace.x - radiusCamX) * ChunksX))); @@ -150,16 +156,8 @@ if (item.CameraSpace.z > chunk[j].CameraSpace.z) { chunk.Insert(j, item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ + + placed = true; break; } @@ -167,27 +165,24 @@ if (!placed) { chunk.Add(item); - /* - for (int k = 0; k < chunk.Count - 1; k++) - { - if (chunk[k].CameraSpace.z < chunk[k + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - } - */ } - usedChunks.Add(chunkIndex); + //usedChunks.Add(chunkIndex); } } } + */ - int layer = LayerMask.GetMask("iso_piece"); - RaycastHit hitInfo = new RaycastHit(); + //if (item.Moved) + //{ outRay.origin = inRay.origin = item.transform.position; - - if (Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layer)) + + bool hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // inRay.origin += inRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -196,7 +191,13 @@ } } - if (Physics.Raycast(outRay, out hitInfo, 50, layer)) + hit = Physics.Raycast(outRay, out hitInfo, 50, layerIn); + //if (hit && hitInfo.collider.transform.IsChildOf(item.transform)) + //{ + // outRay.origin += outRay.direction * hitInfo.distance * 1.1f; + // hit = Physics.Raycast(inRay, out hitInfo, item.CameraSpace.z, layerIn); + //} + if (hit) { IsoItem otherItem = hitInfo.collider.GetComponentInParent(); if (otherItem != null) @@ -204,26 +205,23 @@ otherItem.Behind.Add(item); } } - + //} + } - foreach (int i in usedChunks) + /* + //foreach (int i in usedChunks) + //{ + for (int i = 0; i < numChunks; i++) { List chunk = chunks[i]; for (int j = 0; j < chunk.Count - 1; j++) { - chunk[j].Behind.Add(chunk[j + 1]); - - /* - if (chunk[j].CameraSpace.z < chunk[j + 1].CameraSpace.z) - { - Debug.LogError("OUT OF ORDER ITEM"); - bool bp = true; - } - */ + chunk[j].Behind.Add(chunk[j + 1]);/ } chunk.Clear(); } + */ for (int i = 0; i < objectList.Count; i++) { @@ -238,14 +236,18 @@ } int nextUnmarked = 0; - while (nextUnmarked < allList.Count) + int total = allList.Count; + while (nextUnmarked < total) { - if (!allList[nextUnmarked].MarkPerm) - { - IsoItem item = allList[nextUnmarked]; - Visit(item); - } + IsoItem item = allList[nextUnmarked]; + Visit(item); + nextUnmarked++; + + while (nextUnmarked < total && allList[nextUnmarked].MarkPerm) + { + nextUnmarked++; + } } } @@ -254,16 +256,20 @@ if (item.MarkPerm) return; if (item.MarkTemp) { - //Debug.LogError("CYCLICAL RENDER GRAPH"); + Debug.LogError("CYCLICAL RENDER GRAPH"); item.MarkTemp = false; item.MarkPerm = true; //remaining.Remove(item); return; } item.MarkTemp = true; - foreach (IsoItem newItem in item.Behind) + //for (int i = 0; i < item.Behind.Count; i++) + //{ + // Visit(item.Behind[i]); + //} + foreach (IsoItem nextItem in item.Behind) { - Visit(newItem); + Visit(nextItem); } item.MarkTemp = false; item.MarkPerm = true; diff --git a/FallUnity/Assets/IsoSorting/IsoItem.cs b/FallUnity/Assets/IsoSorting/IsoItem.cs index 275a33c..ef70a5d 100644 --- a/FallUnity/Assets/IsoSorting/IsoItem.cs +++ b/FallUnity/Assets/IsoSorting/IsoItem.cs @@ -6,10 +6,12 @@ { public Vector3 CameraSpace; public float SetDepth; - internal List Behind = new List(); + internal HashSet Behind = new HashSet(); public GameObject LinkedImage; + public Vector3 lastPos = new Vector3(); + public float IsoRadius = 0; public bool IsoPerspective = false; @@ -17,6 +19,8 @@ internal bool MarkTemp = false; internal bool MarkPerm = false; + public bool AllowMovedFlag = false; + public enum IsoTypes { Sprite, @@ -59,6 +63,6 @@ // Update is called once per frame void Update () { - + } } diff --git a/FallUnity/Assets/Leaves/Leaf.prefab b/FallUnity/Assets/Leaves/Leaf.prefab index 804d87d..8131250 100755 --- a/FallUnity/Assets/Leaves/Leaf.prefab +++ b/FallUnity/Assets/Leaves/Leaf.prefab @@ -378,6 +378,8 @@ CameraSpace: {x: 0, y: 0, z: 0} SetDepth: 0 LinkedImage: {fileID: 1906529563300476} + lastPos: {x: 0, y: 0, z: 0} IsoRadius: 0.4 IsoPerspective: 0 + AllowMovedFlag: 1 IsoType: 0 diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 7dda907..2d8d1b1 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -122,5 +122,10 @@ body.AddForce(new Vector3(-body.velocity.x, 0, -body.velocity.z) * SideRestitution); } + + if (transform.position.y < -5) + { + Destroy(this); + } } } \ No newline at end of file diff --git a/FallUnity/Assets/level.unity b/FallUnity/Assets/level.unity index 6f0f3c1..3bc275e 100755 --- a/FallUnity/Assets/level.unity +++ b/FallUnity/Assets/level.unity @@ -223,8 +223,8 @@ m_Script: {fileID: 11500000, guid: e9e45b67a184f38439d0136610b1d1cb, type: 3} m_Name: m_EditorClassIdentifier: - ChunksX: 20 - ChunksY: 20 + ChunksX: 80 + ChunksY: 80 --- !u!1 &257733088 GameObject: m_ObjectHideFlags: 0 @@ -370,8 +370,10 @@ CameraSpace: {x: 0, y: 0, z: 0} SetDepth: 0 LinkedImage: {fileID: 1777425976} + lastPos: {x: 0, y: 0, z: 0} IsoRadius: 0 IsoPerspective: 0 + AllowMovedFlag: 0 IsoType: 1 --- !u!1 &418505720 GameObject: @@ -821,8 +823,10 @@ CameraSpace: {x: 0, y: 0, z: 0} SetDepth: 0 LinkedImage: {fileID: 1548969793} + lastPos: {x: 0, y: 0, z: 0} IsoRadius: 0 IsoPerspective: 0 + AllowMovedFlag: 0 IsoType: 1 --- !u!1 &1206131915 GameObject: