﻿
// Version: 1.0.1

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

namespace GamingIsLove.Makinom
{
	[EditorSettingInfo("Loading Screen Pro", "Uses Loading Screen Pro by Martin Nerurkar for scene loading.")]
	public class LoadingScreenProLoadSceneSetting : BaseLoadSceneSetting
	{
		[EditorHelp("Loading Scene Name", "The name of the loading scene that will be used.\n" +
			"Leave empty to not change the used loading scene.", "")]
		public StringValue<GameObjectSelection> loadingSceneName = new StringValue<GameObjectSelection>();

		[EditorHelp("Stop Screen Fade", "Resets the screen fader to prevent it from blocking view of the loading scene.", "")]
		public bool stopScreenFade = false;

		public LoadingScreenProLoadSceneSetting()
		{

		}

		public override void LoadScene(string sceneName, LoadSceneMode mode)
		{
			string tmp = loadingSceneName.GetValue(new DataCall());
			if(tmp != "")
			{
				Sharklib.LoadingScreen.LoadingScreenConfig.loadingSceneName = tmp;
			}

			LoadingScreenPro.LoadScene(sceneName);

			if(this.stopScreenFade)
			{
				Maki.StartCoroutine(StopFader());
			}
		}

		public override void LoadSceneAsync(string sceneName, LoadSceneMode mode)
		{
			this.LoadScene(sceneName, mode);
		}

		private IEnumerator StopFader()
		{
			yield return null;
			Maki.UI.ScreenFader.Stop();
		}
	}
}
