83 lines
1.8 KiB
C#
83 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
namespace Salvage.ClothingCuller.Components
|
|
{
|
|
public class ModularClothingSpawner : MonoBehaviour
|
|
{
|
|
private Occludee[] spawnedOccludees;
|
|
|
|
[SerializeField]
|
|
private ClothingCuller clothingCuller;
|
|
|
|
[SerializeField]
|
|
private Occludee body;
|
|
|
|
[SerializeField]
|
|
private Occludee[] clothingPrefabs;
|
|
|
|
private void Awake()
|
|
{
|
|
spawnedOccludees = new Occludee[clothingPrefabs.Length];
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
clothingCuller.Register(body, isModular: false);
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.BeginHorizontal();
|
|
for (int i = 0; i < clothingPrefabs.Length; i++)
|
|
{
|
|
drawEquipOrUnEquipButton(i);
|
|
}
|
|
GUILayout.EndHorizontal();
|
|
}
|
|
|
|
private void drawEquipOrUnEquipButton(int index)
|
|
{
|
|
float num = (float)Camera.main.pixelHeight / 1080f;
|
|
GUIStyle style = new GUIStyle(GUI.skin.button)
|
|
{
|
|
fontSize = (int)(30f * num),
|
|
fixedHeight = 100f * num,
|
|
fixedWidth = 300f * num
|
|
};
|
|
Occludee occludee = spawnedOccludees[index];
|
|
Occludee occludee2 = clothingPrefabs[index];
|
|
if (occludee != null)
|
|
{
|
|
GUI.backgroundColor = Color.red;
|
|
if (GUILayout.Button("Unequip " + occludee.name, style))
|
|
{
|
|
unequip(occludee);
|
|
spawnedOccludees[index] = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GUI.backgroundColor = Color.green;
|
|
if (GUILayout.Button("Equip " + occludee2.name, style))
|
|
{
|
|
spawnedOccludees[index] = equip(occludee2);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Occludee equip(Occludee occludeePrefab)
|
|
{
|
|
Occludee occludee = Object.Instantiate(occludeePrefab, clothingCuller.transform);
|
|
occludee.name = occludeePrefab.name;
|
|
clothingCuller.Register(occludee);
|
|
return occludee;
|
|
}
|
|
|
|
private void unequip(Occludee occludee)
|
|
{
|
|
clothingCuller.Deregister(occludee);
|
|
Object.Destroy(occludee.gameObject);
|
|
}
|
|
}
|
|
}
|