Cut 2 of docs/addressables-cut.md. The asset move (git mv
Resources/{Prefabs,Schematics,Sprites/Icons} -> Content/...) and the
UnityHelpers.cs deletion already landed in 1fdf8151, picked up by a
concurrent session sharing this working tree; this commit is the rest
of Cut 2 landing on top of that shared state, atomically:
- Bump CultLib to cultlib-unity-v1.0.60 / caching-unity-v1.4.0 (both
45c2f40) in Packages/manifest.json, packages-lock.json and
Directory.Build.props, together with the 8 ServerShared
[CultInspectorAssetPath] usages becoming [CultInspectorAssetGuid] -
the .NET and Unity sides move together or nothing compiles.
- Assets/Scripts/EngineAssets.cs replaces UnityHelpers: loads an
Addressables key (bare GUID or guid[subAsset]) synchronously,
loading the GameObject and taking the component for the four sites
that load a component. ActionBarSlot, EntityInstance, ShipInstance
and ZoneRenderer call it instead of Resources.Load/UnityHelpers; the
inline "Assets/Resources/" prefix strips are gone with them.
CultCacheDrawers' schematic preview goes through
AssetDatabase.GUIDToAssetPath first.
- Assets/Scripts/Editor/EngineAssetCheck.cs validates every stored
[CultInspectorAssetGuid] value: 32 lowercase hex, resolves to a file,
is addressable, and satisfies its member's consumer-type contract
(Texture2D for icons/logos/schematics, a GameObject with the right
component for prefabs) - table-driven, so an attributed member with
no row fails loudly instead of being skipped.
- GameData/Aetheria.cc: the scratch migration (Aetheria.Shared + the
pinned CultLib revision, a throwaway console app, never landed)
walked all 138 attributed field slots across 180 documents,
rewriting the 30 non-empty Resources paths to their .meta GUIDs -
108 stayed empty, 0 unresolved, matching the map's census exactly.
Verification: dotnet test tests/Aetheria.Shared.Tests 61/61 green
against CultLib 45c2f40; Unity 6000.3.24f1 batchmode compiles clean;
EngineAssetCheck.Run passes all 30 stored references; the map's
negative greps are clean; tests/mutation_tests.py's 5 mutations (wrong
type, non-addressable, random guid, an old path, and an untabled
attributed member) are all caught and named, the control case and the
post-revert recompile stay clean, and the catalog/source are restored
byte-identical afterward.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
209 lines
No EOL
6.4 KiB
C#
209 lines
No EOL
6.4 KiB
C#
using System;
|
|
using MessagePack;
|
|
using Newtonsoft.Json;
|
|
using TMPro;
|
|
using UniRx.Triggers;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ActionBarSlot : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI Label;
|
|
public RawImage Icon;
|
|
public TextMeshProUGUI InputLabel;
|
|
public Image InputIcon;
|
|
public TextMeshProUGUI QuantityRemaining;
|
|
public Image Fill;
|
|
public ObservablePointerEnterTrigger PointerEnterTrigger;
|
|
public ObservablePointerExitTrigger PointerExitTrigger;
|
|
private ActionBarBinding binding;
|
|
|
|
public ActionBarBinding Binding
|
|
{
|
|
get => binding;
|
|
set
|
|
{
|
|
binding = value;
|
|
if (binding == null)
|
|
{
|
|
Fill.fillAmount = 0;
|
|
Label.gameObject.SetActive(false);
|
|
QuantityRemaining.gameObject.SetActive(false);
|
|
Icon.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Binding?.Update();
|
|
}
|
|
|
|
public SavedActionBarBinding Save()
|
|
{
|
|
return Binding switch
|
|
{
|
|
ActionBarConsumableBinding actionBarConsumableBinding => new SavedActionBarConsumableBinding
|
|
{
|
|
Target = actionBarConsumableBinding.Entity.ItemManager.ItemData.RefOf(actionBarConsumableBinding.Target)
|
|
},
|
|
ActionBarGearBinding actionBarGearBinding => new SavedActionBarGearBinding
|
|
{
|
|
EquipmentIndex = actionBarGearBinding.Entity.Equipment.IndexOf(actionBarGearBinding.Item),
|
|
BehaviorIndex = Array.IndexOf(actionBarGearBinding.Item.Behaviors, actionBarGearBinding.Behavior)
|
|
},
|
|
ActionBarWeaponGroupBinding actionBarWeaponGroupBinding => new SavedActionBarWeaponGroupBinding
|
|
{
|
|
Group = actionBarWeaponGroupBinding.Group
|
|
},
|
|
_ => null
|
|
};
|
|
}
|
|
|
|
public void Restore(SavedActionBarBinding binding, Entity entity)
|
|
{
|
|
Binding = binding switch
|
|
{
|
|
SavedActionBarConsumableBinding savedActionBarConsumableBinding =>
|
|
new ActionBarConsumableBinding(
|
|
entity,
|
|
this,
|
|
entity.ItemManager.ItemData.Get(savedActionBarConsumableBinding.Target)),
|
|
SavedActionBarGearBinding savedActionBarGearBinding =>
|
|
new ActionBarGearBinding(
|
|
entity,
|
|
this,
|
|
entity.Equipment[savedActionBarGearBinding.EquipmentIndex],
|
|
entity.Equipment[savedActionBarGearBinding.EquipmentIndex]
|
|
.Behaviors[savedActionBarGearBinding.BehaviorIndex] as IActivatedBehavior),
|
|
SavedActionBarWeaponGroupBinding savedActionBarWeaponGroupBinding =>
|
|
new ActionBarWeaponGroupBinding(entity, this, savedActionBarWeaponGroupBinding.Group),
|
|
_ => null
|
|
};
|
|
}
|
|
}
|
|
|
|
public abstract class ActionBarBinding
|
|
{
|
|
public Entity Entity { get; }
|
|
protected ActionBarSlot Slot { get; }
|
|
public abstract void Activate();
|
|
public abstract void Deactivate();
|
|
public abstract void Update();
|
|
public ActionBarBinding(Entity entity, ActionBarSlot slot)
|
|
{
|
|
Entity = entity;
|
|
Slot = slot;
|
|
}
|
|
}
|
|
|
|
public class ActionBarConsumableBinding : ActionBarBinding
|
|
{
|
|
public ConsumableItemData Target;
|
|
|
|
public ActionBarConsumableBinding(Entity entity, ActionBarSlot slot, ConsumableItemData target) : base(entity, slot)
|
|
{
|
|
Target = target;
|
|
Slot.QuantityRemaining.gameObject.SetActive(true);
|
|
var data = Target;
|
|
if(!string.IsNullOrEmpty(data.Icon))
|
|
{
|
|
Slot.Label.gameObject.SetActive(false);
|
|
Slot.Icon.gameObject.SetActive(true);
|
|
Slot.Icon.texture = EngineAssets.Load<Texture2D>(data.Icon);
|
|
}
|
|
else Slot.Icon.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
Entity.TryActivateConsumable(Target);
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
Slot.QuantityRemaining.text = $"{Entity.CountItemsInCargo(Entity.ItemManager.ItemData.RefOf<ItemData>(Target).Key)}";
|
|
var instance = Entity.FindActiveConsumable(Target);
|
|
if (instance == null) Slot.Fill.fillAmount = 0;
|
|
else Slot.Fill.fillAmount = instance.RemainingDuration / instance.Data.Duration;
|
|
}
|
|
}
|
|
|
|
public class ActionBarGearBinding : ActionBarBinding
|
|
{
|
|
public EquippedItem Item { get; }
|
|
public IActivatedBehavior Behavior { get; }
|
|
|
|
public bool Active;
|
|
|
|
public ActionBarGearBinding(Entity entity, ActionBarSlot slot, EquippedItem item, IActivatedBehavior behavior) : base(entity, slot)
|
|
{
|
|
Item = item;
|
|
var data = Entity.ItemManager.GetData(item.EquippableItem);
|
|
Behavior = behavior;
|
|
Slot.QuantityRemaining.gameObject.SetActive(false);
|
|
Slot.Icon.gameObject.SetActive(true);
|
|
Slot.Label.gameObject.SetActive(false);
|
|
if (!string.IsNullOrEmpty(Item.Data.ActionBarIcon))
|
|
Slot.Icon.texture = EngineAssets.Load<Texture2D>(Item.Data.ActionBarIcon);
|
|
else if (data is WeaponItemData weaponItemData)
|
|
Slot.Icon.texture = ActionGameManager.Instance.Settings.GetIcon(weaponItemData.WeaponType).texture;
|
|
else Slot.Icon.texture = ActionGameManager.Instance.Settings.GetIcon(data.HardpointType).texture;
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
Active = true;
|
|
Behavior.Activate();
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
Active = false;
|
|
Behavior.Deactivate();
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
Slot.Fill.fillAmount = Active ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
[MessagePackObject]
|
|
public class ActionBarWeaponGroupBinding : ActionBarBinding
|
|
{
|
|
[Key(0)] public int Group;
|
|
|
|
public ActionBarWeaponGroupBinding(Entity entity, ActionBarSlot slot, int group) : base(entity, slot)
|
|
{
|
|
Group = group;
|
|
slot.Label.gameObject.SetActive(true);
|
|
slot.Label.text = $"G{Group+1}";
|
|
Slot.Icon.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
foreach (var weapon in Entity.WeaponGroups[Group].weapons)
|
|
{
|
|
weapon.Activate();
|
|
}
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
foreach (var weapon in Entity.WeaponGroups[Group].weapons)
|
|
{
|
|
weapon.Deactivate();
|
|
}
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
|
|
}
|
|
} |