mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-23 04:23:04 +00:00
94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
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()
|
|
{
|
|
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();
|
|
|
|
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()
|
|
{
|
|
if (!F.IsAppInEditTime)
|
|
{
|
|
EditorUtility.DisplayDialog("", "Exit play mode first.", "Ok");
|
|
return;
|
|
}
|
|
|
|
if (null == Loader.Singleton)
|
|
{
|
|
new GameObject("Loader", typeof(Loader));
|
|
}
|
|
|
|
Loader.StartLoading();
|
|
}
|
|
|
|
[MenuItem(EditorCore.MenuName + "/" + "Change path to GTA")]
|
|
static void MenuItemChangePath()
|
|
{
|
|
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");
|
|
}
|
|
}
|
|
}
|