2025-08-27 19:56:49 +08:00
|
|
|
|
using Base;
|
|
|
|
|
using Data;
|
|
|
|
|
using Entity;
|
|
|
|
|
using Prefab;
|
2025-08-28 16:20:24 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2025-09-06 12:25:55 +08:00
|
|
|
|
using Managers;
|
2025-08-27 19:56:49 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Object = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
namespace Item
|
|
|
|
|
{
|
|
|
|
|
public class WeaponResource : ItemResource
|
|
|
|
|
{
|
|
|
|
|
public Attributes Attributes { get; private set; }
|
|
|
|
|
public BulletDef Bullet { get; private set; }
|
|
|
|
|
public WeaponType Type { get; private set; }
|
2025-08-28 16:20:24 +08:00
|
|
|
|
|
2025-09-08 00:13:12 +08:00
|
|
|
|
public IReadOnlyList<Sprite> AttackAnimation { get; private set; }
|
2025-08-28 16:20:24 +08:00
|
|
|
|
public float AttackAnimationTime { get; private set; }
|
2025-09-08 00:13:12 +08:00
|
|
|
|
public float AttackCooldown => 1f / Attributes.attackSpeed;
|
|
|
|
|
public float AttackDetectionTime { get; private set; }
|
|
|
|
|
public bool UseEntityAttackAnimation { get; private set; }
|
2025-08-27 19:56:49 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="def">武器的定义对象。</param>
|
|
|
|
|
/// <exception cref="ArgumentNullException">如果传入的 WeaponDef 为 null,则抛出此异常。</exception>
|
|
|
|
|
public WeaponResource(WeaponDef def)
|
|
|
|
|
: base(def) // 调用基类 ItemResource 的构造函数,直接传入 WeaponDef。
|
|
|
|
|
{
|
|
|
|
|
// 参数校验:确保 WeaponDef 对象不为空,避免空引用异常。
|
|
|
|
|
if (def == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(def), "创建 WeaponResource 时,WeaponDef 不能为 null。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bullet = def.bullet;
|
|
|
|
|
// 初始化武器的属性。Attributes 对象通过 WeaponDef 中的属性数据进行构建。
|
|
|
|
|
Attributes = new Attributes(def.attributes);
|
|
|
|
|
// 初始化武器类型,直接从 WeaponDef 定义中获取。
|
|
|
|
|
Type = def.type;
|
|
|
|
|
|
2025-09-08 00:13:12 +08:00
|
|
|
|
AttackAnimation = PackagesImageManager.Instance.GetSprites(def.attackAnimation);
|
|
|
|
|
AttackAnimationTime = AttackAnimation.Count / FPS;
|
|
|
|
|
AttackDetectionTime = def.attackDetectionTime;
|
|
|
|
|
UseEntityAttackAnimation = def.useEntityAttackAnimation;
|
2025-08-27 19:56:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|