mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
Manage simulator via script
This commit is contained in:
parent
553d229cb9
commit
11b45219ac
8 changed files with 67 additions and 63 deletions
45
Assets/Scenes/Neighborhood.unity
generated
45
Assets/Scenes/Neighborhood.unity
generated
|
@ -302,51 +302,6 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: e110dc8964f72d54e82c846c2a6a37c8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &641803311
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 641803313}
|
||||
- component: {fileID: 641803312}
|
||||
m_Layer: 0
|
||||
m_Name: Neighborhood Simulation
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &641803312
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 641803311}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 695349b682404ab4281ad85c1612b41d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
SimulationContext: 2
|
||||
TickRate: 20
|
||||
--- !u!4 &641803313
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 641803311}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 384.94568, y: 523.42, z: 24.198853}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 8
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &779771439
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace OpenTS2.Content
|
|||
if (NeighborhoodManager.Instance.CurrentNeighborhood == null)
|
||||
throw new Exception("Must be in a neighborhood to enter CAS!");
|
||||
InCAS = true;
|
||||
NeighborhoodManager.Instance.EnterLot(ContentManager.Instance.GetAsset<BaseLotInfoAsset>(CASLotKey));
|
||||
LotManager.Instance.EnterLot(ContentManager.Instance.GetAsset<BaseLotInfoAsset>(CASLotKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
Assets/Scripts/OpenTS2/Content/LotManager.cs
Normal file
33
Assets/Scripts/OpenTS2/Content/LotManager.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using OpenTS2.Content.DBPF;
|
||||
using OpenTS2.Engine;
|
||||
using OpenTS2.Game;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenTS2.Content
|
||||
{
|
||||
public class LotManager
|
||||
{
|
||||
public static LotManager Instance { get; private set; }
|
||||
|
||||
public LotManager()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void EnterLot(BaseLotInfoAsset baseLotInfo)
|
||||
{
|
||||
if (NeighborhoodManager.Instance.CurrentNeighborhood == null)
|
||||
throw new Exception("Must be in a neighborhood to enter a lot");
|
||||
ContentManager.Instance.Changes.SaveChanges();
|
||||
Core.OnLotLoaded?.Invoke();
|
||||
var simulator = Simulator.Instance;
|
||||
if (simulator != null)
|
||||
simulator.Kill();
|
||||
var lotSimulator = Simulator.Create(Simulator.Context.Lot);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/OpenTS2/Content/LotManager.cs.meta
generated
Normal file
11
Assets/Scripts/OpenTS2/Content/LotManager.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f75a889520a01ab4ab79d582b5a36e66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -13,6 +13,7 @@ using UnityEngine;
|
|||
using UnityEngine.SceneManagement;
|
||||
using OpenTS2.Rendering;
|
||||
using OpenTS2.Engine;
|
||||
using OpenTS2.Game;
|
||||
|
||||
namespace OpenTS2.Content
|
||||
{
|
||||
|
@ -73,13 +74,5 @@ namespace OpenTS2.Content
|
|||
SceneManager.LoadScene("Neighborhood");
|
||||
CursorController.Cursor = CursorController.CursorType.Default;
|
||||
}
|
||||
|
||||
public void EnterLot(BaseLotInfoAsset baseLotInfo)
|
||||
{
|
||||
if (CurrentNeighborhood == null)
|
||||
throw new Exception("Must be in a neighborhood to enter a lot");
|
||||
ContentManager.Instance.Changes.SaveChanges();
|
||||
Core.OnLotLoaded?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace OpenTS2.Engine
|
|||
var objectManager = new ObjectManager();
|
||||
var nhoodManager = new NeighborhoodManager();
|
||||
var casController = new CASController();
|
||||
var lotManger = new LotManager();
|
||||
|
||||
TerrainManager.Initialize();
|
||||
MaterialManager.Initialize();
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace OpenTS2.Game
|
|||
{
|
||||
public class Simulator : MonoBehaviour
|
||||
{
|
||||
public static Simulator Instance { get; private set; }
|
||||
public VM VirtualMachine => _virtualMachine;
|
||||
private VM _virtualMachine;
|
||||
public Context SimulationContext = Context.Neighborhood;
|
||||
|
@ -24,11 +25,10 @@ namespace OpenTS2.Game
|
|||
/// Number of ticks to run per second.
|
||||
/// </summary>
|
||||
public int TickRate = 20;
|
||||
private static Simulator _instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
Instance = this;
|
||||
_virtualMachine = new VM();
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,6 @@ namespace OpenTS2.Game
|
|||
CreateGlobalObjects();
|
||||
}
|
||||
|
||||
public Simulator Get()
|
||||
{
|
||||
if (_instance != null)
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void CreateGlobalObjects()
|
||||
{
|
||||
var objects = ObjectManager.Instance.Objects;
|
||||
|
@ -88,5 +81,18 @@ namespace OpenTS2.Game
|
|||
{
|
||||
Debug.LogError(exception.ToString());
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public static Simulator Create(Context context)
|
||||
{
|
||||
var gameObject = new GameObject($"{context} Simulation");
|
||||
var simulator = gameObject.AddComponent<Simulator>();
|
||||
simulator.SimulationContext = context;
|
||||
return simulator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using OpenTS2.Content;
|
||||
using OpenTS2.Engine;
|
||||
using OpenTS2.Game;
|
||||
using OpenTS2.UI.Layouts;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@ -14,6 +15,10 @@ namespace OpenTS2.Scenes
|
|||
{
|
||||
Core.OnNeighborhoodEntered?.Invoke();
|
||||
var hud = new NeighborhoodHUD();
|
||||
var simulator = Simulator.Instance;
|
||||
if (simulator != null)
|
||||
simulator.Kill();
|
||||
var nhoodSimulator = Simulator.Create(Simulator.Context.Neighborhood);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue