<feat> 로봇 동기화 (제어기 <-> 3d)
This commit is contained in:
@@ -7,35 +7,80 @@ using UnityEngine;
|
||||
|
||||
public class AppManager : MonoBehaviour
|
||||
{
|
||||
public static AppManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private ProgramView view;
|
||||
[SerializeField] private TCPView tcpView;
|
||||
[SerializeField] private RobotController robotController;
|
||||
|
||||
[SerializeField] private InteractionView interactionView;
|
||||
private InteractionView interactionView;
|
||||
[SerializeField] private PointManagerView pointManagerView;
|
||||
[SerializeField] private PathLineView pathLineView;
|
||||
[SerializeField] private PopupView popupView;
|
||||
|
||||
[SerializeField] private float motorStatePollInterval = 1.0f;
|
||||
public CancellationTokenSource cancellationTokenSource;
|
||||
private bool isModelAndStaticViewsReady = false;
|
||||
private ProgramModel model;
|
||||
private ProgramPresenter presenter;
|
||||
private string hostip;
|
||||
private int tcpPort;
|
||||
private int udpPort;
|
||||
private string configFileName = "config.cfg";
|
||||
private CancellationToken cancellationToken;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
async void Start()
|
||||
{
|
||||
LoadConfig();
|
||||
|
||||
ProgramModel model = new ProgramModel(hostip, tcpPort, udpPort);
|
||||
model = new ProgramModel(hostip, tcpPort, udpPort, robotController);
|
||||
await model.InitializeAsync();
|
||||
_ = model.GetTCPAsync(cancellationToken);
|
||||
|
||||
presenter = new ProgramPresenter(model, view, tcpView, interactionView, pointManagerView, popupView, pathLineView);
|
||||
isModelAndStaticViewsReady = true;
|
||||
TryCreatePresenter();
|
||||
}
|
||||
|
||||
public void RegisterView(InteractionView Iview)
|
||||
{
|
||||
if (this.interactionView != null) return;
|
||||
this.interactionView = Iview;
|
||||
|
||||
TryCreatePresenter();
|
||||
}
|
||||
|
||||
private void TryCreatePresenter()
|
||||
{
|
||||
if (presenter != null) return;
|
||||
|
||||
presenter = new ProgramPresenter(
|
||||
model,
|
||||
view,
|
||||
tcpView,
|
||||
interactionView,
|
||||
pointManagerView,
|
||||
popupView,
|
||||
pathLineView
|
||||
);
|
||||
|
||||
presenter.RegisterControlledRobot(robotController);
|
||||
_ = presenter.UpdateMotorStateAsync();
|
||||
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
_ = model.GetTCPAsync(cancellationTokenSource.Token);
|
||||
_ = model.StartMovementCheckLoopAsync(cancellationTokenSource.Token);
|
||||
|
||||
await presenter.UpdateMotorStateAsync();
|
||||
view.DisplayProgram(null);
|
||||
StartCoroutine(PollMotorStateCoroutine());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user