- bugfix build manager on starter builds not correctly assigning keybinders with defaults - added 2h ranged shoot animation - added shoot animation type for abilities - new weapon visual handler swaps visual weapons based on ability queues
105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class BuildManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameTag characterClass;
|
|
|
|
|
|
[SerializeField] private List<BuildSlot> defaultBuildSlots = new List<BuildSlot>();
|
|
[SerializeField] private List<AbilityKeyBinder> abilityKeyBinders = new List<AbilityKeyBinder>();
|
|
|
|
[Header("Events:")]
|
|
[SerializeField] private GameEvent_BuildManager onBuildManagerInitialized;
|
|
|
|
|
|
[Header("Runtime Data:")]
|
|
[SerializeField] private List<BuildSlot> selectedBuildSlots = new List<BuildSlot>();
|
|
|
|
|
|
|
|
BuildData buildData = new BuildData();
|
|
|
|
PhotonView owner;
|
|
|
|
public GameTag CharacterClass => characterClass;
|
|
public List<BuildSlot> SelectedBuildSlots => selectedBuildSlots;
|
|
|
|
private void Awake()
|
|
{
|
|
owner = GetComponentInParent<PhotonView>();
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (!owner.IsMine)
|
|
{
|
|
this.enabled = false;
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < defaultBuildSlots.Count; i++)
|
|
{
|
|
selectedBuildSlots[i].ability = defaultBuildSlots[i].ability;
|
|
selectedBuildSlots[i].binderSlot = defaultBuildSlots[i].binderSlot;
|
|
}
|
|
|
|
TryGetSavedBuildData();
|
|
|
|
onBuildManagerInitialized.Raise(this);
|
|
}
|
|
|
|
private void TryGetSavedBuildData()
|
|
{
|
|
buildData = PlayerDataHandler.Instance.LoadCharacterBuildData(PlayerDataHandler.Instance.currentPlayerName.Value, PlayerDataHandler.Instance.currentCharacterName.Value);
|
|
|
|
if (buildData == null)
|
|
{
|
|
SaveCurrentBuild();
|
|
}
|
|
else
|
|
{
|
|
InitializeLoadedBuild();
|
|
}
|
|
}
|
|
|
|
private void SaveCurrentBuild()
|
|
{
|
|
if (buildData == null)
|
|
buildData = new BuildData();
|
|
|
|
for (int i = 0; i < buildData.buildSlotsdata.Length; i++)
|
|
{
|
|
buildData.buildSlotsdata[i].abilityIndex = AbilityIndexer.Instance.Abilities.IndexOf(selectedBuildSlots[i].ability);
|
|
buildData.buildSlotsdata[i].binderSlotIndex = selectedBuildSlots[i].binderSlot;
|
|
|
|
abilityKeyBinders[selectedBuildSlots[i].binderSlot].BindAbility(selectedBuildSlots[i].ability);
|
|
}
|
|
|
|
PlayerDataHandler.Instance.SaveCharacterBuildData(PlayerDataHandler.Instance.currentPlayerName.Value, PlayerDataHandler.Instance.currentCharacterName.Value, buildData);
|
|
}
|
|
private void InitializeLoadedBuild()
|
|
{
|
|
for (int i = 0; i < buildData.buildSlotsdata.Length; i++)
|
|
{
|
|
selectedBuildSlots[i].ability = AbilityIndexer.Instance.Abilities[buildData.buildSlotsdata[i].abilityIndex];
|
|
selectedBuildSlots[i].binderSlot = buildData.buildSlotsdata[i].binderSlotIndex;
|
|
|
|
abilityKeyBinders[selectedBuildSlots[i].binderSlot].BindAbility(selectedBuildSlots[i].ability);
|
|
}
|
|
}
|
|
|
|
public void UpdateBuildOnAbilitiesChanged(int slotIndex, BaseAbility ability)
|
|
{
|
|
selectedBuildSlots[slotIndex].ability = ability;
|
|
selectedBuildSlots[slotIndex].binderSlot = slotIndex;
|
|
|
|
abilityKeyBinders[selectedBuildSlots[slotIndex].binderSlot].BindAbility(selectedBuildSlots[slotIndex].ability);
|
|
|
|
SaveCurrentBuild();
|
|
}
|
|
}
|