vfx controller, fire method in weapon
This commit is contained in:
parent
6224ac3354
commit
7c5979e6a9
@ -13,7 +13,7 @@ MonoBehaviour:
|
||||
m_Name: UnitsData
|
||||
m_EditorClassIdentifier:
|
||||
_units:
|
||||
- isPlayer: 0
|
||||
- isPlayer: 1
|
||||
spawnPos:
|
||||
x: 19
|
||||
z: 4
|
||||
|
@ -27,6 +27,7 @@ namespace Controller
|
||||
|
||||
var hexGrid = new HexGrid(data.FieldData);
|
||||
new MusicController();
|
||||
new VFXController(data.VFXData);
|
||||
MusicController.Instance.SetMusicData(data.MusicData);
|
||||
controllers.Add(hexGrid);
|
||||
|
||||
|
@ -22,10 +22,23 @@ namespace Data
|
||||
private MusicData _musicData;
|
||||
[SerializeField] private string itemDataPath;
|
||||
private ItemsData _itemsData;
|
||||
[SerializeField] private string vfxDataPath;
|
||||
private VFXData _vfxData;
|
||||
[SerializeField] private string 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
|
||||
{
|
||||
get
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DefaultNamespace;
|
||||
using Items;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
@ -30,7 +31,6 @@ namespace HexFiled
|
||||
private void Awake()
|
||||
{
|
||||
_renderer = GetComponent<MeshRenderer>();
|
||||
MusicController.Instance.AddAudioSource(gameObject);
|
||||
_color = UnitColor.GREY;
|
||||
if (!HexManager.CellByColor.ContainsKey(_color))
|
||||
{
|
||||
@ -88,9 +88,12 @@ namespace HexFiled
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -65,21 +65,7 @@ public class TowerView : MonoBehaviour
|
||||
yield return null;
|
||||
}
|
||||
var direction = DirectionHelper.DirectionTo(transform.position, _target.transform.position);
|
||||
var ball = Instantiate(weapon.objectToThrow,
|
||||
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));
|
||||
weapon.Fire(transform, new Vector2(direction.x, direction.z));
|
||||
}
|
||||
}
|
||||
}
|
@ -49,6 +49,7 @@ public class MusicController
|
||||
|
||||
public void RemoveAudioSource(GameObject gameObject)
|
||||
{
|
||||
_sources.Remove(gameObject);
|
||||
if(_sources.ContainsKey(gameObject))
|
||||
_sources.Remove(gameObject);
|
||||
}
|
||||
}
|
@ -38,13 +38,18 @@ namespace Units
|
||||
private int _defenceBonus;
|
||||
|
||||
|
||||
public bool IsBusy { get => _isBusy; set => _isBusy = value; }
|
||||
public bool IsBusy
|
||||
{
|
||||
get => _isBusy;
|
||||
set => _isBusy = value;
|
||||
}
|
||||
|
||||
public UnitView UnitView => _unitView;
|
||||
public bool IsAlive => _isAlive;
|
||||
public UnitColor Color => _data.color;
|
||||
public int InventoryCapacity => _data.inventoryCapacity;
|
||||
public Action<Item> OnItemPickUp;
|
||||
public Action<Unit> OnDeath;
|
||||
public Action<Unit> OnDeath;
|
||||
public BarCanvas BarCanvas => _barCanvas;
|
||||
|
||||
public UnitInfo Data => _data;
|
||||
@ -85,9 +90,10 @@ namespace Units
|
||||
public void Move(HexDirection direction)
|
||||
{
|
||||
if (!_cell.GetNeighbor(direction) || _isBusy || _cell.GetNeighbor(direction).Color != UnitColor.GREY &&
|
||||
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell == _cell.GetNeighbor(direction)) return;
|
||||
|
||||
if(_data.isPlayer)
|
||||
HexManager.UnitCurrentCell[_cell.GetNeighbor(direction).Color].cell ==
|
||||
_cell.GetNeighbor(direction)) return;
|
||||
|
||||
if (_data.isPlayer)
|
||||
Debug.Log("Player");
|
||||
_unitView.StopHardCapture();
|
||||
if (_cell.GetNeighbor(direction).Color == _data.color)
|
||||
@ -96,14 +102,14 @@ namespace Units
|
||||
}
|
||||
else if (_cell.GetNeighbor(direction).Color != UnitColor.GREY)
|
||||
{
|
||||
if( _mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||
_isHardToCapture = true;
|
||||
DoTransit(direction);
|
||||
}
|
||||
|
||||
else if (_mana - _hexGrid.HexCaptureCost >= 0)
|
||||
{
|
||||
if( _mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
|
||||
DoTransit(direction);
|
||||
}
|
||||
}
|
||||
@ -113,7 +119,7 @@ namespace Units
|
||||
_isBusy = true;
|
||||
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
|
||||
_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,
|
||||
(_cell.transform.position - _instance.transform.position).normalized.z));
|
||||
_animator.SetTrigger("Move");
|
||||
@ -131,6 +137,7 @@ namespace Units
|
||||
{
|
||||
_mana -= _hexGrid.HexCaptureCost;
|
||||
}
|
||||
|
||||
_unitView.RegenMana(_mana);
|
||||
UpdateBarCanvas();
|
||||
_isBusy = false;
|
||||
@ -171,14 +178,13 @@ namespace Units
|
||||
{
|
||||
var neigh = _cell.GetNeighbor((HexDirection)i);
|
||||
neigh?.PaintHex(_data.color);
|
||||
|
||||
}
|
||||
|
||||
|
||||
HexManager.UnitCurrentCell.Add(_data.color, (_cell, this));
|
||||
|
||||
_instance = Object.Instantiate(_data.unitPrefa, _cell.transform.parent);
|
||||
_instance.transform.localPosition = _cell.transform.localPosition;
|
||||
|
||||
|
||||
_isAlive = true;
|
||||
_animator = _instance.GetComponent<Animator>();
|
||||
_unitView = _instance.GetComponent<UnitView>();
|
||||
@ -222,7 +228,7 @@ namespace Units
|
||||
{
|
||||
_isBusy = false;
|
||||
_animator.SetBool("isMoving", _isBusy);
|
||||
|
||||
|
||||
if (!_isCapturing)
|
||||
{
|
||||
return;
|
||||
@ -235,7 +241,6 @@ namespace Units
|
||||
else
|
||||
{
|
||||
CaptureHex();
|
||||
|
||||
}
|
||||
|
||||
_isHardToCapture = false;
|
||||
@ -255,19 +260,7 @@ namespace Units
|
||||
Aim(_direction);
|
||||
}
|
||||
|
||||
var ball = Object.Instantiate(_weapon.objectToThrow,
|
||||
_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));
|
||||
_weapon.Fire(_instance.transform, _direction);
|
||||
}
|
||||
|
||||
private void SetUpActions()
|
||||
@ -302,12 +295,11 @@ namespace Units
|
||||
_isAlive = false;
|
||||
HexManager.UnitCurrentCell.Remove(Color);
|
||||
_animator.SetTrigger("Death");
|
||||
TimerHelper.Instance.StartTimer(()=>{Object.Destroy(_instance);}, _animLength.Death);
|
||||
TimerHelper.Instance.StartTimer(() => { Object.Destroy(_instance); }, _animLength.Death);
|
||||
OnDeath?.Invoke(this);
|
||||
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, _instance);
|
||||
MusicController.Instance.RemoveAudioSource(_instance);
|
||||
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.GREY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using DefaultNamespace;
|
||||
using DG.Tweening;
|
||||
using HexFiled;
|
||||
using Items;
|
||||
@ -117,7 +118,7 @@ public class UnitView : MonoBehaviour
|
||||
MusicController.Instance.MusicData.SfxMusic.Step, gameObject);
|
||||
}
|
||||
|
||||
private void AttackEnd()
|
||||
private void AttackEnd() // Методы выполняемые из аниматора
|
||||
{
|
||||
OnAttackEnd?.Invoke();
|
||||
}
|
||||
@ -133,6 +134,10 @@ public class UnitView : MonoBehaviour
|
||||
if (weaponView != null)
|
||||
{
|
||||
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();
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
|
@ -20,5 +20,19 @@ namespace DefaultNamespace
|
||||
Instance ??= this;
|
||||
_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
|
||||
{
|
||||
private ParticleSystem _system;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_system = GetComponent<ParticleSystem>();
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_system.isStopped)
|
||||
if (_system != null && _system.isStopped)
|
||||
{
|
||||
MusicController.Instance.RemoveAudioSource(gameObject);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
MusicController.Instance.RemoveAudioSource(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using DefaultNamespace;
|
||||
using DG.Tweening;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Weapons
|
||||
{
|
||||
@ -23,5 +27,28 @@ namespace Weapons
|
||||
{
|
||||
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 Weapons;
|
||||
|
||||
public class WeaponView : MonoBehaviour
|
||||
namespace Weapons
|
||||
{
|
||||
private Weapon _weapon;
|
||||
|
||||
public Weapon Weapon => _weapon;
|
||||
|
||||
public void SetWeapon(Weapon weapon)
|
||||
public class WeaponView : MonoBehaviour
|
||||
{
|
||||
_weapon = weapon;
|
||||
}
|
||||
public Weapon Weapon { get; private set; }
|
||||
|
||||
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);
|
||||
public void SetWeapon(Weapon weapon)
|
||||
{
|
||||
Weapon = weapon;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user