(client) feat:实现热重载,实现多维度,实现武器,实现掉落物,实现状态UI,实现攻击AI (#44)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
70
Client/Assets/Scripts/Entity/Pickup.cs
Normal file
70
Client/Assets/Scripts/Entity/Pickup.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Base;
|
||||
using Data;
|
||||
using Item;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Pickup:Entity
|
||||
{
|
||||
public ItemResource itemResource;
|
||||
protected override void AutoBehave()
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetTarget(Vector3 pos)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Init(ItemDef itemDef)
|
||||
{
|
||||
itemResource = Managers.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>());
|
||||
bodyAnimationNode.TryAdd(state, new Dictionary<Orientation, ITick[]>());
|
||||
}
|
||||
|
||||
var texture = itemResource.Icon;
|
||||
if (texture.Count == 1)
|
||||
{
|
||||
var imageObj = Instantiate(imagePrefab.gameObject, body.transform);
|
||||
imageObj.transform.localPosition = Vector3.zero;
|
||||
bodyNodes[EntityState.Idle][Orientation.Down] = imageObj;
|
||||
var image = imageObj.GetComponent<ImagePrefab>();
|
||||
image.SetSprite(texture[0]);
|
||||
}
|
||||
else if (texture.Count > 1)
|
||||
{
|
||||
var animatorObj = Instantiate(animatorPrefab.gameObject, body.transform);
|
||||
animatorObj.transform.localPosition = Vector3.zero;
|
||||
bodyNodes[EntityState.Idle][Orientation.Down] = animatorObj;
|
||||
var animator = animatorObj.GetComponent<SpriteAnimator>();
|
||||
animator.SetSprites(texture.ToArray());
|
||||
ITick[] ticks = { animator };
|
||||
|
||||
bodyAnimationNode[EntityState.Idle][Orientation.Down] = ticks;
|
||||
}
|
||||
|
||||
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