Files
Gen_Hack-and-Slash-Roguelite/Client/Assets/Scripts/Item/WeaponResource.cs

60 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using Data;
using Entity;
using Managers;
using UnityEngine;
namespace Item
{
public class WeaponResource : ItemResource
{
/// <summary>
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
/// </summary>
/// <param name="def">武器的定义对象。</param>
/// <exception cref="ArgumentNullException">如果传入的 WeaponDef 为 null则抛出此异常。</exception>
public WeaponResource(WeaponDef def)
: base(def)
{
if (def == null) throw new ArgumentNullException(nameof(def), "创建 WeaponResource 时WeaponDef 不能为 null。");
Bullet = def.bullet;
Attributes = new Attributes(def.attributes);
Type = def.type;
AttackAnimation = PackagesImageManager.Instance.GetSprites(def.attackAnimation);
AttackAnimationTime = AttackAnimation.Count / FPS;
AttackDetectionTime = def.attackDetectionTime;
UseEntityAttackAnimation = def.useEntityAttackAnimation;
SelfWeaponDef = def;
}
// 武器的属性
public Attributes Attributes { get; }
// 武器发射的子弹定义
public BulletDef Bullet { get; private set; }
// 武器类型
public WeaponType Type { get; private set; }
// 攻击动画的精灵列表
public IReadOnlyList<Sprite> AttackAnimation { get; }
// 攻击动画的时长
public float AttackAnimationTime { get; private set; }
// 攻击冷却时间
public float AttackCooldown => 1f / Attributes.attackSpeed;
// 攻击判定时间
public float AttackDetectionTime { get; private set; }
// 是否使用实体自身的攻击动画
public bool UseEntityAttackAnimation { get; private set; }
public WeaponDef SelfWeaponDef { get; private set; }
}
}