rabidus-test/Assets/Scripts/StartGameSlot.cs

68 lines
1.7 KiB
C#

using BNG;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartGameSlot : MonoBehaviour
{
private SnapZone _snapZone;
private LeanTimer _leanTimer;
private void Awake()
{
_snapZone = GetComponent<SnapZone>();
_leanTimer = GetComponent<LeanTimer>();
}
private void OnEnable()
{
_snapZone.OnSnapEvent.AddListener(OnSnaped);
_snapZone.OnDetachEvent.AddListener(OnDetach);
}
private void OnDisable()
{
_snapZone.OnSnapEvent.RemoveListener(OnSnaped);
_snapZone.OnDetachEvent.RemoveListener(OnDetach);
}
private void OnSnaped(Grabbable grab)
{
var info = grab.GetComponent<MonumentMini>().Info;
string level = info.SceneName;
bool isAllMapsMode = info.AllMaps;
void LoadSelectedLevel()
{
GlobalSettings.Instance.AllMaps = isAllMapsMode;
PlayerSetup.Instance.CreateNewPlayer();
SceneLoader.Instance.LoadScene(level);
}
void LoadTournament()
{
GlobalSettings.Instance.AllMaps = isAllMapsMode;
PlayerSetup.Instance.CreateNewPlayer();
SceneLoader.Instance.LoadTournament();
}
grab.GetComponent<SnapZoneHelper>().SnapObject();
if (isAllMapsMode)
{
_leanTimer.StartTimer(1, 0, 3, LoadTournament);
}
else
{
_leanTimer.StartTimer(1, 0, 3, LoadSelectedLevel);
}
}
private void OnDetach(Grabbable grab)
{
grab.GetComponent<SnapZoneHelper>().ReleaseObject();
_leanTimer.StopTimer(1);
}
}