feat(enemy): AbilityRef——AI 层能力引用资产化,字符串仅作定制脚本兜底
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.Abilities
|
||||
{
|
||||
/// <summary>
|
||||
/// 能力引用。配方资产侧引用 EnemyAbilitySO(Unity 引用系统保证拼不错、改名不断链);
|
||||
/// 定制 AiScript 侧仍可直接写字符串 id。资产优先。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct AbilityRef
|
||||
{
|
||||
[Tooltip("能力配置资产;配方路径用这个")]
|
||||
[SerializeField] EnemyAbilitySO _asset;
|
||||
|
||||
[NonSerialized] string _literal; // 定制脚本路径用;不参与序列化
|
||||
|
||||
public AbilityRef(EnemyAbilitySO asset) { _asset = asset; _literal = null; }
|
||||
public AbilityRef(string id) { _asset = null; _literal = id; }
|
||||
public AbilityRef(EnemyAbilitySO asset, string id) { _asset = asset; _literal = id; }
|
||||
|
||||
/// <summary>解析出的能力 id;资产优先,都没有则 null。</summary>
|
||||
public string Id => _asset != null ? _asset.abilityId : _literal;
|
||||
|
||||
public bool IsEmpty => string.IsNullOrEmpty(Id);
|
||||
|
||||
/// <summary>资产与字符串同时非空——歧义配置,供校验器报警告。</summary>
|
||||
public bool HasConflict => _asset != null && !string.IsNullOrEmpty(_literal);
|
||||
|
||||
public static implicit operator AbilityRef(string id) => new AbilityRef(id);
|
||||
public static implicit operator AbilityRef(EnemyAbilitySO asset) => new AbilityRef(asset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00a0a0d1f0e127a47ad01ea9423bbc0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user