From cf76565e4d3087d07e5b67984269beda850e5875 Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Thu, 16 May 2019 16:25:26 +1000 Subject: [PATCH] TrayUI Removing fixed --- .../Plugins/IngameDebugConsole/Sprites.meta | 8 +++++++ Assets/Scenes/Client Scenes/ClientScene.unity | 4 ++-- Assets/Scripts/UI/LogicTrayUI.cs | 17 +++++++++++--- Assets/Scripts/Utility/DebugExtensions.cs | 23 +++++++++++++++---- Assets/Scripts/Utility/ExtensionMethods.cs | 8 +++++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 Assets/Plugins/IngameDebugConsole/Sprites.meta diff --git a/Assets/Plugins/IngameDebugConsole/Sprites.meta b/Assets/Plugins/IngameDebugConsole/Sprites.meta new file mode 100644 index 0000000..504a23d --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Sprites.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb5d7b23a9e684a41a6a5d4f300eb1e6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Client Scenes/ClientScene.unity b/Assets/Scenes/Client Scenes/ClientScene.unity index d5d58dd..765cb3d 100644 --- a/Assets/Scenes/Client Scenes/ClientScene.unity +++ b/Assets/Scenes/Client Scenes/ClientScene.unity @@ -674,7 +674,7 @@ PrefabInstance: - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AnchoredPosition.y - value: -0.000048249298 + value: 0.00002249782 objectReference: {fileID: 0} - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} @@ -684,7 +684,7 @@ PrefabInstance: - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AnchoredPosition.x - value: -0.000075660755 + value: -0.000015290107 objectReference: {fileID: 0} - target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} diff --git a/Assets/Scripts/UI/LogicTrayUI.cs b/Assets/Scripts/UI/LogicTrayUI.cs index d9793d5..dd7a39a 100644 --- a/Assets/Scripts/UI/LogicTrayUI.cs +++ b/Assets/Scripts/UI/LogicTrayUI.cs @@ -104,6 +104,9 @@ public class LogicTrayUI : LogicElementHolder { Vector2 offset = new Vector2(element.rectTransform.rect.width / 2, 0); int index = GetInsertIndex(element.rectTransform, offset); + + Debug.Log("Removing at " + index); + if (index >= reader.LogicChain.Count) index = reader.LogicChain.Count - 1; reader.LogicChain.RemoveAt(index); @@ -115,7 +118,8 @@ public class LogicTrayUI : LogicElementHolder /// Element to add public override void OnAdd(LogicElementUI element) { - int index = GetInsertIndex(element.rectTransform); + Vector2 offset = new Vector2(element.rectTransform.rect.width / 2, 0); + int index = GetInsertIndex(element.rectTransform,offset); reader.Insert(index, element.logicElement); Destroy(element.gameObject); @@ -127,7 +131,8 @@ public class LogicTrayUI : LogicElementHolder /// Element which is hovering public override void OnHover(LogicElementUI element) { - insertIndex = GetInsertIndex(element.rectTransform); + Vector2 offset = new Vector2(element.rectTransform.rect.width / 2, 0); + insertIndex = GetInsertIndex(element.rectTransform, offset); UpdateDisplay(); } @@ -181,9 +186,14 @@ public class LogicTrayUI : LogicElementHolder public int GetInsertIndex(RectTransform rt, Vector2 offset) { - Rect rect = rt.GlobalRect(); + + Rect rect = rt.rect; rect.center += offset; + rect = rt.TransformRect(rect); + + DebugExtensions.DrawRect(rect, Color.green); + foreach (Transform child in content) { RectTransform childRect = child as RectTransform; @@ -191,6 +201,7 @@ public class LogicTrayUI : LogicElementHolder if (rect.Overlaps(childRect.GlobalRect())) return child.GetSiblingIndex(); } + Debug.Log("Returning last"); return reader.LogicChain.Count; } diff --git a/Assets/Scripts/Utility/DebugExtensions.cs b/Assets/Scripts/Utility/DebugExtensions.cs index 1a8e15d..b7d3617 100644 --- a/Assets/Scripts/Utility/DebugExtensions.cs +++ b/Assets/Scripts/Utility/DebugExtensions.cs @@ -58,18 +58,33 @@ public static class DebugExtensions /// /// Draws wireframe around a RectTransform in scene view /// - /// Rect transform to draw around + /// Rect to draw around /// Color of the lines /// How long the lines should be visible for /// Should the lines be obscured by objects closer to the camera - public static void DrawRect(RectTransform transform, Color color, float duration = 0.0f, bool depthTest = false) + public static void DrawRect(Rect rect, Color color, float duration = 0.0f, bool depthTest = false) { - Rect rect = transform.GlobalRect(); - Debug.DrawLine(new Vector3(rect.min.x, rect.max.y, 0), new Vector3(rect.max.x, rect.max.y, 0), color, duration, depthTest); Debug.DrawLine(new Vector3(rect.max.x, rect.max.y, 0), new Vector3(rect.max.x, rect.min.y, 0), color, duration, depthTest); Debug.DrawLine(new Vector3(rect.max.x, rect.min.y, 0), new Vector3(rect.min.x, rect.min.y, 0), color, duration, depthTest); Debug.DrawLine(new Vector3(rect.min.x, rect.min.y, 0), new Vector3(rect.min.x, rect.max.y, 0), color, duration, depthTest); } + /// + /// Draws wireframe around a RectTransform in scene view + /// + /// Rect transform to draw around + /// Color of the lines + /// How long the lines should be visible for + /// Should the lines be obscured by objects closer to the camera + public static void DrawRect(RectTransform transform, Color color, float duration = 0.0f, bool depthTest = false) + { + Rect rect = transform.GlobalRect(); + + DrawRect(rect, color, duration, depthTest); + } + + + + }//End DebugExtentions diff --git a/Assets/Scripts/Utility/ExtensionMethods.cs b/Assets/Scripts/Utility/ExtensionMethods.cs index 25c424a..b6d3633 100644 --- a/Assets/Scripts/Utility/ExtensionMethods.cs +++ b/Assets/Scripts/Utility/ExtensionMethods.cs @@ -70,6 +70,14 @@ public static class ExtensionMethods return r; } + public static Rect TransformRect(this RectTransform rt, Rect rect) + { + Vector2 centre = rt.TransformPoint(rect.center); + rect.size = rt.TransformVector(rect.size); + rect.center = centre; + return rect; + } + ///