more enemy stuff
This commit is contained in:
parent
3b60583c76
commit
d8c49317a3
235 changed files with 27781 additions and 3909 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ public class AbilityManager : MonoBehaviour
|
|||
private void Start()
|
||||
{
|
||||
// upgradeButton.onClick.AddListener((() => AddUpgrade(upgradeToAdd, player.mainAttackInstance)));
|
||||
StoreUpgrade(upgradeToAdd);
|
||||
}
|
||||
|
||||
public void StoreUpgrade(AbilityUpgrade upgradeToStore)
|
||||
|
|
@ -59,23 +61,34 @@ public class AbilityManager : MonoBehaviour
|
|||
Debug.Log($"Added upgrade {newUpgrade.upgrade.upgradeName}. Current count: {newUpgrade.count}");
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
}
|
||||
|
||||
public void AddUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
||||
{
|
||||
if (!ability.attachedUpgrades.Contains(upgrade))
|
||||
foreach (StoredUpgrade storedUpgrade in upgradesInventory.ToArray())
|
||||
{
|
||||
AbilityUpgrade newUpgrade = Instantiate(upgrade, ability.transform);
|
||||
ability.attachedUpgrades.Add(newUpgrade);
|
||||
newUpgrade.thisPlayerAbility = ability;
|
||||
newUpgrade.ApplyUpgrade();
|
||||
}
|
||||
else
|
||||
{
|
||||
ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade);
|
||||
if (foundUpgrade)
|
||||
if (storedUpgrade.upgrade == upgrade)
|
||||
{
|
||||
foundUpgrade.count++;
|
||||
foundUpgrade.ApplyUpgrade();
|
||||
storedUpgrade.count--;
|
||||
if (storedUpgrade.count <= 0)
|
||||
{
|
||||
upgradesInventory.Remove(storedUpgrade);
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
}
|
||||
if (!ability.attachedUpgrades.Contains(upgrade))
|
||||
{
|
||||
AbilityUpgrade newUpgrade = Instantiate(upgrade, ability.transform);
|
||||
ability.attachedUpgrades.Add(newUpgrade);
|
||||
newUpgrade.thisPlayerAbility = ability;
|
||||
newUpgrade.ApplyUpgrade();
|
||||
}
|
||||
else
|
||||
{
|
||||
ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade);
|
||||
if (foundUpgrade)
|
||||
{
|
||||
foundUpgrade.count++;
|
||||
foundUpgrade.ApplyUpgrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
|
@ -15,6 +16,7 @@ public class AbilityUIObject : MonoBehaviour
|
|||
[SerializeField] private TextMeshProUGUI piercing;
|
||||
[SerializeField] private TextMeshProUGUI projectileCount;
|
||||
[Header("Upgrades")]
|
||||
[SerializeField] private int upgradeSlotAmount;
|
||||
[SerializeField] private UpgradeBoxUI templateUpgradeBox;
|
||||
[SerializeField] private Transform upgradeGrid;
|
||||
[SerializeField] private List<UpgradeBoxUI> upgradeBoxes = new();
|
||||
|
|
@ -32,14 +34,30 @@ public class AbilityUIObject : MonoBehaviour
|
|||
piercing.text = $"Piercing: {isBullet.pierceAmount}";
|
||||
projectileCount.text = $"Projectiles: {isBullet.projectileCount}";
|
||||
}
|
||||
foreach (AbilityUpgrade upgrade in thisAbility.attachedUpgrades)
|
||||
{
|
||||
AddUpgradeBox(upgrade);
|
||||
}
|
||||
|
||||
int upgradeBoxesToAdd = Math.Abs(upgradeSlotAmount - upgradeBoxes.Count);
|
||||
for (int i = 0; i < upgradeBoxesToAdd; i++)
|
||||
{
|
||||
AddUpgradeBox(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUpgradeBox(AbilityUpgrade upgrade)
|
||||
{
|
||||
UpgradeBoxUI newBox = Instantiate(templateUpgradeBox, upgradeGrid);
|
||||
newBox.gameObject.SetActive(true);
|
||||
upgradeBoxes.Add(newBox);
|
||||
newBox.upgradeImage.sprite = upgrade.upgradeIcon;
|
||||
newBox.UpdateCounter();
|
||||
newBox.thisPlayerAbility = thisAbility;
|
||||
if (upgrade)
|
||||
{
|
||||
newBox.upgradeImage.sprite = upgrade.upgradeIcon;
|
||||
newBox.thisAbilityUpgrade = upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUpgradeBoxes()
|
||||
|
|
|
|||
11
Assets/Scripts/Abilities/EnemyAbility.cs
Normal file
11
Assets/Scripts/Abilities/EnemyAbility.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class EnemyAbility : ScriptableObject
|
||||
{
|
||||
public float cooldown;
|
||||
public float power;
|
||||
public virtual void UseAbility(Entity target, Enemy owner)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Abilities/EnemyAbility.cs.meta
Normal file
2
Assets/Scripts/Abilities/EnemyAbility.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3e75d1221694242192a35134c73e473
|
||||
|
|
@ -1,14 +1,33 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UpgradeBoxUI : MonoBehaviour
|
||||
public class UpgradeBoxUI : MonoBehaviour, IDropHandler
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI counterUI;
|
||||
public Image upgradeImage;
|
||||
public AbilityUpgrade thisAbilityUpgrade;
|
||||
public PlayerAbility thisPlayerAbility;
|
||||
public void UpdateCounter()
|
||||
{
|
||||
if (!thisAbilityUpgrade)
|
||||
{
|
||||
counterUI.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
counterUI.gameObject.SetActive(true);
|
||||
counterUI.text = $"x{thisAbilityUpgrade.count}";
|
||||
}
|
||||
|
||||
public void OnDrop(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("A");
|
||||
if (eventData.pointerDrag.TryGetComponent(out StoredAbilityUpgradeUI isStoredUpgrade) && (!thisAbilityUpgrade || isStoredUpgrade.storedUpgrade == thisAbilityUpgrade))
|
||||
{
|
||||
thisAbilityUpgrade = isStoredUpgrade.storedUpgrade;
|
||||
AbilityManager.instance.AddUpgrade(thisAbilityUpgrade, thisPlayerAbility);
|
||||
UpdateCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
Assets/Scripts/Entities/Enemy.meta
Normal file
8
Assets/Scripts/Entities/Enemy.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 76492d48e9b8650b3a777d1a78255403
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/Entities/Enemy/BossRange.cs
Normal file
14
Assets/Scripts/Entities/Enemy/BossRange.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class BossRange : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag(tag))
|
||||
{
|
||||
EnemySpawner.instance.StartBoss();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/Enemy/BossRange.cs.meta
Normal file
2
Assets/Scripts/Entities/Enemy/BossRange.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b504e72f3e510d93bbb892b7ce53bbe
|
||||
|
|
@ -1,9 +1,17 @@
|
|||
using System;
|
||||
using Core.Extensions;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Enemy : Entity
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Ability
|
||||
{
|
||||
public EnemyAbility ability;
|
||||
public float currentCooldown;
|
||||
}
|
||||
[Header("Targetting")]
|
||||
public Entity closestTarget;
|
||||
public float engagementRange;
|
||||
|
|
@ -24,9 +32,11 @@ public class Enemy : Entity
|
|||
}
|
||||
[Header("Drops")]
|
||||
public List<UpgradeDrop> possibleDrops = new();
|
||||
|
||||
[SerializeField] private UpgradePickup pickupObject;
|
||||
private void Start()
|
||||
|
||||
[Header("Abilities")]
|
||||
[SerializeField] private Ability[] allAbilities;
|
||||
private void Start()
|
||||
{
|
||||
if (Random.Range(0f, 2f) > 1f)
|
||||
{
|
||||
|
|
@ -35,6 +45,30 @@ public class Enemy : Entity
|
|||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (detectedPlayer)
|
||||
{
|
||||
Ability foundAbility = null;
|
||||
foreach (Ability availableAbility in allAbilities)
|
||||
{
|
||||
if (foundAbility == null && availableAbility.currentCooldown <= 0)
|
||||
{
|
||||
foundAbility = availableAbility;
|
||||
}
|
||||
else if (availableAbility.currentCooldown > 0)
|
||||
{
|
||||
availableAbility.currentCooldown -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
if (foundAbility != null)
|
||||
{
|
||||
foundAbility.ability.UseAbility(closestTarget, this);
|
||||
foundAbility.currentCooldown = foundAbility.ability.cooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FixedUpdate()
|
||||
{
|
||||
if (!detectedPlayer && Vector3.Distance(transform.position, closestTarget.transform.position) < engagementRange)
|
||||
36
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs
Normal file
36
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Enemy Projectile Ability", menuName = "EnemyAbilities/FireBullet")]
|
||||
public class EnemyFireBullet : EnemyAbility
|
||||
{
|
||||
public enum FireMode {Angled, Offset};
|
||||
[Header("Projectile")]
|
||||
public FireMode fireMode = FireMode.Offset;
|
||||
public Vector2 offset;
|
||||
public float angle;
|
||||
public int projectileCount;
|
||||
public int pierceAmount;
|
||||
public float projectileSpeed;
|
||||
public float bulletLifetime;
|
||||
public float accuracy;
|
||||
public Projectile projectile;
|
||||
|
||||
public override void UseAbility(Entity target, Enemy owner)
|
||||
{
|
||||
for (int i = 0; i < projectileCount; i++)
|
||||
{
|
||||
Projectile newProjectile = Instantiate(projectile, owner.transform.position, Quaternion.identity);
|
||||
newProjectile.RotateToTarget(target.transform.position);
|
||||
if (fireMode == FireMode.Offset && projectileCount > 1)
|
||||
{
|
||||
newProjectile.transform.position += new Vector3(Random.Range(-offset.x, offset.x), Random.Range(-offset.y, offset.y));
|
||||
}
|
||||
newProjectile.pierceAmount = pierceAmount;
|
||||
newProjectile.damage = power;
|
||||
newProjectile.speed = projectileSpeed;
|
||||
newProjectile.lifetime = bulletLifetime;
|
||||
newProjectile.transform.Rotate(0, 0, Random.Range(-accuracy, accuracy));
|
||||
newProjectile.tag = owner.tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs.meta
Normal file
2
Assets/Scripts/Entities/Enemy/EnemyFireBullet.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c76701d260732d13a1beca8945ac458
|
||||
61
Assets/Scripts/Entities/Enemy/EnemySpawner.cs
Normal file
61
Assets/Scripts/Entities/Enemy/EnemySpawner.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class EnemySpawner : MonoBehaviour
|
||||
{
|
||||
#region Statication
|
||||
|
||||
public static EnemySpawner instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null && instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Header("Enemies")]
|
||||
public bool canSpawn = true;
|
||||
public Enemy[] enemiesToSpawn;
|
||||
public List<Transform> spawnPoints;
|
||||
public float spawnRate;
|
||||
[SerializeField] private float currentSpawnTime;
|
||||
[Header("Boss")]
|
||||
public Enemy bossEnemy;
|
||||
public Transform bossSpawnPoint;
|
||||
[Header("Cache")]
|
||||
[SerializeField] private Transform enemyFolder;
|
||||
[SerializeField] private Marisa player;
|
||||
private void Update()
|
||||
{
|
||||
if (canSpawn)
|
||||
{
|
||||
currentSpawnTime -= Time.deltaTime;
|
||||
if (currentSpawnTime < 0)
|
||||
{
|
||||
currentSpawnTime = spawnRate;
|
||||
SpawnEnemy(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], spawnPoints[Random.Range(0, spawnPoints.Count)].position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnEnemy(Enemy enemy, Vector3 location)
|
||||
{
|
||||
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
|
||||
newEnemy.transform.SetParent(enemyFolder);
|
||||
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
|
||||
}
|
||||
|
||||
public void StartBoss()
|
||||
{
|
||||
SpawnEnemy(bossEnemy, bossSpawnPoint.position);
|
||||
canSpawn = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class EnemySpawner : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Marisa player;
|
||||
public Enemy[] enemiesToSpawn;
|
||||
public List<Transform> spawnPoints;
|
||||
public float spawnRate;
|
||||
[SerializeField] private float currentSpawnTime;
|
||||
[SerializeField] private Transform enemyFolder;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
currentSpawnTime -= Time.deltaTime;
|
||||
if (currentSpawnTime < 0)
|
||||
{
|
||||
currentSpawnTime = spawnRate;
|
||||
SpawnEnemy(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], spawnPoints[Random.Range(0, spawnPoints.Count)].position);
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnEnemy(Enemy enemy, Vector3 location)
|
||||
{
|
||||
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
|
||||
newEnemy.transform.SetParent(enemyFolder);
|
||||
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,45 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class StoredAbilityUpgradeUI : MonoBehaviour
|
||||
public class StoredAbilityUpgradeUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private TextMeshProUGUI nameUI;
|
||||
[SerializeField] private TextMeshProUGUI countUI;
|
||||
|
||||
public AbilityUpgrade storedUpgrade;
|
||||
[HideInInspector] public Transform parentAfterDrag;
|
||||
public void SetUpgrade(AbilityUpgrade upgrade, int count)
|
||||
{
|
||||
//icon.sprite = upgrade.upgradeIcon;
|
||||
storedUpgrade = upgrade;
|
||||
nameUI.text = upgrade.name;
|
||||
countUI.text = $"x{count}";
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
parentAfterDrag = transform.parent;
|
||||
icon.raycastTarget = false;
|
||||
icon.transform.SetParent(transform.root);
|
||||
icon.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
icon.transform.position = Input.mousePosition;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
icon.raycastTarget = true;
|
||||
icon.transform.SetParent(parentAfterDrag);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Destroy(icon.gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue