Organised and added fan art
This commit is contained in:
3
Assets/Scripts/Game/Buildings.meta
Normal file
3
Assets/Scripts/Game/Buildings.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da83f1712164887a1710190cac61f41
|
||||
timeCreated: 1774952920
|
||||
11
Assets/Scripts/Game/Buildings/BuildingBase.cs
Normal file
11
Assets/Scripts/Game/Buildings/BuildingBase.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Buildings/BuildingBase.cs.meta
Normal file
3
Assets/Scripts/Game/Buildings/BuildingBase.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfb885c06483444a8586e0e2d1933163
|
||||
timeCreated: 1774952929
|
||||
7
Assets/Scripts/Game/Buildings/FanBuilding.cs
Normal file
7
Assets/Scripts/Game/Buildings/FanBuilding.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Fruitomation.Game
|
||||
{
|
||||
public class FanBuilding : BuildingBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Buildings/FanBuilding.cs.meta
Normal file
3
Assets/Scripts/Game/Buildings/FanBuilding.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1926ee4d89f644c6976fa93256772490
|
||||
timeCreated: 1774954178
|
||||
84
Assets/Scripts/Game/FruitBehaviour.cs
Normal file
84
Assets/Scripts/Game/FruitBehaviour.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Game/FruitBehaviour.cs.meta
Normal file
11
Assets/Scripts/Game/FruitBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed414fdac7005b54db4dc1ec26e16bd6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/Scripts/Game/FruitSpawner.cs
Normal file
54
Assets/Scripts/Game/FruitSpawner.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Game/FruitSpawner.cs.meta
Normal file
11
Assets/Scripts/Game/FruitSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fc36d0808cf971459d9e430faaeadd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user