using System; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace PrizeSystem { public class PrizeSettingPanel : MonoBehaviour, IControl { [SerializeField] AbstractPrizeConfigurator CurrentConfigurator; [SerializeField] List prizeTypeToPanelMaps; private void Update() => CurrentConfigurator?.Tick(); public void Swipe(int direction) => CurrentConfigurator?.Swipe(direction); public void Switch() => CurrentConfigurator?.ChangeOption(1); public AbstractPrizeConfigurator SetPanelByType(PrizeType newType) { GameObject newPanel; try { PrizeTypeToPanelMap pttp = prizeTypeToPanelMaps.Where(t => t.Type == newType).First(); newPanel = pttp.Panel; } catch { Debug.LogError("Не нашел панель по типу. Вероятно мапинг не заполнен", this); return null; } if (transform.childCount > 0) { Destroy(transform.GetChild(0).gameObject); } var go = Instantiate(newPanel, transform); if(go.TryGetComponent(out var prizeConfigConfigurator)) { CurrentConfigurator = prizeConfigConfigurator; } else { CurrentConfigurator = null; } return CurrentConfigurator; } public void SetPanelByPrize(Prize prize) { var panel = SetPanelByType(prize.PrizeType); panel.Configure(prize); //Конфигурировать панель } public Prize GetPrize() => CurrentConfigurator.GetPrize(); [Serializable] public struct PrizeTypeToPanelMap { public PrizeType Type; public GameObject Panel; } } }