Made only X dir count as off-screen
This commit is contained in:
@@ -2708,7 +2708,7 @@ RectTransform:
|
|||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: -980}
|
m_AnchoredPosition: {x: 0, y: -980}
|
||||||
m_SizeDelta: {x: 3840, y: 200}
|
m_SizeDelta: {x: 6000, y: 200}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!61 &2112507920
|
--- !u!61 &2112507920
|
||||||
BoxCollider2D:
|
BoxCollider2D:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
using System.Numerics;
|
||||||
using Fruitomation.Global;
|
using Fruitomation.Global;
|
||||||
using PashaBibko.Pacore.Attributes;
|
using PashaBibko.Pacore.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Vector3 = UnityEngine.Vector3;
|
||||||
|
|
||||||
namespace Fruitomation.Game.Items
|
namespace Fruitomation.Game.Items
|
||||||
{
|
{
|
||||||
@@ -72,16 +74,13 @@ namespace Fruitomation.Game.Items
|
|||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
bool contained = IsWithinCanvas(RectTransform, AttachedCanvas.GetComponent<RectTransform>());
|
if (IsNotWithinCanvas(RectTransform, AttachedCanvas.GetComponent<RectTransform>()))
|
||||||
EnteredCanvas = EnteredCanvas || contained;
|
|
||||||
|
|
||||||
if (!contained && EnteredCanvas)
|
|
||||||
{
|
{
|
||||||
TriggerDestruction();
|
TriggerDestruction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsWithinCanvas(RectTransform element, RectTransform canvas)
|
private static bool IsNotWithinCanvas(RectTransform element, RectTransform canvas)
|
||||||
{
|
{
|
||||||
Vector3[] elementCorners = new Vector3[4];
|
Vector3[] elementCorners = new Vector3[4];
|
||||||
Vector3[] canvasCorners = new Vector3[4];
|
Vector3[] canvasCorners = new Vector3[4];
|
||||||
@@ -89,23 +88,27 @@ namespace Fruitomation.Game.Items
|
|||||||
element.GetWorldCorners(elementCorners);
|
element.GetWorldCorners(elementCorners);
|
||||||
canvas.GetWorldCorners(canvasCorners);
|
canvas.GetWorldCorners(canvasCorners);
|
||||||
|
|
||||||
Rect bounds = new
|
float aMin = float.MaxValue;
|
||||||
(
|
float aMax = float.MinValue;
|
||||||
canvasCorners[0].x,
|
|
||||||
canvasCorners[0].y,
|
foreach (Vector3 corner in canvasCorners)
|
||||||
canvasCorners[2].x - canvasCorners[0].x,
|
{
|
||||||
canvasCorners[2].y - canvasCorners[0].y
|
aMin = Mathf.Min(aMin, corner.x);
|
||||||
);
|
aMax = Mathf.Max(aMax, corner.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float bMin = float.MaxValue;
|
||||||
|
float bMax = float.MinValue;
|
||||||
|
|
||||||
foreach (Vector3 corner in elementCorners)
|
foreach (Vector3 corner in elementCorners)
|
||||||
{
|
{
|
||||||
if (bounds.Contains(corner))
|
bMin = Mathf.Min(bMin, corner.x);
|
||||||
{
|
bMax = Mathf.Max(bMax, corner.x);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return
|
||||||
|
!(bMin > (aMin - 1f)) ||
|
||||||
|
!(bMax < (aMax + 1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TriggerDestruction(bool harvest = true)
|
public void TriggerDestruction(bool harvest = true)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ TagManager:
|
|||||||
-
|
-
|
||||||
- Buildings
|
- Buildings
|
||||||
- Items
|
- Items
|
||||||
-
|
- BuildingNoRaycast
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|||||||
Reference in New Issue
Block a user