Reworked Socket + EndPos reset
This commit is contained in:
1 parent
085d330a87
commit
430f676e49
151 files changed
+18194
-18446
No files matched your search
@@ -0,0 +1,276 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class MachineCoordinatesMovementScript : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("XAxis Transform")]
|
||||
Transform XAxis;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("YAxis Transform")]
|
||||
Transform YAxis;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("ZAxis Transform")]
|
||||
Transform ZAxis;
|
||||
|
||||
[SerializeField]
|
||||
Vector3 CurrentCords;
|
||||
|
||||
[SerializeField]
|
||||
float CartXSpeed = 0.1f;
|
||||
|
||||
[SerializeField]
|
||||
float CartYSpeed = 0.1f;
|
||||
|
||||
[SerializeField]
|
||||
float CartZSpeed = 0.1f;
|
||||
|
||||
[SerializeField]
|
||||
int MaterialsToInsert = 0;
|
||||
|
||||
[SerializeField]
|
||||
bool TestProgramStart;
|
||||
|
||||
[SerializeField]
|
||||
bool DebugStart = false;
|
||||
|
||||
[SerializeField]
|
||||
bool Restart = false;
|
||||
|
||||
// Ôëàã ðàáîòû, ïî íåìó ïðîâåðÿåòñÿ, âûïîëíÿåòñÿ ëè ñåé÷àñ êàêàÿ-ëèáî ïðîãðàììà
|
||||
bool WorkInProgress = false;
|
||||
|
||||
[SerializeField]
|
||||
List<bool> InsertedMaterials;
|
||||
|
||||
[SerializeField]
|
||||
List<bool> InsertedReels;
|
||||
|
||||
bool ReadyToWork = false;
|
||||
|
||||
bool ReelsReady = false;
|
||||
|
||||
// Íîìåð îáúåêòà â CurrentProgram, ê êîòîðîìó äâèãàòüñÿ
|
||||
int CurrentStep = 0;
|
||||
|
||||
List<Vector3> CurrentProgram;
|
||||
|
||||
// Ãðàíèöû ïî êîîðäèíàòàì: (0.435, 0.02, 0.4125)
|
||||
|
||||
[SerializeField]
|
||||
GameObject Board;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//DiagonalMoveDbg = false;
|
||||
for (int i = 0; i < MaterialsToInsert; i++)
|
||||
{
|
||||
InsertedMaterials.Add(false);
|
||||
InsertedReels.Add(false);
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
CurrentCords = new(XAxis.localPosition.x, YAxis.localPosition.y, ZAxis.localPosition.z);
|
||||
|
||||
if (DebugStart)
|
||||
{
|
||||
DebugStart = false;
|
||||
StartWork(PalmTreeProg);
|
||||
}
|
||||
|
||||
if (TestProgramStart == true)
|
||||
{
|
||||
TestProgramStart = false;
|
||||
|
||||
if (ReadyToWork)
|
||||
{
|
||||
StartWork(PalmTreeProg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(InsertedMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
if (Restart == true)
|
||||
{
|
||||
if (MoveTo(Vector3.zero))
|
||||
{
|
||||
Restart = false;
|
||||
}
|
||||
}
|
||||
else if (WorkInProgress == true)
|
||||
{
|
||||
if(CurrentStep <= CurrentProgram.Count - 1)
|
||||
{
|
||||
if (MoveTo(CurrentProgram[CurrentStep]))
|
||||
{
|
||||
if(YAxis.localPosition.y > 0) {
|
||||
CurrentProgram[CurrentStep] = new(CurrentProgram[CurrentStep].x, 0, CurrentProgram[CurrentStep].z);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentStep++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkInProgress = false;
|
||||
Restart = true;
|
||||
Board.GetComponent<BoardScript>().ComponentsPlaced();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ôóíêöèÿ íà÷àëà ðàáîòû, ïðèíèìàåò ïðîãðàììó äëÿ ðàáîòû
|
||||
public void StartWork(List<Vector3> program)
|
||||
{
|
||||
WorkInProgress = true;
|
||||
Restart = true;
|
||||
CurrentProgram = new(program);
|
||||
CurrentStep = 0;
|
||||
}
|
||||
|
||||
public void MaterialInserted(int index)
|
||||
{
|
||||
InsertedMaterials[index] = true;
|
||||
|
||||
foreach (bool mat in InsertedMaterials) {
|
||||
if (!mat) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(ReelsReady){
|
||||
ReadyToWork = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReelInserted(int index)
|
||||
{
|
||||
InsertedReels[index] = true;
|
||||
|
||||
foreach (bool reel in InsertedReels) {
|
||||
if (!reel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ReelsReady = true;
|
||||
}
|
||||
|
||||
public void MaterialRemoved(int index)
|
||||
{
|
||||
InsertedMaterials[index] = false;
|
||||
|
||||
ReadyToWork = false;
|
||||
}
|
||||
|
||||
public void ReelRemoved(int index)
|
||||
{
|
||||
InsertedReels[index] = false;
|
||||
|
||||
ReelsReady = false;
|
||||
}
|
||||
|
||||
|
||||
// Âîçâðàùàåò true, êîãäà íàõîäèòñÿ â êîîðäèíàòå, êîòîðóþ ñîîáùèëè
|
||||
bool MoveTo(Vector3 cords)
|
||||
{
|
||||
float XMoveDistance = cords.x - XAxis.localPosition.x;
|
||||
float YMoveDistance = cords.y - YAxis.localPosition.y;
|
||||
float ZMoveDistance = cords.z - ZAxis.localPosition.z;
|
||||
|
||||
if (Mathf.Abs(XMoveDistance) < 0.0001f)
|
||||
{
|
||||
XMoveDistance = 0;
|
||||
}
|
||||
if (Mathf.Abs(YMoveDistance) < 0.0001f)
|
||||
{
|
||||
YMoveDistance = 0;
|
||||
}
|
||||
if (Mathf.Abs(ZMoveDistance) < 0.0001f)
|
||||
{
|
||||
ZMoveDistance = 0;
|
||||
}
|
||||
|
||||
if (Mathf.Abs(XMoveDistance) > 0 || Mathf.Abs(ZMoveDistance) > 0)
|
||||
{
|
||||
float XStep = CartXSpeed * Time.deltaTime;
|
||||
float XMoveAmount = Mathf.Min(XStep, Mathf.Abs(XMoveDistance));
|
||||
|
||||
float ZStep = CartZSpeed * Time.deltaTime;
|
||||
float ZMoveAmount = Mathf.Min(ZStep, Mathf.Abs(ZMoveDistance));
|
||||
|
||||
|
||||
if (XMoveDistance > 0)
|
||||
{
|
||||
XAxis.Translate(XMoveAmount, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
XAxis.Translate(-XMoveAmount, 0, 0);
|
||||
}
|
||||
|
||||
if (ZMoveDistance > 0)
|
||||
{
|
||||
ZAxis.Translate(0, 0, ZMoveAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
ZAxis.Translate(0, 0, -ZMoveAmount);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (Mathf.Abs(YMoveDistance) > 0)
|
||||
{
|
||||
float YStep = CartYSpeed * Time.deltaTime;
|
||||
float YMoveAmount = Mathf.Min(YStep, Mathf.Abs(YMoveDistance));
|
||||
|
||||
if (YMoveDistance > 0)
|
||||
{
|
||||
YAxis.Translate(0, -YMoveAmount, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
YAxis.Translate(0, YMoveAmount, 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
XAxis.localPosition = new(cords.x, XAxis.localPosition.y, XAxis.localPosition.z);
|
||||
YAxis.localPosition = new(YAxis.localPosition.x, cords.y, YAxis.localPosition.z);
|
||||
ZAxis.localPosition = new(ZAxis.localPosition.x, ZAxis.localPosition.y, cords.z);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ãðàíèöû ïî êîîðäèíàòàì: (0.435, 0.02, 0.4125)
|
||||
[SerializeField]
|
||||
List<Vector3> testProgr;
|
||||
|
||||
[SerializeField]
|
||||
List<Vector3> PalmTreeProg;
|
||||
|
||||
public void StartWorkFromButton()
|
||||
{
|
||||
if (!WorkInProgress)
|
||||
{
|
||||
TestProgramStart = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user