111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using Cielonos.MainGame.Characters;
|
|
using Cielonos.MainGame.Inventory;
|
|
using Lean.Pool;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public partial class Projectile : AttackAreaBase
|
|
{
|
|
protected bool ignoreEnvironment = false;
|
|
protected int maximumPenetrateCount = 1;
|
|
protected int currentPenetrateCount = 0;
|
|
|
|
public virtual Projectile Initialize(CharacterBase creator, bool ignoreEnvironment, int penetrateCount = 1, params Fraction[] targetFractions)
|
|
{
|
|
return Initialize(creator, null, ignoreEnvironment, penetrateCount, targetFractions);
|
|
}
|
|
|
|
public virtual Projectile Initialize(CharacterBase creator, ItemBase itemSource,
|
|
bool ignoreEnvironment, int penetrateCount = 1, params Fraction[] targetFractions)
|
|
{
|
|
Projectile projectile = base.Initialize<Projectile>(creator, itemSource, targetFractions);
|
|
projectile.ignoreEnvironment = ignoreEnvironment;
|
|
projectile.maximumPenetrateCount = penetrateCount;
|
|
return projectile;
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
if (raycastSm != null)
|
|
{
|
|
HitCharacter(other, default);
|
|
HitEnvironment(other, default);
|
|
}
|
|
}
|
|
|
|
public override void HitCharacter(Collider characterCollider, Vector3 hitPosition)
|
|
{
|
|
if (!isEnabling)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Debug.Log("Projectile HitCharacter: " + characterCollider.name);
|
|
|
|
CharacterBase targetCharacter = characterCollider.GetComponentInParent<CharacterBase>();
|
|
|
|
if (targetCharacter == creator) return;
|
|
|
|
if (targetCharacter != null) // && targetCharacter.HasAnyTag(targetTagList))
|
|
{
|
|
if (hitSm.checkedObjects.Contains(targetCharacter.gameObject))
|
|
{
|
|
return;
|
|
}
|
|
|
|
hitSm.AddCheckedObject(targetCharacter.gameObject);
|
|
|
|
HitOnTarget(characterCollider, hitPosition);
|
|
}
|
|
}
|
|
|
|
public override void HitEnvironment(Collider other, Vector3 hitPosition)
|
|
{
|
|
if (ignoreEnvironment)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (other.gameObject.layer == LayerMask.NameToLayer("Default") ||
|
|
other.gameObject.layer == LayerMask.NameToLayer("Ground") ||
|
|
other.gameObject.layer == LayerMask.NameToLayer("Wall") ||
|
|
other.gameObject.layer == LayerMask.NameToLayer("FadableEnvironment") ||
|
|
other.gameObject.layer == LayerMask.NameToLayer("UnfadableEnvironment"))
|
|
{
|
|
//特效
|
|
GenerateHitEffect(hitPosition);
|
|
|
|
//音效
|
|
PlaySoundFX(hitPosition);
|
|
|
|
LeanPool.Despawn(topParent.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class Projectile
|
|
{
|
|
protected override void HitOnTarget(Collider hitCollider, Vector3 hitPosition)
|
|
{
|
|
base.HitOnTarget(hitCollider, hitPosition);
|
|
|
|
if (++currentPenetrateCount >= maximumPenetrateCount)
|
|
{
|
|
LeanPool.Despawn(topParent.gameObject);
|
|
}
|
|
}
|
|
|
|
public void Explode(Vector3 hitPosition = default)
|
|
{
|
|
if (hitPosition == default)
|
|
{
|
|
hitPosition = transform.position;
|
|
}
|
|
|
|
GenerateHitEffect(hitPosition);
|
|
PlaySoundFX(hitPosition);
|
|
LeanPool.Despawn(topParent.gameObject);
|
|
}
|
|
}
|
|
} |