using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MPStudio
{
    
[DefaultExecutionOrder(-1)]
public class SceneryManager : MonoBehaviour
{
    
    private Dictionary<int, string> _sceneNames;

    public static SceneryManager Inst;

    private void Awake()
    {
        if (Inst == null)
        {
            Inst = this;
        }
        else if (Inst != this)
        {
            Destroy(gameObject);
        }
    }

    public int GetLvID()
    {
        return SaveManager.Inst.testData.lvID;
    }

    /// <summary>
    ///     加载场景
    /// </summary>
    /// <param name="sceneKey"></param>
    public void LoadScene(int sceneKey)
    {
        if (_sceneNames.ContainsKey(sceneKey))
            UnityEngine. SceneManagement.SceneManager.LoadScene(_sceneNames[sceneKey]);
        else
            throw  new KeyNotFoundException();
    }

    //获取当前场景的名字
    public string GetCurrentLevelName()
    {
        return UnityEngine. SceneManagement.SceneManager.GetActiveScene().name;
    }
    
    public const int MaxLvID = 100;
    
    // Start is called before the first frame update
  protected   virtual void Start()
    {
        
    }

    public static int GetLevelSceneId()
    {
        var name =UnityEngine. SceneManagement.SceneManager.GetActiveScene().name;

        if (name.Contains("Level"))
        {
            return ToolCollect.GetPureNumber(name);
        }
        else
        {
            return -1;
        }
    }

    public static int GetLevelSceneIndex()
    {
        return GetLevelSceneId() - 1;
    }
}
}