fixed despawn items. added ISetUp.cs for building views
This commit is contained in:
parent
5ea371e08d
commit
896a1dae28
@ -15,13 +15,21 @@ namespace HexFiled
|
||||
|
||||
|
||||
[SerializeField] private HexCell[] neighbors;
|
||||
private Item _item;
|
||||
[SerializeField] private Item _item;
|
||||
private UnitColor _color;
|
||||
private MeshRenderer _renderer;
|
||||
|
||||
public UnitColor Color => _color;
|
||||
|
||||
public Item Item => _item;
|
||||
public Item Item
|
||||
{
|
||||
get => _item;
|
||||
set
|
||||
{
|
||||
if (_item == null)
|
||||
_item = value;
|
||||
}
|
||||
}
|
||||
private GameObject _building;
|
||||
|
||||
public GameObject Building
|
||||
@ -50,10 +58,7 @@ namespace HexFiled
|
||||
}
|
||||
}
|
||||
|
||||
public void SetItem(Item item)
|
||||
{
|
||||
_item = item == _item ? null : item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<HexCell> GetListNeighbours()
|
||||
@ -87,14 +92,14 @@ namespace HexFiled
|
||||
HexManager.CellByColor[previousColor].Remove(this);
|
||||
_color = color;
|
||||
HexManager.CellByColor[_color].Add(this);
|
||||
|
||||
OnHexPainted?.Invoke(this);
|
||||
if(color == UnitColor.Grey) return;
|
||||
|
||||
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[color].VFXCellCapturePrefab, transform.position + new Vector3(0,0.1f,0));
|
||||
MusicController.Instance.AddAudioSource(vfx);
|
||||
MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures, vfx);
|
||||
|
||||
OnHexPainted?.Invoke(this);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -123,12 +123,12 @@ namespace HexFiled
|
||||
}
|
||||
|
||||
|
||||
// #if UNITY_EDITOR
|
||||
// TMP_Text label = Object.Instantiate(_fieldData.cellLabelPrefab, _gridCanvas.transform, false);
|
||||
// label.rectTransform.anchoredPosition =
|
||||
// new Vector2(position.x, position.z);
|
||||
// label.text = cell.coordinates.ToStringOnSeparateLines();
|
||||
// #endif
|
||||
#if UNITY_EDITOR
|
||||
TMP_Text label = Object.Instantiate(_fieldData.cellLabelPrefab, _gridCanvas.transform, false);
|
||||
label.rectTransform.anchoredPosition =
|
||||
new Vector2(position.x, position.z);
|
||||
label.text = cell.coordinates.ToStringOnSeparateLines();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,18 +17,7 @@ namespace HexFiled
|
||||
HexManager.UnitCurrentCell = new Dictionary<UnitColor, (HexCell cell, Unit unit)>();
|
||||
}
|
||||
|
||||
public void PaintOnDeath(Unit unit)
|
||||
{
|
||||
HexManager.PaintHexList(HexManager.CellByColor[unit.Color], UnitColor.Grey);
|
||||
// #if UNITY_EDITOR
|
||||
//
|
||||
//
|
||||
// if (HexManager.UnitCurrentCell.Count == 1)
|
||||
// {
|
||||
// SceneManager.LoadScene(1);
|
||||
// }
|
||||
// #endif
|
||||
}
|
||||
|
||||
public void CheckDeathOrDestroy(HexCell cell)
|
||||
{
|
||||
HexManager.UnitCurrentCell
|
||||
|
@ -20,10 +20,10 @@ namespace Items
|
||||
public void PlaceItem(HexCell cell)
|
||||
{
|
||||
Unit.UseItem(this);
|
||||
var obj = GameObject.Instantiate(buildingPrefab,
|
||||
var obj = Instantiate(buildingPrefab,
|
||||
cell.transform.position + buildingPrefab.transform.position, Quaternion.identity);
|
||||
obj.GetComponent<TowerView>()?.SetUp(Unit.Color);
|
||||
obj.GetComponent<BombView>()?.SetUp(Unit);
|
||||
obj.GetComponent<ISetUp>().SetUp(Unit);
|
||||
|
||||
cell.Building = obj;
|
||||
OnItemUsed.Invoke();
|
||||
OnItemUsed = null;
|
||||
|
9
Assets/Scripts/Items/ISetUp.cs
Normal file
9
Assets/Scripts/Items/ISetUp.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Units;
|
||||
|
||||
namespace Items
|
||||
{
|
||||
public interface ISetUp
|
||||
{
|
||||
public void SetUp(Unit unit);
|
||||
}
|
||||
}
|
3
Assets/Scripts/Items/ISetUp.cs.meta
Normal file
3
Assets/Scripts/Items/ISetUp.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70c0a37f5f0f4fd3be4c467b404cfa82
|
||||
timeCreated: 1643646005
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using DefaultNamespace;
|
||||
using HexFiled;
|
||||
using Units;
|
||||
@ -30,7 +31,7 @@ namespace Items
|
||||
[SerializeField] private Sprite icon;
|
||||
[SerializeField] private bool isInvokeOnPickUp = false;
|
||||
[SerializeField] private ItemType type;
|
||||
|
||||
|
||||
public ItemType Type => type;
|
||||
|
||||
public bool IsInvokeOnPickUp => isInvokeOnPickUp;
|
||||
@ -46,6 +47,7 @@ namespace Items
|
||||
{
|
||||
_instance = GameObject.Instantiate(iconPrefab, cell.transform.position + new Vector3(0, 1, 0),Quaternion.identity, parent.transform);
|
||||
_instance.AddComponent<ItemView>().SetUp(this);
|
||||
cell.Item = this;
|
||||
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
|
||||
return _instance;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace Items
|
||||
|
||||
var item = _data.ItemInfos[i].Item;
|
||||
Items.Add(item.Spawn(cell, _itemParrant, itemIcon[item.Type]), cell);
|
||||
cell.SetItem(_data.ItemInfos[i].Item);
|
||||
|
||||
_spawnTime = Random.Range(_data.SpawnTime.from, _data.SpawnTime.to);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace Items
|
||||
{
|
||||
public class BombView : MonoBehaviour
|
||||
public class BombView : MonoBehaviour, ISetUp
|
||||
{
|
||||
[SerializeField] private int damage;
|
||||
[SerializeField] private GameObject hit;
|
||||
|
@ -5,11 +5,12 @@ using System.Linq;
|
||||
using DefaultNamespace;
|
||||
using DG.Tweening;
|
||||
using HexFiled;
|
||||
using Items;
|
||||
using Units;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
|
||||
public class TowerView : MonoBehaviour
|
||||
public class TowerView : MonoBehaviour, ISetUp
|
||||
{
|
||||
[Serializable]
|
||||
internal struct Crystal
|
||||
@ -28,11 +29,11 @@ public class TowerView : MonoBehaviour
|
||||
|
||||
public UnitColor Color => _color;
|
||||
|
||||
public void SetUp(UnitColor unitColor)
|
||||
public void SetUp(Unit unit)
|
||||
{
|
||||
_color = unitColor;
|
||||
_color = unit.Color;
|
||||
|
||||
crystals.First(x => x.UnitColor == unitColor).GameObject.SetActive(true);
|
||||
crystals.First(x => x.UnitColor == (unit.Color)).GameObject.SetActive(true);
|
||||
var capsule = gameObject.AddComponent<CapsuleCollider>();
|
||||
capsule.radius = weapon.disnatce * HexGrid.HexDistance;
|
||||
}
|
||||
@ -71,4 +72,6 @@ public class TowerView : MonoBehaviour
|
||||
weapon.Fire(transform, new Vector2(direction.x, direction.z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -329,6 +329,7 @@ namespace Units
|
||||
_unitView.OnHit -= Damage;
|
||||
_isAlive = false;
|
||||
_isBusy = true;
|
||||
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.Grey);
|
||||
HexManager.UnitCurrentCell.Remove(Color);
|
||||
_animator.SetTrigger("Death");
|
||||
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[Color].VFXDeathPrefab,
|
||||
|
@ -63,7 +63,7 @@ namespace Chars
|
||||
player.OnDeath += unit => _uiController.CheatMenu.OnPlayerDeath();
|
||||
|
||||
player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this);
|
||||
player.OnDeath += _paintedController.PaintOnDeath;
|
||||
|
||||
player.Spawn(unitInfo.spawnPos);
|
||||
}
|
||||
else
|
||||
@ -75,7 +75,7 @@ namespace Chars
|
||||
AIAgent agent = new AIAgent(unitInfo, enemy);
|
||||
//enemy.OnPlayerSpawned += x => _controllers.Add(agent);
|
||||
enemy.OnDeath += x => { _controllers.Remove(agent); };
|
||||
enemy.OnDeath += _paintedController.PaintOnDeath;
|
||||
|
||||
enemy.Spawn(unitInfo.spawnPos);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user