Browse Source

TrayUI Removing fixed

master
JoshuaReason 5 years ago
parent
commit
cf76565e4d
5 changed files with 51 additions and 9 deletions
  1. +8
    -0
      Assets/Plugins/IngameDebugConsole/Sprites.meta
  2. +2
    -2
      Assets/Scenes/Client Scenes/ClientScene.unity
  3. +14
    -3
      Assets/Scripts/UI/LogicTrayUI.cs
  4. +19
    -4
      Assets/Scripts/Utility/DebugExtensions.cs
  5. +8
    -0
      Assets/Scripts/Utility/ExtensionMethods.cs

+ 8
- 0
Assets/Plugins/IngameDebugConsole/Sprites.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cb5d7b23a9e684a41a6a5d4f300eb1e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 2
Assets/Scenes/Client Scenes/ClientScene.unity View File

@ -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}

+ 14
- 3
Assets/Scripts/UI/LogicTrayUI.cs View File

@ -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
/// <param name="element">Element to add</param>
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
/// <param name="element">Element which is hovering</param>
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;
}

+ 19
- 4
Assets/Scripts/Utility/DebugExtensions.cs View File

@ -58,18 +58,33 @@ public static class DebugExtensions
/// <summary>
/// Draws wireframe around a RectTransform in scene view
/// </summary>
/// <param name="transform">Rect transform to draw around</param>
/// <param name="rect">Rect to draw around</param>
/// <param name="color">Color of the lines</param>
/// <param name="duration">How long the lines should be visible for</param>
/// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
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);
}
/// <summary>
/// Draws wireframe around a RectTransform in scene view
/// </summary>
/// <param name="transform">Rect transform to draw around</param>
/// <param name="color">Color of the lines</param>
/// <param name="duration">How long the lines should be visible for</param>
/// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
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

+ 8
- 0
Assets/Scripts/Utility/ExtensionMethods.cs View File

@ -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;
}
/// <summary>

Loading…
Cancel
Save