75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using XRLib;
|
|
|
|
namespace XED
|
|
{
|
|
public class WorkController : MonoBehaviour, ISingle
|
|
{
|
|
StackerCrane stackerCrane;
|
|
|
|
[SerializeField]
|
|
private GameObject loadPrefab;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
stackerCrane = FindSingle<StackerCrane>();
|
|
stackerCrane.onLoadCompletedEvent += ReArrangeCargo;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.C))
|
|
{
|
|
SpawnCargo();
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.I))
|
|
{
|
|
stackerCrane.AddTask(new StackerCraneTask(ETaskType.Incoming));
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.O))
|
|
{
|
|
stackerCrane.AddTask(new StackerCraneTask(ETaskType.Outgoing));
|
|
}
|
|
|
|
if (stackerCrane.incomeCell.load == null)
|
|
{
|
|
if(readyCargos.Count == 0)
|
|
return;
|
|
|
|
readyCargos.RemoveAt(0);
|
|
|
|
if (readyCargos.Count == 0)
|
|
return;
|
|
|
|
var cargo = readyCargos.First();
|
|
stackerCrane.incomeCell.load = cargo;
|
|
}
|
|
}
|
|
List<GameObject> readyCargos = new();
|
|
int index = 0;
|
|
private void SpawnCargo()
|
|
{
|
|
GameObject cargo = Instantiate(loadPrefab);
|
|
cargo.name = index.ToString();
|
|
index++;
|
|
cargo.transform.parent = stackerCrane.incomeCell.transform;
|
|
cargo.transform.localPosition = new Vector3(0f, stackerCrane.incomeCell.transform.childCount - 0.5f, 0f);
|
|
if (stackerCrane.incomeCell.load == null)
|
|
stackerCrane.incomeCell.load = cargo;
|
|
readyCargos.Add(cargo);
|
|
}
|
|
|
|
public void ReArrangeCargo(StackerCrane sc)
|
|
{
|
|
for (int i = 0; i < stackerCrane.incomeCell.transform.childCount; i++)
|
|
{
|
|
stackerCrane.incomeCell.transform.GetChild(i).transform.localPosition = new Vector3(0f, i + 0.5f, 0f);
|
|
}
|
|
}
|
|
}
|
|
}
|