initial
This commit is contained in:
1 parent
75fa7ab38c
commit
c9424320ae
1425 files changed
+484748
-5
No files matched your search
@@ -0,0 +1,255 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class XYCoordinatesMovementScript : 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 Restart = false;
|
||||
|
||||
// Ôëàã ðàáîòû, ïî íåìó ïðîâåðÿåòñÿ, âûïîëíÿåòñÿ ëè ñåé÷àñ êàêàÿ-ëèáî ïðîãðàììà
|
||||
bool WorkInProgress = false;
|
||||
|
||||
[SerializeField]
|
||||
List<bool> InsertedMaterials;
|
||||
|
||||
bool ReadyToWork = false;
|
||||
|
||||
// Íîìåð îáúåêòà â CurrentProgram, ê êîòîðîìó äâèãàòüñÿ
|
||||
int CurrentStep = 0;
|
||||
|
||||
//float test = float.Parse("0.11", CultureInfo.InvariantCulture);
|
||||
|
||||
List<Vector3> CurrentProgram;
|
||||
|
||||
// Ãðàíèöû ïî êîîðäèíàòàì: (0.435, 0.02, 0.4125)
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
//DiagonalMoveDbg = false;
|
||||
for (int i = 0; i < MaterialsToInsert; i++)
|
||||
{
|
||||
InsertedMaterials.Add(false);
|
||||
}
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
CurrentCords = new(XAxis.localPosition.x, YAxis.localPosition.y, ZAxis.localPosition.z);
|
||||
|
||||
/* if (DiagonalMoveDbg == true)
|
||||
{
|
||||
XAxis.Translate(CartXSpeed * Time.deltaTime, 0, 0);
|
||||
ZAxis.Translate(0, 0, CartZSpeed * Time.deltaTime);
|
||||
}*/
|
||||
|
||||
if (TestProgramStart == true)
|
||||
{
|
||||
TestProgramStart = false;
|
||||
//Debug.Log(testProgr);
|
||||
|
||||
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)
|
||||
{
|
||||
//Debug.Log(1);
|
||||
if (MoveTo(CurrentProgram[CurrentStep]))
|
||||
{
|
||||
//Debug.Log(2 + " " + YAxis.localPosition.y);
|
||||
if(YAxis.localPosition.y > 0) {
|
||||
CurrentProgram[CurrentStep] = new(CurrentProgram[CurrentStep].x, 0, CurrentProgram[CurrentStep].z);
|
||||
//Debug.Log(3);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Debug.Log(4);
|
||||
CurrentStep++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WorkInProgress = false;
|
||||
Restart = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Ôóíêöèÿ íà÷àëà ðàáîòû, ïðèíèìàåò ïðîãðàììó äëÿ ðàáîòû
|
||||
public void StartWork(List<Vector3> program)
|
||||
{
|
||||
WorkInProgress = true;
|
||||
Restart = true;
|
||||
CurrentProgram = new(program);
|
||||
CurrentStep = 0;
|
||||
|
||||
//TargetCords = new(CurrentProgram[CurrentStep]);
|
||||
}
|
||||
|
||||
public void MaterialInserted(int index)
|
||||
{
|
||||
InsertedMaterials[index] = true;
|
||||
|
||||
foreach (bool mat in InsertedMaterials) {
|
||||
if (!mat) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ReadyToWork = true;
|
||||
}
|
||||
|
||||
public void MaterialRemoved(int index)
|
||||
{
|
||||
InsertedMaterials[index] = false;
|
||||
|
||||
ReadyToWork = 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));
|
||||
|
||||
//Debug.Log("Òåêóùèé óãîë: " + Cover.localEulerAngles.y + "\nÍà ñêîëüêî ïîâåðí¸ì: " + rotationAmount + "\nØàã ðàñ÷èòàííûé ÷åðåç ñêîðîñòü: " + step + "\nÐàçíèöà ìåæäó öåëüþ è òåêóùèì: " + AngleDifference + "\nÂðåìÿ: " + Time.deltaTime);
|
||||
|
||||
// òåêóùèé - çàäàííûé = + (120 - 0) -> çàêðûòèå -> -rotationAmount
|
||||
|
||||
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;
|
||||
//Debug.Log("Òåêóùèé óãîë: " + transform.localEulerAngles.z + "\nÍà ñêîëüêî ïîâåðí¸ì: " + rotationAmount + "\nØàã ðàñ÷èòàííûé ÷åðåç ñêîðîñòü: " + step + "\nÐàçíèöà ìåæäó öåëüþ è òåêóùèì: " + Mathf.Abs(transform.localEulerAngles.z - target_angle) + "\nÂðåìÿ: " + delttm);
|
||||
}
|
||||
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