fixed item despawn
This commit is contained in:
parent
9ca0f33ceb
commit
76e280dfad
@ -15,3 +15,4 @@ MonoBehaviour:
|
|||||||
icon: {fileID: 21300000, guid: c455216bc89f6c54d90211b86a5cf0e6, type: 3}
|
icon: {fileID: 21300000, guid: c455216bc89f6c54d90211b86a5cf0e6, type: 3}
|
||||||
type: 0
|
type: 0
|
||||||
buildingPrefab: {fileID: 9125080148727291347, guid: 5663dbcf605325241b40bc2afd5b6647, type: 3}
|
buildingPrefab: {fileID: 9125080148727291347, guid: 5663dbcf605325241b40bc2afd5b6647, type: 3}
|
||||||
|
isVisiting: 1
|
||||||
|
@ -124,7 +124,7 @@ namespace AI
|
|||||||
var item = GetNearestItem(agent);
|
var item = GetNearestItem(agent);
|
||||||
if (((item.dist > 0 && item.dist <= _data.DistaceToCollectBonus) ||
|
if (((item.dist > 0 && item.dist <= _data.DistaceToCollectBonus) ||
|
||||||
agent.Unit.Mana <= agent.Unit.Data.maxMana * _data.ManaPercentToCollectBonus) &&
|
agent.Unit.Mana <= agent.Unit.Data.maxMana * _data.ManaPercentToCollectBonus) &&
|
||||||
(item.hex.Item.Type == ItemType.DEFENCE
|
(item.hex.Item.Item.Type == ItemType.DEFENCE
|
||||||
? agent.Unit.InventoryDefence.Count
|
? agent.Unit.InventoryDefence.Count
|
||||||
: agent.Unit.Inventory.Count) < agent.Unit.InventoryCapacity / 2)
|
: agent.Unit.Inventory.Count) < agent.Unit.InventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using Data;
|
using Data;
|
||||||
using DefaultNamespace;
|
using DefaultNamespace;
|
||||||
using Items;
|
using Items;
|
||||||
|
using Items.ItemViews;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ namespace HexFiled
|
|||||||
[HideInInspector] public GameObject BuildingInstance;
|
[HideInInspector] public GameObject BuildingInstance;
|
||||||
|
|
||||||
[SerializeField] private HexCell[] neighbors;
|
[SerializeField] private HexCell[] neighbors;
|
||||||
[SerializeField] private Item _item;
|
[SerializeField] private ItemView _item;
|
||||||
[SerializeField, AssetsOnly] public GameObject Building;
|
[SerializeField, AssetsOnly] public GameObject Building;
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ namespace HexFiled
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item Item
|
public ItemView Item
|
||||||
{
|
{
|
||||||
get => _item;
|
get => _item;
|
||||||
set => _item = value;
|
set => _item = value;
|
||||||
|
@ -24,17 +24,11 @@ namespace Items
|
|||||||
|
|
||||||
public BonusType BonusType => bonusType;
|
public BonusType BonusType => bonusType;
|
||||||
|
|
||||||
public override void PickUp(Unit unit)
|
|
||||||
{
|
public int Value => value;
|
||||||
if(bonusType != BonusType.Heal)
|
|
||||||
base.PickUp(unit);
|
public GameObject UsisngVFX => usisngVFX;
|
||||||
else
|
|
||||||
{
|
|
||||||
VFXController.Instance.PlayEffect(usisngVFX, Unit.Instance.transform);
|
|
||||||
Unit.UnitView.OnHit.Invoke(-value);
|
|
||||||
Despawn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Invoke(Unit unit)
|
public void Invoke(Unit unit)
|
||||||
{
|
{
|
||||||
|
@ -39,35 +39,22 @@ namespace Items
|
|||||||
|
|
||||||
public Sprite Icon => icon;
|
public Sprite Icon => icon;
|
||||||
|
|
||||||
protected Unit Unit;
|
|
||||||
protected Action<Unit> OnItemUsed;
|
protected Action<Unit> OnItemUsed;
|
||||||
|
|
||||||
public UnitColor Color => Unit.Color;
|
|
||||||
|
|
||||||
public GameObject Spawn(HexCell cell, GameObject parent, GameObject iconPrefab)
|
public GameObject Spawn(HexCell cell, GameObject parent, GameObject iconPrefab)
|
||||||
{
|
{
|
||||||
_instance = GameObject.Instantiate(iconPrefab, cell.transform.position + new Vector3(0, 1, 0),
|
_instance = GameObject.Instantiate(iconPrefab, cell.transform.position + new Vector3(0, 1, 0),
|
||||||
Quaternion.identity, parent.transform);
|
Quaternion.identity, parent.transform);
|
||||||
_instance.AddComponent<ItemView>().SetUp(this);
|
var view = _instance.AddComponent<ItemView>();
|
||||||
cell.Item = this;
|
view.SetUp(this);
|
||||||
|
cell.Item = view;
|
||||||
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
|
_instance.AddComponent<CapsuleCollider>().isTrigger = true;
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void PickUp(Unit unit)
|
|
||||||
{
|
|
||||||
_instance.transform.DOMove(unit.UnitView.transform.position, 0.1f).OnComplete(() =>
|
|
||||||
{
|
|
||||||
unit.PickUpItem(this);
|
|
||||||
Despawn();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Despawn()
|
|
||||||
{
|
|
||||||
Destroy(_instance.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,7 @@ namespace Items
|
|||||||
{
|
{
|
||||||
cellByColor.Value.ForEach(x =>
|
cellByColor.Value.ForEach(x =>
|
||||||
{
|
{
|
||||||
if (x.Building != null)
|
if (x.Building != null && x.Item != null)
|
||||||
{
|
{
|
||||||
closedList.Add(x);
|
closedList.Add(x);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using DG.Tweening;
|
using DefaultNamespace;
|
||||||
|
using DG.Tweening;
|
||||||
|
using Units;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Items.ItemViews
|
namespace Items.ItemViews
|
||||||
@ -19,11 +21,29 @@ namespace Items.ItemViews
|
|||||||
Rotate();
|
Rotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
public void PickUp(Unit unit)
|
||||||
|
{
|
||||||
|
if (_item is Bonus { BonusType: BonusType.Heal } bonus)
|
||||||
|
{
|
||||||
|
VFXController.Instance.PlayEffect(bonus.UsisngVFX, unit.Instance.transform);
|
||||||
|
unit.UnitView.OnHit.Invoke(-bonus.Value);
|
||||||
|
Despawn();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transform.DOMove(unit.UnitView.transform.position, 0.1f).OnComplete(() =>
|
||||||
|
{
|
||||||
|
unit.PickUpItem(_item);
|
||||||
|
Despawn();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Despawn()
|
||||||
{
|
{
|
||||||
transform.DOKill();
|
transform.DOKill();
|
||||||
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Rotate()
|
private void Rotate()
|
||||||
{
|
{
|
||||||
transform.DORotate(transform.rotation.eulerAngles + new Vector3(0, 10, 0), 0.1f)
|
transform.DORotate(transform.rotation.eulerAngles + new Vector3(0, 10, 0), 0.1f)
|
||||||
|
@ -64,6 +64,11 @@ namespace Items
|
|||||||
|
|
||||||
public void UseAbility(Unit unit, Unit chosenUnit)
|
public void UseAbility(Unit unit, Unit chosenUnit)
|
||||||
{
|
{
|
||||||
|
if (unit == null)
|
||||||
|
{
|
||||||
|
DeAim();
|
||||||
|
return;
|
||||||
|
}
|
||||||
unit.UseItem(this);
|
unit.UseItem(this);
|
||||||
DeAim();
|
DeAim();
|
||||||
OnItemUsed?.Invoke(unit);
|
OnItemUsed?.Invoke(unit);
|
||||||
|
@ -135,7 +135,8 @@ namespace Units
|
|||||||
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
|
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
|
||||||
|
|
||||||
|
|
||||||
if (_cell.GetNeighbor(direction).Color == _data.color || _cell.GetNeighbor(direction).Color == _easyCaptureColor)
|
if (_cell.GetNeighbor(direction).Color == _data.color ||
|
||||||
|
(_cell.GetNeighbor(direction).Color == _easyCaptureColor && _easyCaptureColor != UnitColor.Grey))
|
||||||
{
|
{
|
||||||
DoTransit(direction);
|
DoTransit(direction);
|
||||||
}
|
}
|
||||||
@ -211,9 +212,10 @@ namespace Units
|
|||||||
{
|
{
|
||||||
_mana -= _hexGrid.HexCaptureCost;
|
_mana -= _hexGrid.HexCaptureCost;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UnitView.RegenMana();
|
UnitView.RegenMana();
|
||||||
}
|
|
||||||
|
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
|
@ -177,7 +177,7 @@ public class UnitView : MonoBehaviour
|
|||||||
|
|
||||||
if (itemView == null || itemView.pickedUp || !_unit.CanPickUpItem(itemView.Item)) return;
|
if (itemView == null || itemView.pickedUp || !_unit.CanPickUpItem(itemView.Item)) return;
|
||||||
itemView.pickedUp = true;
|
itemView.pickedUp = true;
|
||||||
itemView.Item.PickUp(_unit);
|
itemView.PickUp(Unit);
|
||||||
ItemFabric.Items.Remove(itemView.gameObject);
|
ItemFabric.Items.Remove(itemView.gameObject);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user