法杖,武器切换
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.MainGame.Characters;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public partial class BattleManager
|
||||
{
|
||||
public class AttackAreaSubmodule : SubmoduleBase<BattleManager>
|
||||
{
|
||||
public AttackAreaCollection playerAttackAreas;
|
||||
public AttackAreaCollection enemyAttackAreas;
|
||||
|
||||
public AttackAreaSubmodule(BattleManager owner) : base(owner)
|
||||
{
|
||||
playerAttackAreas = new AttackAreaCollection();
|
||||
enemyAttackAreas = new AttackAreaCollection();
|
||||
}
|
||||
|
||||
public void Register(AttackAreaBase attackArea)
|
||||
{
|
||||
if (attackArea.creator.fraction == Fraction.Player)
|
||||
{
|
||||
Debug.Log($"Registered AttackArea: {attackArea.areaName}");
|
||||
playerAttackAreas.Add(attackArea);
|
||||
}
|
||||
else if (attackArea.creator.fraction == Fraction.Enemy)
|
||||
{
|
||||
enemyAttackAreas.Add(attackArea);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unregister(AttackAreaBase attackArea)
|
||||
{
|
||||
if (attackArea.creator.fraction == Fraction.Player)
|
||||
{
|
||||
Debug.Log($"Unregistered AttackArea: {attackArea.areaName}");
|
||||
playerAttackAreas.Remove(attackArea);
|
||||
}
|
||||
else if (attackArea.creator.fraction == Fraction.Enemy)
|
||||
{
|
||||
enemyAttackAreas.Remove(attackArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AttackAreaCollection
|
||||
{
|
||||
public List<AttackAreaBase> activeAttackAreas;
|
||||
public List<NormalArea> activeNormalAreas;
|
||||
public List<Projectile> activeProjectiles;
|
||||
|
||||
public AttackAreaCollection()
|
||||
{
|
||||
activeAttackAreas = new List<AttackAreaBase>();
|
||||
activeNormalAreas = new List<NormalArea>();
|
||||
activeProjectiles = new List<Projectile>();
|
||||
}
|
||||
|
||||
public void Add(AttackAreaBase attackArea)
|
||||
{
|
||||
activeAttackAreas.Add(attackArea);
|
||||
|
||||
if (attackArea is NormalArea normalArea)
|
||||
{
|
||||
activeNormalAreas.Add(normalArea);
|
||||
}
|
||||
else if (attackArea is Projectile projectile)
|
||||
{
|
||||
activeProjectiles.Add(projectile);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(AttackAreaBase attackArea)
|
||||
{
|
||||
activeAttackAreas.Remove(attackArea);
|
||||
|
||||
if (attackArea is NormalArea normalArea)
|
||||
{
|
||||
activeNormalAreas.Remove(normalArea);
|
||||
}
|
||||
else if (attackArea is Projectile projectile)
|
||||
{
|
||||
activeProjectiles.Remove(projectile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e21e9325e65fefa42924ff1f8880d266
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cielonos.MainGame.Characters;
|
||||
using Sirenix.OdinInspector;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public partial class BattleManager : Singleton<BattleManager>
|
||||
{
|
||||
private static Player Player => MainGameManager.Player;
|
||||
|
||||
[ShowInInspector]
|
||||
private EnemySubmodule enemySm;
|
||||
|
||||
[ShowInInspector]
|
||||
private AttackAreaSubmodule attackAreaSm;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
enemySm ??= new EnemySubmodule(this);
|
||||
attackAreaSm ??= new AttackAreaSubmodule(this);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class BattleManager
|
||||
{
|
||||
public static EnemySubmodule EnemySm => Instance.enemySm;
|
||||
public static AttackAreaSubmodule AttackAreaSm => Instance.attackAreaSm;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fd3eac588b1eaf4a858946bb8f55f1f
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cielonos.MainGame.Characters;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public partial class BattleManager
|
||||
{
|
||||
public class EnemySubmodule : SubmoduleBase<BattleManager>
|
||||
{
|
||||
public enum SortingType
|
||||
{
|
||||
Nearest,
|
||||
Farthest
|
||||
}
|
||||
|
||||
public List<CharacterBase> activeEnemiesList;
|
||||
|
||||
public EnemySubmodule(BattleManager owner) : base(owner)
|
||||
{
|
||||
activeEnemiesList = new List<CharacterBase>();
|
||||
}
|
||||
|
||||
public CharacterBase GetNearestEnemy(float maximumDistance = float.MaxValue, Transform origin = null)
|
||||
{
|
||||
if (origin == null)
|
||||
{
|
||||
origin = Player.transform;
|
||||
}
|
||||
|
||||
List<CharacterBase> nearestEnemies = GetEnemiesInRadius(origin.position, maximumDistance);
|
||||
CharacterBase nearestEnemy = nearestEnemies.Count > 0 ? nearestEnemies[0] : null;
|
||||
|
||||
return nearestEnemy;
|
||||
}
|
||||
|
||||
public List<CharacterBase> GetNearestEnemies(float maximumDistance = float.MaxValue, int enemyCount = 1, Transform origin = null)
|
||||
{
|
||||
if (origin == null)
|
||||
{
|
||||
origin = Player.transform;
|
||||
}
|
||||
|
||||
List<CharacterBase> nearestEnemies = GetEnemiesInRadius(origin.position, maximumDistance).Take(enemyCount).ToList();
|
||||
|
||||
return nearestEnemies;
|
||||
}
|
||||
|
||||
public List<CharacterBase> GetEnemiesInRadius(Vector3 origin, float radius, SortingType sortingType = SortingType.Nearest)
|
||||
{
|
||||
List<CharacterBase> enemiesInRadius = new List<CharacterBase>();
|
||||
foreach (CharacterBase enemy in activeEnemiesList)
|
||||
{
|
||||
float enemyRadius = enemy.collisionSc.useCharacterController
|
||||
? enemy.collisionSc.characterController.radius
|
||||
: enemy.collisionSc.mainColliderRadius;
|
||||
|
||||
float distance = Vector3.Distance(origin, enemy.transform.position) - enemyRadius;
|
||||
if (distance <= radius)
|
||||
{
|
||||
enemiesInRadius.Add(enemy);
|
||||
}
|
||||
}
|
||||
|
||||
if (sortingType == SortingType.Nearest)
|
||||
{
|
||||
enemiesInRadius = enemiesInRadius.OrderBy(x => Vector3.Distance(origin, x.transform.position)).ToList();
|
||||
}
|
||||
else if (sortingType == SortingType.Farthest)
|
||||
{
|
||||
enemiesInRadius = enemiesInRadius.OrderByDescending(x => Vector3.Distance(origin, x.transform.position)).ToList();
|
||||
}
|
||||
|
||||
return enemiesInRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfa83226b5985464ebb62c8b756c514d
|
||||
Reference in New Issue
Block a user