78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace PrizeSystem
|
|
{
|
|
public class PrizeSettingPanel : MonoBehaviour, IControl
|
|
{
|
|
[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;
|
|
}
|
|
}
|
|
|
|
} |