156 lines
5.0 KiB
C#
156 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Characters;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public partial class HitSubmodule : AttackAreaSubmoduleBase
|
|
{
|
|
public int originalHitCount;
|
|
public int currentHitIndex;
|
|
public float hitInterval;
|
|
private float currentIntervalTime;
|
|
|
|
public List<GameObject> checkedObjects;
|
|
public bool isAutoPlayHitSound;
|
|
public List<string> hitSoundList;
|
|
public List<Action<CharacterBase, Vector3>> generalHitEventList;
|
|
public SortedList<int, Action<CharacterBase, Vector3>> specificHitEventList;
|
|
|
|
public HitSubmodule(AttackAreaBase attackArea) : base(attackArea)
|
|
{
|
|
InitializeAsOnceHit();
|
|
CommonInitialize();
|
|
}
|
|
|
|
public HitSubmodule(AttackAreaBase attackArea, float hitInterval = -1, int hitCount = -1) : base(attackArea)
|
|
{
|
|
InitializeAsMultipleHit(hitInterval, hitCount);
|
|
CommonInitialize();
|
|
}
|
|
|
|
private void InitializeAsOnceHit()
|
|
{
|
|
this.originalHitCount = 1;
|
|
this.currentHitIndex = 0;
|
|
this.hitInterval = -1;
|
|
this.currentIntervalTime = 0;
|
|
}
|
|
|
|
private void InitializeAsMultipleHit(float hitInterval, int hitCount)
|
|
{
|
|
this.originalHitCount = hitCount;
|
|
this.currentHitIndex = 0;
|
|
this.hitInterval = hitInterval;
|
|
this.currentIntervalTime = 0;
|
|
}
|
|
|
|
private void CommonInitialize()
|
|
{
|
|
isAutoPlayHitSound = true;
|
|
checkedObjects = new List<GameObject>();
|
|
hitSoundList = new List<string>();
|
|
generalHitEventList = new List<Action<CharacterBase, Vector3>>();
|
|
specificHitEventList = new SortedList<int, Action<CharacterBase, Vector3>>();
|
|
}
|
|
}
|
|
|
|
public partial class HitSubmodule
|
|
{
|
|
public HitSubmodule AddHitSound(string soundName, AK.Wwise.Event soundEvent = null)
|
|
{
|
|
if (owner.itemSource != null)
|
|
{
|
|
soundEvent ??= owner.itemSource.audioContainer.soundEventDictionary[soundName];
|
|
}
|
|
else
|
|
{
|
|
soundEvent ??= owner.creator.audioSc.audioContainer.soundEventDictionary[soundName];
|
|
}
|
|
|
|
if (soundEvent == null)
|
|
{
|
|
Debug.LogWarning($"[HitSubmodule] Sound event '{soundName}' not found in audio container.");
|
|
return this;
|
|
}
|
|
|
|
attackArea.audioContainer.soundEventDictionary.TryAdd(soundName, soundEvent);
|
|
hitSoundList.Add(soundName);
|
|
return this;
|
|
}
|
|
|
|
public HitSubmodule AddHitEvent(Action<CharacterBase, Vector3> hitEvent)
|
|
{
|
|
generalHitEventList.Add(hitEvent);
|
|
return this;
|
|
}
|
|
|
|
public HitSubmodule AddHitEvent(Action<CharacterBase, Vector3> hitEvent, params int[] indexes)
|
|
{
|
|
foreach (int i in indexes)
|
|
{
|
|
specificHitEventList[i] = hitEvent;
|
|
}
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public partial class HitSubmodule
|
|
{
|
|
public void Update()
|
|
{
|
|
if (!isEnabling || currentHitIndex >= originalHitCount - 1 || attackArea.timeSm.delayTime > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
currentIntervalTime += attackArea.creator.selfTimeSm.DeltaTime;
|
|
if (currentIntervalTime >= hitInterval)
|
|
{
|
|
checkedObjects.Clear();
|
|
if (attackArea.attackSm != null)
|
|
{
|
|
//attackArea.attackSm.modifiedAttackValue = attackArea.attackSm.originalAttackValue;
|
|
}
|
|
currentIntervalTime -= hitInterval;
|
|
currentHitIndex++;
|
|
}
|
|
|
|
if (currentHitIndex >= originalHitCount - 1)
|
|
{
|
|
attackArea.isEnabling = false;
|
|
}
|
|
}
|
|
|
|
public void AddCheckedObject(GameObject obj)
|
|
{
|
|
checkedObjects.Add(obj);
|
|
}
|
|
|
|
public void PlayHitSound(Vector3 position, string soundName)
|
|
{
|
|
if (hitSoundList.Count == 0) return;
|
|
|
|
attackArea.audioContainer.PlaySoundFX(soundName, position);
|
|
}
|
|
|
|
public void InvokeAllHitEvents(CharacterBase target, Vector3 hitPosition)
|
|
{
|
|
if (attackArea.canTriggerHitEvent)
|
|
{
|
|
foreach (Action<CharacterBase, Vector3> hitEvent in generalHitEventList)
|
|
{
|
|
hitEvent.Invoke(target, hitPosition);
|
|
}
|
|
|
|
Debug.Log($"[HitSubmodule] Invoking specific hit event for hit index {currentHitIndex}.");
|
|
if (specificHitEventList.ContainsKey(currentHitIndex))
|
|
{
|
|
specificHitEventList[currentHitIndex].Invoke(target, hitPosition);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |