Organised and added fan art

This commit is contained in:
2026-03-31 11:52:26 +01:00
parent dbd7414f8f
commit b92f4d1189
25 changed files with 235 additions and 7 deletions

View File

@@ -0,0 +1,84 @@
using Fruitomation.Global;
using PashaBibko.Pacore.Attributes;
using UnityEngine.UI;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Fruitomation.Game
{
public class FruitBehaviour : MonoBehaviour
{
[Header("References")]
[SerializeField] private RectTransform RectTransform;
[SerializeField] private Rigidbody2D Body2D;
[SerializeField] private Button Button;
[Header("Read only")]
[InspectorReadOnly, SerializeField] private Canvas AttachedCanvas;
[InspectorReadOnly, SerializeField] private FruitSpawner Spawner;
[InspectorReadOnly, SerializeField] private bool EnteredCanvas;
public void InitFruitBehaviour(Canvas canvas, FruitSpawner spawner)
{
AttachedCanvas = canvas;
EnteredCanvas = false;
Spawner = spawner;
Body2D.velocity = Random.insideUnitCircle * 2.5f;
}
private void Update()
{
if (!GameStateController.Is(GameState.Simulation))
{
TriggerDestruction();
}
}
private void FixedUpdate()
{
bool contained = IsWithinCanvas(RectTransform, AttachedCanvas.GetComponent<RectTransform>());
EnteredCanvas = EnteredCanvas || contained;
if (!contained && EnteredCanvas)
{
TriggerDestruction();
}
}
public void TriggerDestruction()
{
MoneyController.Add((ulong)Random.Range(1, 5));
Spawner.RemoveFruit(this);
Destroy(gameObject);
}
private static bool IsWithinCanvas(RectTransform element, RectTransform canvas)
{
Vector3[] elementCorners = new Vector3[4];
Vector3[] canvasCorners = new Vector3[4];
element.GetWorldCorners(elementCorners);
canvas.GetWorldCorners(canvasCorners);
Rect bounds = new
(
canvasCorners[0].x,
canvasCorners[0].y,
canvasCorners[2].x - canvasCorners[0].x,
canvasCorners[2].y - canvasCorners[0].y
);
foreach (Vector3 corner in elementCorners)
{
if (bounds.Contains(corner))
{
return true;
}
}
return false;
}
}
}