78 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace PrizeSystem
{
public class PrizeSettingPanel : MonoBehaviour
{
[SerializeField] AbstractPrizeConfigurator CurrentConfigurator;
[SerializeField] List<PrizeTypeToPanelMap> 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<AbstractPrizeConfigurator>(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;
}
}
}