|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
|
|
|
|
public class Fire : ResourcePool
|
|
|
|
|
{
|
|
|
|
|
public Character character;
|
|
|
|
|
|
|
|
|
|
//[System.Serializable]
|
|
|
|
|
//public class FireEvent : UnityEvent<Projectile, Vector3> { }
|
|
|
|
|
//[FormerlySerializedAs("onFire")]
|
|
|
|
|
//[SerializeField]
|
|
|
|
|
//[Space(10)]
|
|
|
|
|
//private FireEvent onFire = new FireEvent();
|
|
|
|
|
Vector3 angle = new Vector3(0, 0, 90);
|
|
|
|
|
public bool OnFire(Vector3 dirShoot, bool DOUBLE = true)
|
|
|
|
|
{
|
|
|
|
|
if (dirShoot != Vector3.zero)
|
|
|
|
|
{
|
|
|
|
|
poss.Clear();
|
|
|
|
|
|
|
|
|
|
if (character.skill.Active("Fire", "MultiShot") != null)
|
|
|
|
|
{
|
|
|
|
|
transform.localEulerAngles = 1 <= Mathf.Abs(dirShoot.z) ? angle : Vector3.zero;
|
|
|
|
|
|
|
|
|
|
poss.Add(DOUBLE ? targetDouble[0].position : targetDouble2[0].position);
|
|
|
|
|
poss.Add(DOUBLE ? targetDouble[1].position : targetDouble2[1].position);
|
|
|
|
|
|
|
|
|
|
ProjectileCreate(prefabProjectile.gameObject, dirShoot, poss[0]);
|
|
|
|
|
ProjectileCreate(prefabProjectile.gameObject, dirShoot, poss[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
poss.Add(DOUBLE ? targetFire.position : targetFire2.position);
|
|
|
|
|
|
|
|
|
|
ProjectileCreate(prefabProjectile.gameObject, dirShoot, poss[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DOUBLE)
|
|
|
|
|
{
|
|
|
|
|
if (character.skill.Active("Fire", "DoubleShot") != null)
|
|
|
|
|
{
|
|
|
|
|
dirDouble = dirShoot;
|
|
|
|
|
Invoke("DoubleShot", 0.1f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Vector3 dirDouble;
|
|
|
|
|
List<Vector3> poss = new List<Vector3>();
|
|
|
|
|
void DoubleShot()
|
|
|
|
|
{
|
|
|
|
|
OnFire(dirDouble, false);
|
|
|
|
|
}
|
|
|
|
|
public void OnFire(int type, List<object> value)
|
|
|
|
|
{
|
|
|
|
|
Transform target = (Transform)value[0];
|
|
|
|
|
Vector3 dir = (Vector3)value[1];
|
|
|
|
|
|
|
|
|
|
Projectile projectile = ProjectileCreate((GameObject)value[2], dir, targetFire.position);
|
|
|
|
|
if (projectile != null)
|
|
|
|
|
{
|
|
|
|
|
//onFire.Invoke(projectile, dir);
|
|
|
|
|
projectile.TargetSet(target, (float)value[4]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public Transform targetFire;
|
|
|
|
|
public Transform targetFire2;
|
|
|
|
|
public List<Transform> targetDouble;
|
|
|
|
|
public List<Transform> targetDouble2;
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public Projectile prefabProjectile;
|
|
|
|
|
public Sprite spriteChanged;
|
|
|
|
|
Bundle<Projectile> dicProjectile = new Bundle<Projectile>();
|
|
|
|
|
public Projectile ProjectileCreate(GameObject prefab, Vector3 dir, Vector3 targetFire)
|
|
|
|
|
{
|
|
|
|
|
GameObject obj = character.map.ObjectCreate(prefab.gameObject, null, Vector3.one, targetFire);
|
|
|
|
|
|
|
|
|
|
Projectile projectile = dicProjectile.Get(obj.name);
|
|
|
|
|
if (projectile == null)
|
|
|
|
|
{
|
|
|
|
|
projectile = obj.GetComponent<Projectile>();
|
|
|
|
|
dicProjectile.Add(projectile.name, projectile);
|
|
|
|
|
}
|
|
|
|
|
if (projectile.spriteRenderer != null && spriteChanged != null)
|
|
|
|
|
projectile.spriteRenderer.sprite = spriteChanged;
|
|
|
|
|
|
|
|
|
|
//onFire.Invoke(projectile, dir);
|
|
|
|
|
//character.ProjectileCreate(projectile, dir);
|
|
|
|
|
projectile.spdMovePer = character.SPDATK_PER;
|
|
|
|
|
projectile.OnInitialized(character, character.layerEnemy, dir, character.RANGE);
|
|
|
|
|
|
|
|
|
|
return projectile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<string, Projectile> dicWeapon = new Dictionary<string, Projectile>();
|
|
|
|
|
public void OnWeaponChanged(EquipData equip)
|
|
|
|
|
{
|
|
|
|
|
if(prefabProjectile != null)
|
|
|
|
|
{
|
|
|
|
|
//character.ATK -= (int)prefabProjectile.ATK;
|
|
|
|
|
character.ATKChanged(-(int)prefabProjectile.ATK, true);//플레이어 무기해제, 현재 장착중인 무기의 공격력만큼 하락
|
|
|
|
|
character.DelayAttackChanged(-prefabProjectile.DLAATK, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//현재는 이미지만 바꾸지만 같은 타임이어도 여러가지 달라질수 있으니 이미지가 아닌 프리팹 자체를 변경하게끔 하는 수정이 필요
|
|
|
|
|
string key = $"Projectile {equip.type2}";
|
|
|
|
|
if (dicWeapon.ContainsKey(key))
|
|
|
|
|
{
|
|
|
|
|
prefabProjectile = dicWeapon[key];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
prefabProjectile = PrefabManager.Instance.PrefabGet(key).GetComponent<Projectile>();
|
|
|
|
|
dicWeapon.Add(key, prefabProjectile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefabProjectile != null)
|
|
|
|
|
{
|
|
|
|
|
//prefabProjectile.spriteRenderer.sprite = equip.sprite;
|
|
|
|
|
spriteChanged = equip.sprite;
|
|
|
|
|
|
|
|
|
|
character.ATKChanged((int)prefabProjectile.ATK, true);//플레이어 무기장착, 장착할 무기의 공격력만큼 상승
|
|
|
|
|
character.DelayAttackChanged(prefabProjectile.DLAATK, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|