mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 11:27:14 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -1,42 +1,47 @@
|
||||
using Base;
|
||||
using Data;
|
||||
using Item;
|
||||
using Prefab;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Data;
|
||||
using Item;
|
||||
using Managers;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Pickup : Entity
|
||||
{
|
||||
public ItemResource itemResource;
|
||||
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
var entity = other.GetComponent<Character>();
|
||||
if (entity == null) return;
|
||||
if (entity.TryPickupItem(itemResource, 1) <= 0) Kill();
|
||||
}
|
||||
|
||||
protected override void AutoBehave()
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetTarget(Vector3 pos)
|
||||
public override bool SetTarget(Vector3 pos)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Init(ItemDef itemDef)
|
||||
{
|
||||
itemResource = Managers.ItemResourceManager.Instance.GetItem(itemDef.defName);
|
||||
itemResource = ItemResourceManager.Instance.GetItem(itemDef.defName);
|
||||
// 预缓存枚举值(避免每次循环重复调用 Enum.GetValues)
|
||||
var states = Enum.GetValues(typeof(EntityState)).Cast<EntityState>().ToArray();
|
||||
// 预初始化字典结构(减少内层循环的字典检查)
|
||||
foreach (var state in states)
|
||||
{
|
||||
bodyNodes.TryAdd(state, new Dictionary<Orientation, GameObject>());
|
||||
}
|
||||
foreach (var state in states) bodyNodes.TryAdd(state, new Dictionary<Orientation, GameObject>());
|
||||
|
||||
var texture = itemResource.Icon;
|
||||
if (texture.Count == 1)
|
||||
{
|
||||
var imageObj = Instantiate(Utils.GameObjectCreate.ImagePrefab.gameObject, body.transform);
|
||||
var imageObj = Instantiate(AnimationUtils.ImagePrefab.gameObject, body.transform);
|
||||
imageObj.transform.localPosition = Vector3.zero;
|
||||
bodyNodes[EntityState.Idle][Orientation.Down] = imageObj;
|
||||
var image = imageObj.GetComponent<ImagePrefab>();
|
||||
@@ -44,25 +49,15 @@ namespace Entity
|
||||
}
|
||||
else if (texture.Count > 1)
|
||||
{
|
||||
var animatorObj = Instantiate(Utils.GameObjectCreate.AnimatorPrefab.gameObject, body.transform);
|
||||
var animatorObj = Instantiate(AnimationUtils.AnimatorPrefab.gameObject, body.transform);
|
||||
animatorObj.transform.localPosition = Vector3.zero;
|
||||
bodyNodes[EntityState.Idle][Orientation.Down] = animatorObj;
|
||||
var animator = animatorObj.GetComponent<SpriteAnimator>();
|
||||
animator.SetSprites(texture.ToArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
SetBodyTexture(EntityState.Idle, Orientation.Down);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
var entity = other.GetComponent<Character>();
|
||||
if (entity == null) return;
|
||||
if (entity.TryPickupItem(itemResource, 1) <= 0)
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user