Added a scene controller
This commit is contained in:
@@ -28,7 +28,6 @@ namespace Fruitomation.Game
|
||||
|
||||
[UsedImplicitly, Preserve, InspectorCallable("Click Building")] public void OnBuildingClicked()
|
||||
{
|
||||
Debug.Log($"Building clicked {gameObject.name}");
|
||||
if (GameStateController.Is(GameState.Editing))
|
||||
{
|
||||
Manager.RemoveBuilding(this);
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace Fruitomation.Game
|
||||
|
||||
info.Building.Init(this, building.GridPosition, building.Position, building.IsFlipped);
|
||||
Buildings.Add(info.Building);
|
||||
|
||||
for (int x = building.GridPosition.x; x < building.GridPosition.x + info.Building.SizeOnGrid.x; x++)
|
||||
for (int y = building.GridPosition.y; y < building.GridPosition.y + info.Building.SizeOnGrid.y; y++)
|
||||
{
|
||||
InhabitedCells[x, y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +104,7 @@ namespace Fruitomation.Game
|
||||
)
|
||||
).ToList();
|
||||
|
||||
string json = JsonUtility.ToJson(new SerializedBuildings(serialized), false);
|
||||
string json = JsonUtility.ToJson(new SerializedBuildings(serialized), true);
|
||||
File.WriteAllText(Filepath, json);
|
||||
}
|
||||
|
||||
|
||||
50
Assets/Scripts/Game/SceneController.cs
Normal file
50
Assets/Scripts/Game/SceneController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using PashaBibko.Pacore.Attributes;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace Fruitomation.Game
|
||||
{
|
||||
[CreateInstanceOnStart] public class SceneController : MonoBehaviour
|
||||
{
|
||||
private static SceneController Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance is not null)
|
||||
{
|
||||
Debug.LogError($"Multiple instances of [{nameof(SceneController)}] cannot exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private IEnumerator StartLoadInternal(string scene)
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(scene);
|
||||
if (operation == null)
|
||||
{
|
||||
string error = $"Unknown scene [{scene}]";
|
||||
throw new ArgumentException(error);
|
||||
}
|
||||
|
||||
operation.allowSceneActivation = false;
|
||||
operation.completed += _ =>
|
||||
{
|
||||
sw.Stop();
|
||||
Debug.Log($"Scene finished loading [Took {sw.ElapsedMilliseconds}ms]");
|
||||
};
|
||||
|
||||
yield return new WaitForSeconds(5f);
|
||||
operation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
public static void StartLoadOf(string scene) => Instance.StartCoroutine(Instance.StartLoadInternal(scene));
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Game/SceneController.cs.meta
Normal file
2
Assets/Scripts/Game/SceneController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d873aa48a3b7c44db3a4bd68b11c113
|
||||
Reference in New Issue
Block a user