111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class App : MonoBehaviour
|
|
{
|
|
public static ScriptVM VM { get; private set; }
|
|
public static ScriptLoader Loader { get; private set; }
|
|
public static GameState GameState { get; private set; }
|
|
public static CameraController CameraController { get; private set; }
|
|
public static UIManager UI { get; private set; }
|
|
public static TextManager TextManager { get; private set; }
|
|
public static VideoPlayer VideoPlayer { get; private set; }
|
|
public static SceneLoader SceneLoader { get; private set; }
|
|
public static ResourceManager ResourceManager { get; private set; }
|
|
|
|
public const float Ps1FPS = 60f;
|
|
|
|
|
|
[SerializeField] private string startScript;
|
|
|
|
void Awake()
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
InitializeManagers();
|
|
|
|
// ÓÁÈÐÀÅÌ àâòîçàãðóçêó - òîëüêî ïî F1
|
|
}
|
|
|
|
private void InitializeManagers()
|
|
{
|
|
// Ñîçäàåì âñå ìåíåäæåðû
|
|
GameState = new GameObject("GameState").AddComponent<GameState>();
|
|
GameState.IsPlayerControlLocked = true;
|
|
DontDestroyOnLoad(GameState.gameObject);
|
|
|
|
|
|
ControlsController controlsController = new GameObject("ControlsController").AddComponent<ControlsController>(); //TODO: Set On Scene
|
|
DontDestroyOnLoad(controlsController.gameObject);
|
|
|
|
ResourceManager = new GameObject("ResourceManager").AddComponent<ResourceManager>();
|
|
DontDestroyOnLoad(ResourceManager.gameObject);
|
|
|
|
CameraController = FindFirstObjectByType<CameraController>();
|
|
DontDestroyOnLoad(CameraController.gameObject);
|
|
|
|
UI = FindFirstObjectByType<UIManager>();
|
|
if (UI == null)
|
|
{
|
|
Debug.LogError("UIManager not found on scene! Please add UIManager component to a GameObject.");
|
|
return;
|
|
}
|
|
UI.Initialize(); // Âàæíî: èíèöèàëèçèðóåì çäåñü!
|
|
DontDestroyOnLoad(UI.gameObject);
|
|
|
|
TextManager = new GameObject("TextManager").AddComponent<TextManager>();
|
|
DontDestroyOnLoad(TextManager.gameObject);
|
|
|
|
// Îñòàëüíûå ìåíåäæåðû
|
|
Loader = new ScriptLoader();
|
|
SceneLoader = gameObject.AddComponent<SceneLoader>();
|
|
VM = gameObject.AddComponent<ScriptVM>();
|
|
}
|
|
|
|
public void LoadScriptFromFile(string filePath)
|
|
{
|
|
string fullPath = Path.Combine(Application.streamingAssetsPath, filePath);
|
|
|
|
if (File.Exists(fullPath))
|
|
{
|
|
byte[] scriptData = File.ReadAllBytes(fullPath);
|
|
Script script = Loader.Load(scriptData);
|
|
VM.LoadAndRunScript(script);
|
|
Debug.Log($"Script loaded from: {fullPath}");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"File not found: {fullPath}");
|
|
}
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
// Çàãðóçêà ñêðèïòà òîëüêî ïî F1
|
|
if (Input.GetKeyDown(KeyCode.F1))
|
|
{
|
|
// Çàãðóæàåì êîíêðåòíûé áèíàðíûé ôàéë
|
|
LoadScriptFromFile("Events/" + startScript + ".TRNSL");
|
|
}
|
|
|
|
// Äëÿ äåáàãà
|
|
if (Input.GetKeyDown(KeyCode.F2))
|
|
{
|
|
if (VM.IsRunning)
|
|
{
|
|
Debug.Log("Script is running");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No script running");
|
|
}
|
|
}
|
|
|
|
// Äëÿ îñòàíîâêè ñêðèïòà
|
|
if (Input.GetKeyDown(KeyCode.F3))
|
|
{
|
|
// TODO: Äîáàâèòü ìåòîä îñòàíîâêè â VM
|
|
Debug.Log("Stop script requested");
|
|
}
|
|
}
|
|
} |