using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Entities.SyncBases;
using Cyber.Util;
using Cyber.Items;
namespace Cyber.Controls {
///
/// Interface that controls the visible equipment on the characters.
///
public class EquipmentInterface : MonoBehaviour {
///
/// Equipment mesh.
///
[System.Serializable]
public struct EquipmentMesh {
///
/// The slot enum of the item.
///
public EquipSlot Slot;
///
/// The in-world slot of the item.
///
public MeshFilter Mesh;
}
///
/// The inventory.
///
public Inventory Inventory;
///
/// How many times per second the visual equipment should be updated.
///
public float UpdateFrequency = 1f;
///
/// The slots where the equipped items go.
///
public EquipmentMesh[] Slots;
private float LastUpdateTime = 0;
private void Update() {
if (Time.time - LastUpdateTime >= 1f / UpdateFrequency) {
Dictionary Equips = Inventory.Equipped.GetEquippedDict();
// Empty all slots
for (int i = 0; i < Slots.Length; i++) {
Slots[i].Mesh.mesh = null;
}
// Equip all slots
foreach (EquipSlot Slot in Equips.Keys) {
for (int i = 0; i < Slots.Length; i++) {
if (Slots[i].Slot == Slot) {
Slots[i].Mesh.mesh = MeshDB.GetMesh(Equips[Slots[i].Slot].ModelID);
break;
}
}
}
LastUpdateTime = Time.time;
}
}
}
}