Route weapon groups through checkpoints
This commit is contained in:
parent
30eda5c82e
commit
0258e9f106
5 changed files with 88 additions and 13 deletions
|
|
@ -1424,6 +1424,37 @@ public class ActionGameManager : MonoBehaviour
|
|||
QueueRunCheckpoint("entity-name");
|
||||
}
|
||||
|
||||
public bool CommitWeaponGroupMembership(EquippedItem item, int groupIndex, bool assigned)
|
||||
{
|
||||
if (item?.Entity?.WeaponGroups == null ||
|
||||
groupIndex < 0 ||
|
||||
groupIndex >= item.Entity.WeaponGroups.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var weapon = item.GetBehavior<Weapon>();
|
||||
if (weapon == null)
|
||||
return false;
|
||||
|
||||
var group = item.Entity.WeaponGroups[groupIndex];
|
||||
if (assigned)
|
||||
{
|
||||
if (!group.items.Contains(item))
|
||||
group.items.Add(item);
|
||||
if (!group.weapons.Contains(weapon))
|
||||
group.weapons.Add(weapon);
|
||||
}
|
||||
else
|
||||
{
|
||||
group.items.Remove(item);
|
||||
group.weapons.Remove(weapon);
|
||||
}
|
||||
|
||||
QueueRunCheckpoint("weapon-group-membership");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CommitEquippedItemOverrideShutdown(EquippedItem item, bool enabled)
|
||||
{
|
||||
if (item?.EquippableItem == null)
|
||||
|
|
|
|||
|
|
@ -33,18 +33,9 @@ public class WeaponGroupAssignment : MonoBehaviour
|
|||
group.Label.color = groupContainsItem() ? ActiveColor : InactiveColor;
|
||||
group.Button.onClick.AddListener(() =>
|
||||
{
|
||||
if (groupContainsItem())
|
||||
{
|
||||
item.Entity.WeaponGroups[i1].items.Remove(item);
|
||||
item.Entity.WeaponGroups[i1].weapons.Remove(weapon);
|
||||
group.Label.color = InactiveColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Entity.WeaponGroups[i1].items.Add(item);
|
||||
item.Entity.WeaponGroups[i1].weapons.Add(weapon);
|
||||
group.Label.color = ActiveColor;
|
||||
}
|
||||
var assigned = !groupContainsItem();
|
||||
if (ActionGameManager.Instance.CommitWeaponGroupMembership(item, i1, assigned))
|
||||
group.Label.color = assigned ? ActiveColor : InactiveColor;
|
||||
});
|
||||
|
||||
group.BeginDragTrigger.OnBeginDragAsObservable()
|
||||
|
|
|
|||
Loading…
Reference in a new issue