SanAndreasUnity/Assets/Scripts/Editor/EditorLoader.cs

95 lines
2.8 KiB
C#
Raw Normal View History

using SanAndreasUnity.Behaviours;
using SanAndreasUnity.Utilities;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace SanAndreasUnity.Editor
{
public class EditorLoader
{
[InitializeOnLoadMethod]
static void Init()
{
EditorApplication.update -= EditorUpdate;
EditorApplication.update += EditorUpdate;
Loader.onLoadingFinished -= OnLoadingFinished;
Loader.onLoadingFinished += OnLoadingFinished;
}
static void EditorUpdate()
{
2022-01-21 00:36:27 +00:00
if (!F.IsAppInEditTime)
return;
if (Loader.IsLoading)
{
if (EditorUtility.DisplayCancelableProgressBar("Loading game data", Loader.LoadingStatus, Loader.GetProgressPerc()))
{
Loader.StopLoading();
EditorUtility.ClearProgressBar();
return;
}
}
}
static void OnLoadingFinished()
{
EditorUtility.ClearProgressBar();
2022-01-21 23:25:31 +00:00
if (Loader.HasLoaded)
EditorUtility.DisplayDialog("", "Successfully loaded game data.", "Ok");
else
EditorUtility.DisplayDialog("", "Error in loading game data. Check console for more information.", "Ok");
}
[MenuItem(EditorCore.MenuName + "/" + "Load game data")]
static void MenuItemLoadGameData()
{
2022-01-21 00:36:27 +00:00
if (!F.IsAppInEditTime)
{
EditorUtility.DisplayDialog("", "Exit play mode first.", "Ok");
return;
}
2022-01-21 00:36:27 +00:00
if (null == Loader.Singleton)
{
new GameObject("Loader", typeof(Loader));
}
Loader.StartLoading();
}
[MenuItem(EditorCore.MenuName + "/" + "Change path to GTA")]
static void MenuItemChangePath()
{
2022-01-21 00:36:27 +00:00
if (!F.IsAppInEditTime)
{
EditorUtility.DisplayDialog("", "Exit play mode first.", "Ok");
return;
}
Config.Load();
string selectedFolder = EditorUtility.OpenFolderPanel("Select GTA installation folder", Config.GamePath ?? "", "");
if (string.IsNullOrWhiteSpace(selectedFolder))
{
return;
}
if (!Loader.IsGamePathCorrect(selectedFolder, out string errorMessage))
{
EditorUtility.DisplayDialog("", "Selected folder is not valid:\r\n\r\n" + errorMessage, "Ok");
return;
}
Config.SetString(Config.const_game_dir, selectedFolder);
Config.SaveUserConfig();
EditorUtility.DisplayDialog("", "Successfully changed path.", "Ok");
}
}
}