vfx controller, fire method in weapon
This commit is contained in:
parent
6224ac3354
commit
7c5979e6a9
@ -13,7 +13,7 @@ MonoBehaviour:
|
|||||||
m_Name: UnitsData
|
m_Name: UnitsData
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_units:
|
_units:
|
||||||
- isPlayer: 0
|
- isPlayer: 1
|
||||||
spawnPos:
|
spawnPos:
|
||||||
x: 19
|
x: 19
|
||||||
z: 4
|
z: 4
|
||||||
|
@ -27,6 +27,7 @@ namespace Controller
|
|||||||
|
|
||||||
var hexGrid = new HexGrid(data.FieldData);
|
var hexGrid = new HexGrid(data.FieldData);
|
||||||
new MusicController();
|
new MusicController();
|
||||||
|
new VFXController(data.VFXData);
|
||||||
MusicController.Instance.SetMusicData(data.MusicData);
|
MusicController.Instance.SetMusicData(data.MusicData);
|
||||||
controllers.Add(hexGrid);
|
controllers.Add(hexGrid);
|
||||||
|
|
||||||
|
@ -22,10 +22,23 @@ namespace Data
|
|||||||
private MusicData _musicData;
|
private MusicData _musicData;
|
||||||
[SerializeField] private string itemDataPath;
|
[SerializeField] private string itemDataPath;
|
||||||
private ItemsData _itemsData;
|
private ItemsData _itemsData;
|
||||||
|
[SerializeField] private string vfxDataPath;
|
||||||
|
private VFXData _vfxData;
|
||||||
[SerializeField] private string chosenWeaponDataPath;
|
[SerializeField] private string chosenWeaponDataPath;
|
||||||
|
|
||||||
public string ChosenWeapon => File.ReadAllText(Application.persistentDataPath + "/" + chosenWeaponDataPath);
|
public string ChosenWeapon => File.ReadAllText(Application.persistentDataPath + "/" + chosenWeaponDataPath);
|
||||||
|
|
||||||
|
public VFXData VFXData {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_vfxData == null)
|
||||||
|
{
|
||||||
|
_vfxData = Load<VFXData>("Data/" + vfxDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _vfxData;
|
||||||
|
}
|
||||||
|
}
|
||||||
public ItemsData ItemsData
|
public ItemsData ItemsData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using DefaultNamespace;
|
||||||
using Items;
|
using Items;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
@ -30,7 +31,6 @@ namespace HexFiled
|
|||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
_renderer = GetComponent<MeshRenderer>();
|
_renderer = GetComponent<MeshRenderer>();
|
||||||
MusicController.Instance.AddAudioSource(gameObject);
|
|
||||||
_color = UnitColor.GREY;
|
_color = UnitColor.GREY;
|
||||||
if (!HexManager.CellByColor.ContainsKey(_color))
|
if (!HexManager.CellByColor.ContainsKey(_color))
|
||||||
{
|
{
|
||||||
@ -88,9 +88,12 @@ namespace HexFiled
|
|||||||
HexManager.CellByColor[_color].Add(this);
|
HexManager.CellByColor[_color].Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures,
|
|
||||||
gameObject);
|
|
||||||
Instantiate(HexGrid.Colors[color].VFXPrefab, transform);
|
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[color].VFXPrefab, transform.position + new Vector3(0,0.1f,0));
|
||||||
|
MusicController.Instance.AddAudioSource(vfx);
|
||||||
|
MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures, vfx);
|
||||||
|
|
||||||
onHexPainted?.Invoke(this);
|
onHexPainted?.Invoke(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,21 +65,7 @@ public class TowerView : MonoBehaviour
|
|||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
var direction = DirectionHelper.DirectionTo(transform.position, _target.transform.position);
|
var direction = DirectionHelper.DirectionTo(transform.position, _target.transform.position);
|
||||||
var ball = Instantiate(weapon.objectToThrow,
|
weapon.Fire(transform, new Vector2(direction.x, direction.z));
|
||||||
transform.forward + transform.position + new Vector3(0, 1),
|
|
||||||
Quaternion.LookRotation(direction));
|
|
||||||
|
|
||||||
MusicController.Instance.AddAudioSource(ball);
|
|
||||||
MusicController.Instance.PlayAudioClip(weapon.shotSound, ball);
|
|
||||||
|
|
||||||
ball.AddComponent<WeaponView>().SetWeapon(weapon);
|
|
||||||
ball.transform.DOMove(
|
|
||||||
new Vector3(direction.x,
|
|
||||||
0, direction.z) * weapon.disnatce * HexGrid.HexDistance +
|
|
||||||
transform.position + new Vector3(0, 1, 0),
|
|
||||||
weapon.speed)
|
|
||||||
.SetEase(Ease.Linear)
|
|
||||||
.OnComplete(() => Destroy(ball));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,6 +49,7 @@ public class MusicController
|
|||||||
|
|
||||||
public void RemoveAudioSource(GameObject gameObject)
|
public void RemoveAudioSource(GameObject gameObject)
|
||||||
{
|
{
|
||||||
_sources.Remove(gameObject);
|
if(_sources.ContainsKey(gameObject))
|
||||||
|
_sources.Remove(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,7 +38,12 @@ namespace Units
|
|||||||
private int _defenceBonus;
|
private int _defenceBonus;
|
||||||
|
|
||||||
|
|
||||||
public bool IsBusy { get => _isBusy; set => _isBusy = value; }
|
public bool IsBusy
|
||||||
|
{
|
||||||
|
get => _isBusy;
|
||||||
|
set => _isBusy = value;
|
||||||
|
}
|
||||||
|
|
||||||
public UnitView UnitView => _unitView;
|
public UnitView UnitView => _unitView;
|
||||||
public bool IsAlive => _isAlive;
|
public bool IsAlive => _isAlive;
|
||||||
public UnitColor Color => _data.color;
|
public UnitColor Color => _data.color;
|
||||||
@ -85,9 +90,10 @@ namespace Units
|
|||||||
public void Move(HexDirection direction)
|
public void Move(HexDirection direction)
|
||||||
{
|
{
|
||||||
if (!_cell.GetNeighbor(direction) || _isBusy || _cell.GetNeighbor(direction).Color != UnitColor.GREY &&
|
if (!_cell.GetNeighbor(direction) || _isBusy || _cell.GetNeighbor(direction).Color != UnitColor.GREY &&
|
||||||
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell == _cell.GetNeighbor(direction)) return;
|
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell ==
|
||||||
|
_cell.GetNeighbor(direction)) return;
|
||||||
|
|
||||||
if(_data.isPlayer)
|
if (_data.isPlayer)
|
||||||
Debug.Log("Player");
|
Debug.Log("Player");
|
||||||
_unitView.StopHardCapture();
|
_unitView.StopHardCapture();
|
||||||
if (_cell.GetNeighbor(direction).Color == _data.color)
|
if (_cell.GetNeighbor(direction).Color == _data.color)
|
||||||
@ -96,14 +102,14 @@ namespace Units
|
|||||||
}
|
}
|
||||||
else if (_cell.GetNeighbor(direction).Color != UnitColor.GREY)
|
else if (_cell.GetNeighbor(direction).Color != UnitColor.GREY)
|
||||||
{
|
{
|
||||||
if( _mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||||
_isHardToCapture = true;
|
_isHardToCapture = true;
|
||||||
DoTransit(direction);
|
DoTransit(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (_mana - _hexGrid.HexCaptureCost >= 0)
|
else if (_mana - _hexGrid.HexCaptureCost >= 0)
|
||||||
{
|
{
|
||||||
if( _mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||||
DoTransit(direction);
|
DoTransit(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +119,7 @@ namespace Units
|
|||||||
_isBusy = true;
|
_isBusy = true;
|
||||||
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
|
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
|
||||||
_cell = _cell.GetNeighbor(direction);
|
_cell = _cell.GetNeighbor(direction);
|
||||||
HexManager.UnitCurrentCell[_data.color] = ( _cell, this );
|
HexManager.UnitCurrentCell[_data.color] = (_cell, this);
|
||||||
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
||||||
(_cell.transform.position - _instance.transform.position).normalized.z));
|
(_cell.transform.position - _instance.transform.position).normalized.z));
|
||||||
_animator.SetTrigger("Move");
|
_animator.SetTrigger("Move");
|
||||||
@ -131,6 +137,7 @@ namespace Units
|
|||||||
{
|
{
|
||||||
_mana -= _hexGrid.HexCaptureCost;
|
_mana -= _hexGrid.HexCaptureCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
_unitView.RegenMana(_mana);
|
_unitView.RegenMana(_mana);
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
@ -171,7 +178,6 @@ namespace Units
|
|||||||
{
|
{
|
||||||
var neigh = _cell.GetNeighbor((HexDirection)i);
|
var neigh = _cell.GetNeighbor((HexDirection)i);
|
||||||
neigh?.PaintHex(_data.color);
|
neigh?.PaintHex(_data.color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HexManager.UnitCurrentCell.Add(_data.color, (_cell, this));
|
HexManager.UnitCurrentCell.Add(_data.color, (_cell, this));
|
||||||
@ -235,7 +241,6 @@ namespace Units
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CaptureHex();
|
CaptureHex();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_isHardToCapture = false;
|
_isHardToCapture = false;
|
||||||
@ -255,19 +260,7 @@ namespace Units
|
|||||||
Aim(_direction);
|
Aim(_direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ball = Object.Instantiate(_weapon.objectToThrow,
|
_weapon.Fire(_instance.transform, _direction);
|
||||||
_instance.transform.forward + _instance.transform.position + new Vector3(0, 2),
|
|
||||||
_instance.transform.rotation);
|
|
||||||
MusicController.Instance.AddAudioSource(ball);
|
|
||||||
MusicController.Instance.PlayAudioClip(_weapon.shotSound, ball);
|
|
||||||
ball.AddComponent<WeaponView>().SetWeapon(_weapon);
|
|
||||||
ball.transform.DOMove(
|
|
||||||
new Vector3(_direction.normalized.x,
|
|
||||||
0, _direction.normalized.y) * _weapon.disnatce * HexGrid.HexDistance +
|
|
||||||
_instance.transform.position + new Vector3(0, 2, 0),
|
|
||||||
_weapon.speed)
|
|
||||||
.SetEase(Ease.Linear)
|
|
||||||
.OnComplete(() => Object.Destroy(ball));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetUpActions()
|
private void SetUpActions()
|
||||||
@ -302,12 +295,11 @@ namespace Units
|
|||||||
_isAlive = false;
|
_isAlive = false;
|
||||||
HexManager.UnitCurrentCell.Remove(Color);
|
HexManager.UnitCurrentCell.Remove(Color);
|
||||||
_animator.SetTrigger("Death");
|
_animator.SetTrigger("Death");
|
||||||
TimerHelper.Instance.StartTimer(()=>{Object.Destroy(_instance);}, _animLength.Death);
|
TimerHelper.Instance.StartTimer(() => { Object.Destroy(_instance); }, _animLength.Death);
|
||||||
OnDeath?.Invoke(this);
|
OnDeath?.Invoke(this);
|
||||||
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, _instance);
|
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, _instance);
|
||||||
MusicController.Instance.RemoveAudioSource(_instance);
|
MusicController.Instance.RemoveAudioSource(_instance);
|
||||||
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.GREY);
|
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.GREY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Data;
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
using HexFiled;
|
using HexFiled;
|
||||||
using Items;
|
using Items;
|
||||||
@ -117,7 +118,7 @@ public class UnitView : MonoBehaviour
|
|||||||
MusicController.Instance.MusicData.SfxMusic.Step, gameObject);
|
MusicController.Instance.MusicData.SfxMusic.Step, gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AttackEnd()
|
private void AttackEnd() // Методы выполняемые из аниматора
|
||||||
{
|
{
|
||||||
OnAttackEnd?.Invoke();
|
OnAttackEnd?.Invoke();
|
||||||
}
|
}
|
||||||
@ -133,6 +134,10 @@ public class UnitView : MonoBehaviour
|
|||||||
if (weaponView != null)
|
if (weaponView != null)
|
||||||
{
|
{
|
||||||
OnHit?.Invoke(weaponView.Weapon.modifiedDamage);
|
OnHit?.Invoke(weaponView.Weapon.modifiedDamage);
|
||||||
|
var vfx = VFXController.Instance.PlayEffect(weaponView.Weapon.VFXGameObject, weaponView.transform);
|
||||||
|
MusicController.Instance.AddAudioSource(vfx);
|
||||||
|
MusicController.Instance.PlayAudioClip(weaponView.Weapon.hitSound, vfx);
|
||||||
|
|
||||||
other.transform.DOKill();
|
other.transform.DOKill();
|
||||||
Destroy(other.gameObject);
|
Destroy(other.gameObject);
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,19 @@ namespace DefaultNamespace
|
|||||||
Instance ??= this;
|
Instance ??= this;
|
||||||
_data = data;
|
_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameObject PlayEffect(GameObject effect, Vector3 pos)
|
||||||
|
{
|
||||||
|
var obj = Object.Instantiate(effect, pos, effect.transform.rotation);
|
||||||
|
obj.AddComponent<VFXView>();
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject PlayEffect(GameObject effect, Transform pos)
|
||||||
|
{
|
||||||
|
var obj = Object.Instantiate(effect, pos.position, pos.rotation);
|
||||||
|
obj.AddComponent<VFXView>();
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,23 +6,19 @@ namespace DefaultNamespace
|
|||||||
public class VFXView : MonoBehaviour
|
public class VFXView : MonoBehaviour
|
||||||
{
|
{
|
||||||
private ParticleSystem _system;
|
private ParticleSystem _system;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
_system = GetComponent<ParticleSystem>();
|
_system = GetComponent<ParticleSystem>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (_system.isStopped)
|
if (_system != null && _system.isStopped)
|
||||||
{
|
{
|
||||||
|
MusicController.Instance.RemoveAudioSource(gameObject);
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
MusicController.Instance.RemoveAudioSource(gameObject);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using DefaultNamespace;
|
||||||
|
using DG.Tweening;
|
||||||
|
using HexFiled;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Weapons
|
namespace Weapons
|
||||||
{
|
{
|
||||||
@ -23,5 +27,28 @@ namespace Weapons
|
|||||||
{
|
{
|
||||||
modifiedDamage = damage + bonus;
|
modifiedDamage = damage + bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Fire(Transform start, Vector2 direction)
|
||||||
|
{
|
||||||
|
var ball = Object.Instantiate(objectToThrow,
|
||||||
|
start.forward + start.transform.position + new Vector3(0, 2),
|
||||||
|
start.rotation);
|
||||||
|
|
||||||
|
MusicController.Instance.AddAudioSource(ball);
|
||||||
|
MusicController.Instance.PlayAudioClip(shotSound, ball);
|
||||||
|
ball.AddComponent<WeaponView>().SetWeapon(this);
|
||||||
|
Weapon tmpThis = this;
|
||||||
|
ball.transform.DOMove(new Vector3(direction.normalized.x,
|
||||||
|
0, direction.normalized.y) * tmpThis.disnatce * HexGrid.HexDistance +
|
||||||
|
start.position + new Vector3(0, 2, 0), tmpThis.speed)
|
||||||
|
.SetEase(Ease.Linear)
|
||||||
|
.OnComplete(() =>
|
||||||
|
{
|
||||||
|
var vfx = VFXController.Instance.PlayEffect(tmpThis.VFXGameObject, ball.transform);
|
||||||
|
MusicController.Instance.AddAudioSource(vfx);
|
||||||
|
MusicController.Instance.PlayAudioClip(tmpThis.hitSound, vfx);
|
||||||
|
Object.Destroy(ball);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +1,17 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Data;
|
|
||||||
using DefaultNamespace;
|
|
||||||
using DefaultNamespace.Weapons;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Weapons;
|
|
||||||
|
|
||||||
public class WeaponView : MonoBehaviour
|
namespace Weapons
|
||||||
{
|
{
|
||||||
private Weapon _weapon;
|
public class WeaponView : MonoBehaviour
|
||||||
|
|
||||||
public Weapon Weapon => _weapon;
|
|
||||||
|
|
||||||
public void SetWeapon(Weapon weapon)
|
|
||||||
{
|
{
|
||||||
_weapon = weapon;
|
public Weapon Weapon { get; private set; }
|
||||||
}
|
|
||||||
|
public void SetWeapon(Weapon weapon)
|
||||||
|
{
|
||||||
|
Weapon = weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
var go = Instantiate(_weapon.VFXGameObject, transform.position, transform.rotation);
|
|
||||||
go.AddComponent<VFXView>();
|
|
||||||
MusicController.Instance.AddAudioSource(go);
|
|
||||||
MusicController.Instance.RemoveAudioSource(gameObject);
|
|
||||||
MusicController.Instance.PlayAudioClip(_weapon.hitSound, go);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user