rabidus-test/Assets/Scripts/StartGameSlot.cs

68 lines
1.7 KiB
C#
Raw Normal View History

2023-09-11 15:44:17 +03:00
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)
{
2023-10-02 19:12:35 +03:00
var info = grab.GetComponent<MonumentMini>().Info;
string level = info.SceneName;
bool isAllMapsMode = info.AllMaps;
2023-09-11 15:44:17 +03:00
void LoadSelectedLevel()
2023-10-13 14:13:44 +03:00
{
GlobalSettings.Instance.AllMaps = isAllMapsMode;
PlayerSetup.Instance.CreateNewPlayer();
SceneLoader.Instance.LoadScene(level);
}
void LoadTournament()
2023-09-11 15:44:17 +03:00
{
2023-10-10 17:25:59 +03:00
GlobalSettings.Instance.AllMaps = isAllMapsMode;
2023-10-05 17:56:59 +03:00
PlayerSetup.Instance.CreateNewPlayer();
2023-10-11 11:58:06 +03:00
SceneLoader.Instance.LoadTournament();
2023-09-11 15:44:17 +03:00
}
2023-10-02 19:12:35 +03:00
grab.GetComponent<SnapZoneHelper>().SnapObject();
2023-10-13 14:13:44 +03:00
if (isAllMapsMode)
{
_leanTimer.StartTimer(1, 0, 3, LoadTournament);
}
else
{
_leanTimer.StartTimer(1, 0, 3, LoadSelectedLevel);
}
2023-09-11 15:44:17 +03:00
}
private void OnDetach(Grabbable grab)
{
2023-10-02 19:12:35 +03:00
grab.GetComponent<SnapZoneHelper>().ReleaseObject();
2023-09-18 20:09:22 +03:00
_leanTimer.StopTimer(1);
2023-09-11 15:44:17 +03:00
}
}