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,3 @@
fileFormatVersion: 2
guid: 6da83f1712164887a1710190cac61f41
timeCreated: 1774952920

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Fruitomation.Game
{
public abstract class BuildingBase : MonoBehaviour
{
[Header("Building Properties")]
[SerializeField] private Texture2D BuildingTexture;
[field: SerializeField] public Vector2Int SizeOnGrid { get; private set; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cfb885c06483444a8586e0e2d1933163
timeCreated: 1774952929

View File

@@ -0,0 +1,7 @@
namespace Fruitomation.Game
{
public class FanBuilding : BuildingBase
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1926ee4d89f644c6976fa93256772490
timeCreated: 1774954178

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

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed414fdac7005b54db4dc1ec26e16bd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
using PashaBibko.Pacore.Attributes;
using System.Collections.Generic;
using Fruitomation.Global;
using UnityEngine;
namespace Fruitomation.Game
{
public class FruitSpawner : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private int MaxSpawned;
[SerializeField] private float MinSpawnTime;
[SerializeField] private float MaxSpawnTime;
[Header("References")]
[SerializeField] private Transform FruitSpawnParent;
[SerializeField] private GameObject FruitPrefab;
[SerializeField] private Canvas GameCanvas;
[Header("Read only")]
[SerializeField, InspectorReadOnly] private List<FruitBehaviour> ActiveFruits;
private float TimeUntilNextSpawn;
private void Update()
{
if (ActiveFruits.Count <= MaxSpawned && GameStateController.Is(GameState.Simulation))
{
TimeUntilNextSpawn -= Time.deltaTime;
if (TimeUntilNextSpawn <= 0f)
{
TimeUntilNextSpawn = Random.Range(MinSpawnTime, MaxSpawnTime);
SpawnFruit();
}
}
}
private void SpawnFruit()
{
GameObject go = Instantiate(FruitPrefab, FruitSpawnParent);
FruitBehaviour behaviour = go.GetComponent<FruitBehaviour>();
Debug.Assert(behaviour != null, "Could not find FruitBehaviour");
ActiveFruits.Add(behaviour);
behaviour.InitFruitBehaviour
(
GameCanvas, this
);
}
public void RemoveFruit(FruitBehaviour fruit) => ActiveFruits.Remove(fruit);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1fc36d0808cf971459d9e430faaeadd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: