You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
373 lines
17 KiB
C#
373 lines
17 KiB
C#
|
4 years ago
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
using SiegeSong;
|
||
|
|
|
||
|
|
namespace SiegeSong
|
||
|
|
{
|
||
|
|
public class EquipmentManager : MonoBehaviour
|
||
|
|
{
|
||
|
|
public HUDManager hudManager;
|
||
|
|
|
||
|
|
public int LeftHandCurrentTechniqueIndex;
|
||
|
|
public int LeftHandCurrentEquipIndex;
|
||
|
|
public List<GameObject> LeftHandEquipSlots;
|
||
|
|
|
||
|
|
public int AbilityCurrentTechniqueIndex;
|
||
|
|
public int AbilityCurrentEquipIndex;
|
||
|
|
public List<GameObject> AbilityEquipSlots;
|
||
|
|
|
||
|
|
public int RightHandCurrentTechniqueIndex;
|
||
|
|
public int RightHandCurrentEquipIndex;
|
||
|
|
public List<GameObject> RightHandEquipSlots;
|
||
|
|
|
||
|
|
public Animator CharacterAnimator;
|
||
|
|
|
||
|
|
public int DefaultStanceID = 0;
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateStance(EquipableArea equipableArea, int StanceID = -1)
|
||
|
|
{
|
||
|
|
CharacterAnimator.SetFloat("Stance", StanceID == -1 ? DefaultStanceID : StanceID);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void AddEquipmentToSlots(GameObject equipment)
|
||
|
|
{
|
||
|
|
var equipSlots = new List<GameObject>();
|
||
|
|
equipSlots.Add(equipment);
|
||
|
|
switch (equipment.GetComponent<Equipable>().EquipableArea)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
equipSlots.AddRange(LeftHandEquipSlots);
|
||
|
|
LeftHandEquipSlots = equipSlots;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
equipSlots.AddRange(AbilityEquipSlots);
|
||
|
|
AbilityEquipSlots = equipSlots;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
equipSlots.AddRange(RightHandEquipSlots);
|
||
|
|
RightHandEquipSlots = equipSlots;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void RemoveEquipmentFromSlots(GameObject equipment)
|
||
|
|
{
|
||
|
|
var existingEquipSlots = new List<GameObject>();
|
||
|
|
var existingSlots = new GameObject[0];
|
||
|
|
switch (equipment.GetComponent<Equipable>().EquipableArea)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
LeftHandEquipSlots.Clear();
|
||
|
|
LeftHandEquipSlots.AddRange(existingEquipSlots);
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
LeftHandCurrentEquipIndex = 0;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
AbilityEquipSlots.Clear();
|
||
|
|
AbilityEquipSlots.AddRange(existingEquipSlots);
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
AbilityCurrentEquipIndex = 0;
|
||
|
|
AbilityEquipSlots.RemoveAll(slot => slot.GetComponent<Equipable>().ID == equipment.GetComponent<Equipable>().ID);
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
existingSlots = new GameObject[RightHandEquipSlots.Count];
|
||
|
|
RightHandEquipSlots.CopyTo(existingSlots);
|
||
|
|
|
||
|
|
var newEquipSlots = new List<GameObject>();
|
||
|
|
|
||
|
|
RightHandEquipSlots.Clear();
|
||
|
|
RightHandEquipSlots = null;
|
||
|
|
|
||
|
|
|
||
|
|
for (var i = 0; i < existingSlots.Length; i++)
|
||
|
|
if (existingSlots[i].GetComponent<Equipable>().ID != equipment.GetComponent<Equipable>().ID)
|
||
|
|
{
|
||
|
|
newEquipSlots.Add(existingSlots[i]);
|
||
|
|
}
|
||
|
|
|
||
|
|
RightHandEquipSlots = newEquipSlots;
|
||
|
|
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
RightHandCurrentEquipIndex = 0;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateHUD();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseLeft()
|
||
|
|
{
|
||
|
|
Use(EquipableArea.Left);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseRight()
|
||
|
|
{
|
||
|
|
Use(EquipableArea.Right);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UseAbility()
|
||
|
|
{
|
||
|
|
Use(EquipableArea.Ability);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StopLeft()
|
||
|
|
{
|
||
|
|
Stop(EquipableArea.Left);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StopRight()
|
||
|
|
{
|
||
|
|
Stop(EquipableArea.Right);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StopAbility()
|
||
|
|
{
|
||
|
|
Stop(EquipableArea.Ability);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Stop(EquipableArea area)
|
||
|
|
{
|
||
|
|
switch (area)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
CharacterAnimator.SetBool("UseLeftEquipment", false);
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
CharacterAnimator.SetBool("UseAbilityEquipment", false);
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
CharacterAnimator.SetBool("UseRightEquipment", false);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Use(EquipableArea area)
|
||
|
|
{
|
||
|
|
switch (area)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
if (LeftHandCurrentEquipIndex < LeftHandEquipSlots.Count && LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length > LeftHandCurrentTechniqueIndex)
|
||
|
|
{
|
||
|
|
LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[LeftHandCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[LeftHandCurrentTechniqueIndex].GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
if (AbilityCurrentEquipIndex < AbilityEquipSlots.Count && AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length > AbilityCurrentTechniqueIndex)
|
||
|
|
{
|
||
|
|
AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques[AbilityCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques[AbilityCurrentTechniqueIndex].GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
if (RightHandCurrentEquipIndex < RightHandEquipSlots.Count && RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length > RightHandCurrentTechniqueIndex)
|
||
|
|
{
|
||
|
|
RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
//hudController.FadeInThenOutEquipmentSlots();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextLeftEquip()
|
||
|
|
{
|
||
|
|
var putAway = LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().PutAwayTechnique;
|
||
|
|
if (putAway != null && putAway.GetComponent<Technique>() != null)
|
||
|
|
{
|
||
|
|
putAway.GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
putAway.GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
ChangeEquip(EquipableArea.Left);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextAbilityEquip()
|
||
|
|
{
|
||
|
|
var putAway = AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().PutAwayTechnique;
|
||
|
|
if (putAway != null && putAway.GetComponent<Technique>() != null)
|
||
|
|
{
|
||
|
|
putAway.GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
putAway.GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
ChangeEquip(EquipableArea.Ability);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextRightEquip()
|
||
|
|
{
|
||
|
|
var putAway = RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().PutAwayTechnique;
|
||
|
|
if (putAway != null && putAway.GetComponent<Technique>() != null)
|
||
|
|
{
|
||
|
|
putAway.GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
putAway.GetComponent<Technique>().Use();
|
||
|
|
}
|
||
|
|
RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
ChangeEquip(EquipableArea.Right);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextLeftTechnique()
|
||
|
|
{
|
||
|
|
ChangeTechnique(EquipableArea.Left);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextAbilityTechnique()
|
||
|
|
{
|
||
|
|
ChangeTechnique(EquipableArea.Ability);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextRightTechnique()
|
||
|
|
{
|
||
|
|
ChangeTechnique(EquipableArea.Right);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public void ChangeEquip(EquipableArea area, bool next = true)
|
||
|
|
{
|
||
|
|
switch (area)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
if (LeftHandCurrentEquipIndex >= LeftHandEquipSlots.Count)
|
||
|
|
LeftHandCurrentEquipIndex = 0;
|
||
|
|
else
|
||
|
|
LeftHandCurrentEquipIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
if (AbilityCurrentEquipIndex >= AbilityEquipSlots.Count)
|
||
|
|
AbilityCurrentEquipIndex = 0;
|
||
|
|
else
|
||
|
|
AbilityCurrentEquipIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
if (RightHandCurrentEquipIndex >= RightHandEquipSlots.Count)
|
||
|
|
RightHandCurrentEquipIndex = 0;
|
||
|
|
else
|
||
|
|
RightHandCurrentEquipIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ResetTechnique(EquipableArea area)
|
||
|
|
{
|
||
|
|
switch (area)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
LeftHandCurrentEquipIndex = 0;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
AbilityCurrentEquipIndex = 0;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
RightHandCurrentEquipIndex = 0;
|
||
|
|
break;
|
||
|
|
|
||
|
|
}
|
||
|
|
UpdateHUD();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ChangeTechnique(EquipableArea area, bool next = true)
|
||
|
|
{
|
||
|
|
switch (area)
|
||
|
|
{
|
||
|
|
case EquipableArea.Left:
|
||
|
|
if (LeftHandCurrentEquipIndex >= LeftHandEquipSlots.Count || LeftHandCurrentTechniqueIndex >= LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
else
|
||
|
|
LeftHandCurrentTechniqueIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Ability:
|
||
|
|
if (AbilityCurrentEquipIndex >= AbilityEquipSlots.Count || AbilityCurrentTechniqueIndex >= AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
else
|
||
|
|
AbilityCurrentTechniqueIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
case EquipableArea.Right:
|
||
|
|
if (RightHandCurrentEquipIndex >= RightHandEquipSlots.Count || RightHandCurrentTechniqueIndex >= RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
else
|
||
|
|
RightHandCurrentTechniqueIndex += next ? 1 : -1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
UpdateTechniqueAnimationParameters();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateTechniqueAnimationParameters()
|
||
|
|
{
|
||
|
|
if (LeftHandCurrentEquipIndex >= LeftHandEquipSlots.Count || LeftHandCurrentTechniqueIndex >= LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
{
|
||
|
|
LeftHandEquipSlots[0].GetComponent<Equipable>().Techniques[0].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
LeftHandCurrentEquipIndex = 0;
|
||
|
|
LeftHandCurrentTechniqueIndex = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
CharacterAnimator.SetInteger("LeftEquipment", LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[LeftHandCurrentTechniqueIndex].GetComponent<Technique>().ID);
|
||
|
|
LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[LeftHandCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (AbilityCurrentEquipIndex >= AbilityEquipSlots.Count || AbilityCurrentTechniqueIndex >= AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
{
|
||
|
|
AbilityEquipSlots[0].GetComponent<Equipable>().Techniques[0].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
AbilityCurrentEquipIndex = 0;
|
||
|
|
AbilityCurrentTechniqueIndex = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques[AbilityCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
CharacterAnimator.SetInteger("AbilityEquipment", AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques[AbilityCurrentTechniqueIndex].GetComponent<Technique>().ID);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (RightHandCurrentEquipIndex >= RightHandEquipSlots.Count || RightHandCurrentTechniqueIndex >= RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques.Length)
|
||
|
|
{
|
||
|
|
RightHandEquipSlots[0].GetComponent<Equipable>().Techniques[0].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
RightHandCurrentEquipIndex = 0;
|
||
|
|
RightHandCurrentTechniqueIndex = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
CharacterAnimator.SetInteger("RightEquipment", RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().ID);
|
||
|
|
RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().CharacterAnimator = CharacterAnimator;
|
||
|
|
}
|
||
|
|
|
||
|
|
UpdateHUD();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateHUD()
|
||
|
|
{
|
||
|
|
if (hudManager != null)
|
||
|
|
{
|
||
|
|
hudManager.LeftHandTechniqueDisplayValue = LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[LeftHandCurrentTechniqueIndex].GetComponent<Technique>().FriendlyName;
|
||
|
|
hudManager.LeftHandEquipDisplayValue = LeftHandEquipSlots[LeftHandCurrentEquipIndex].GetComponent<Equipable>().FriendlyName;
|
||
|
|
hudManager.AbilityTechniqueDisplayValue = AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().Techniques[AbilityCurrentTechniqueIndex].GetComponent<Technique>().FriendlyName;
|
||
|
|
hudManager.AbilityEquipDisplayValue = AbilityEquipSlots[AbilityCurrentEquipIndex].GetComponent<Equipable>().FriendlyName;
|
||
|
|
hudManager.RightHandTechniqueDisplayValue = RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().Techniques[RightHandCurrentTechniqueIndex].GetComponent<Technique>().FriendlyName;
|
||
|
|
hudManager.RightHandEquipDisplayValue = RightHandEquipSlots[RightHandCurrentEquipIndex].GetComponent<Equipable>().FriendlyName;
|
||
|
|
hudManager.DisplayUIGroup(HUDGroup.EquipmentArea);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|