using System.Collections.Generic; using UnityEngine; using UnityEngine.Serialization; namespace UnityTest.ZXL { public class CharacterInfo : MonoBehaviour { [SerializeField] private ClothingType clothingType; [SerializeField] private List list = new List(); public void SetCloth(string str) { ClothingData go = null; foreach (var data in list) { if (data.name == str) { go = data; } } if (go != null) { foreach (var clothingData in list) { clothingData.HideAll(); } go.ShowAll(); } else { Debug.LogError($"the info dont have {str}"); } } } [System.Serializable] public class ClothingData { public string name; [FormerlySerializedAs("go")] public List gos; public void HideAll() { foreach (var gameObject in gos) { gameObject.SetActive(false); } } public void ShowAll() { foreach (var gameObject in gos) { gameObject.SetActive(true); } } } public enum ClothingType { 衣服, 呼吸器, 头盔, 手套, 鞋子, } }