Сделал работу кнопок программы, начал делать настройки

This commit is contained in:
FreshMix committed 2026-06-17 20:00:56 +03:00
1 parent 9e7457b818
commit a3cccd5530
30 files changed
+15837 -17296

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ControlButtonsScript : MonoBehaviour
{
[SerializeField] private List<string> buttonTitle = new List<string>();
[SerializeField] private List<UnityEngine.UI.Button> buttonObject = new List<UnityEngine.UI.Button>();
public Dictionary<string, UnityEngine.UI.Button> buttonsDictionary { get; private set; }
List<string> activeButtons = new List<string>();
private void Awake()
{
BuildDictionary();
}
private void BuildDictionary()
{
buttonsDictionary = new Dictionary<string, UnityEngine.UI.Button>();
for (int i = 0; i < buttonTitle.Count && i < buttonObject.Count; i++)
{
buttonsDictionary[buttonTitle[i]] = buttonObject[i];
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
//Debug.Log(buttonsDictionary.Count);
disableButtons();
buttonsDictionary["Run"].interactable = true;
}
void disableButtons()
{
foreach (var button in buttonsDictionary.Values)
{
button.interactable = false;
}
activeButtons.Clear();
}
public void SetActiveButtons(List<string> buttonsToActivate)
{
if (activeButtons.SequenceEqual(buttonsToActivate)) return;
disableButtons();
foreach (var button in buttonsToActivate)
{
buttonsDictionary[button].interactable = true;
}
activeButtons = buttonsToActivate;
}
public void RunButtonAction()
{
disableButtons();
buttonsDictionary["Pause"].interactable = true;
buttonsDictionary["Stop"].interactable = true;
}
public void PauseButtonAction()
{
disableButtons();
buttonsDictionary["Run"].interactable = true;
buttonsDictionary["Stop"].interactable = true;
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7cc8690c09bc8744f83cb1b81187fa02
+45
View File
@@ -0,0 +1,45 @@
using UnityEngine;
public class LogsListScript : MonoBehaviour
{
[SerializeField]
UIListElement _ElementTemplate;
private int _lastLogIndex = -1;
private UIListElement createNewElementObject(float y_pos)
{
GameObject newObject = Instantiate(_ElementTemplate.gameObject, _ElementTemplate.transform.parent);
newObject.GetComponent<RectTransform>().localPosition = new(0, y_pos, 0);
newObject.SetActive(true);
return newObject.GetComponent<UIListElement>();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
MachineCoordinatesMovementScript.OnError.AddListener(addLogLine);
//UIListElement newElement;
//for (int i = 0; i < 3; i++)
//{
// _lastLogIndex++;
// newElement = createNewElementObject(-1f * i * _ElementTemplate.GetComponent<RectTransform>().rect.height);
// newElement.SetProperty("Text", "Test " + i);
//}
}
private void addLogLine(string text)
{
_lastLogIndex++;
UIListElement newElement = createNewElementObject(-1f * _lastLogIndex * _ElementTemplate.GetComponent<RectTransform>().rect.height);
newElement.SetProperty("Text", text);
}
// Update is called once per frame
void Update()
{
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 46dc8d26e06bd5a439e548d7a75c9bc2
@@ -1,10 +1,8 @@
using Palmmedia.ReportGenerator.Core;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using System.Linq;
public class MachineCoordinatesMovementScript : MonoBehaviour
{
@@ -21,7 +19,10 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
[Tooltip("ZAxis Transform")]
Transform ZAxis;
[SerializeField]
[SerializeField]
ControlButtonsScript ActionButtonsController;
[SerializeField]
Vector3 CurrentCords;
[SerializeField]
@@ -43,18 +44,22 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
bool DebugStart = false;
[SerializeField]
bool Restart = false;
bool RestartFlag = false;
// Ôëàã ðàáîòû, ïî íåìó ïðîâåðÿåòñÿ, âûïîëíÿåòñÿ ëè ñåé÷àñ êàêàÿ-ëèáî ïðîãðàììà
bool WorkInProgress = false;
bool PauseFlag = false;
bool ErrorFlag = false;
int StepToPause = -1;
[SerializeField]
[SerializeField]
List<bool> InsertedMaterials;
[SerializeField]
List<bool> InsertedReels;
bool ReadyToWork = false;
[SerializeField]
bool ReadyToWork = false;
bool ReelsReady = false;
@@ -69,15 +74,16 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
// Íîìåð îáúåêòà â CurrentProgram, ê êîòîðîìó äâèãàòüñÿ
static public int CurrentStep = 0 ;
static public List<Vector3> CurrentProgram { get; private set; }
static public List<Vector3> ComponentsHoldersCords { get; private set; }
[Serializable]
public class MachineStepEvent : UnityEvent<int> { }
public class MachineErrorEvent : UnityEvent<string> { }
[Tooltip("Event called when step updated")]
public static MachineStepEvent OnStep = new MachineStepEvent();
public static MachineStepEvent OnStep = new();
public static MachineErrorEvent OnError = new();
// Ãðàíèöû ïî êîîðäèíàòàì: (0.435, 0.02, 0.4125)
@@ -106,29 +112,24 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
StartWork(PalmTreeProg);
}
if (TestProgramStart == true)
{
TestProgramStart = false;
if (ReadyToWork)
{
StartWork(PalmTreeProg);
}
else
{
Debug.Log(InsertedMaterials);
}
}
setActiveActionButtons();
if (Restart == true)
if (RestartFlag == true)
{
if (MoveTo(Vector3.zero))
{
Restart = false;
RestartFlag = false;
}
}
else if (WorkInProgress == true)
{
if (PauseFlag)
{
return;
}
if(CurrentStep <= CurrentProgram.Count - 1)
{
if (MoveTo(CurrentProgram[CurrentStep]))
@@ -143,22 +144,60 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
}
}
if(StepToPause != -1 && StepToPause == CurrentStep)
{
PauseFlag = true;
StepToPause = -1;
}
}
else
{
WorkInProgress = false;
Restart = true;
resetFlags();
RestartFlag = true;
Board.GetComponent<BoardScript>().ComponentsPlaced();
}
}
}
}
void setActiveActionButtons()
{
List<string> buttonsToActivate = new List<string>();
if (WorkInProgress)
{
buttonsToActivate.Add("Stop");
if (PauseFlag)
{
buttonsToActivate.Add("Run");
buttonsToActivate.Add("Step");
}
else
{
buttonsToActivate.Add("Pause");
}
}
else if (ErrorFlag)
{
buttonsToActivate.Add("Reset");
}
else
{
buttonsToActivate.Add("Run");
buttonsToActivate.Add("Step");
}
ActionButtonsController.SetActiveButtons(buttonsToActivate);
}
// Ôóíêöèÿ íà÷àëà ðàáîòû, ïðèíèìàåò ïðîãðàììó äëÿ ðàáîòû
public void StartWork(List<Vector3> program)
{
WorkInProgress = true;
Restart = true;
CurrentProgram = new(program);
RestartFlag = true;
CurrentProgram = new(program);
CurrentStep = 0;
OnStep?.Invoke(CurrentStep);
}
@@ -286,12 +325,83 @@ public class MachineCoordinatesMovementScript : MonoBehaviour
public void StartWorkFromButton()
{
if (!WorkInProgress)
if (!WorkInProgress)
{
TestProgramStart = true;
if (ReadyToWork)
{
StartWork(PalmTreeProg);
}
else
{
OnError?.Invoke(DateTime.Now + " Error: " + "Materials not inserted: " + InsertedMaterials.Count(b => b) + " / 3.");
//Debug.Log(InsertedMaterials);
}
}
else if (PauseFlag)
{
StepToPause = -1;
PauseFlag = false;
}
}
public void PauseWorkFromButton()
{
if (WorkInProgress)
{
PauseFlag = !PauseFlag;
}
}
public void StopWorkFromButton()
{
resetFlags();
ErrorFlag = true;
OnError?.Invoke(DateTime.Now + " Error: " + "Stopped from button.");
}
public void ResetFromButton()
{
OnError?.Invoke("To start work again press Run, to continue press Step.");
resetFlags();
RestartFlag = true;
}
public void StepFromButton()
{
if (!WorkInProgress)
{
if (CurrentStep != 0) WorkInProgress = true; // Для продолжения работы после остановки
else if (ReadyToWork)
{
StartWork(PalmTreeProg);
StepToPause = CurrentStep + 1;
}
else
{
OnError?.Invoke(DateTime.Now + " Error: " + "Materials not inserted: " + InsertedMaterials.Count(b => b) + " / 3.");
//Debug.Log(InsertedMaterials);
}
}
else if (PauseFlag)
{
StepToPause = CurrentStep + 1;
PauseFlag = false;
}
}
private void resetFlags()
{
WorkInProgress = false;
ErrorFlag = false;
PauseFlag = false;
RestartFlag = false;
}
}
+26 -16
View File
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using TMPro;
@@ -8,10 +8,10 @@ using UnityEngine.UI;
public class PositionListScript : MonoBehaviour
{
[SerializeField]
PositionListElement _positionListElementTemplate;
UIListElement _ElementTemplate;
[SerializeField]
List<PositionListElement> _positionsList = new();
List<UIListElement> _positionsList = new();
// Start is called once before the first execution of Update after the MonoBehaviour is created
@@ -29,11 +29,11 @@ public class PositionListScript : MonoBehaviour
private void fillList()
{
PositionListElement newElement;
UIListElement newElement;
for (int i = 1; i < MachineCoordinatesMovementScript.CurrentProgram.Count; i += 2)
{
newElement = createNewElementObject(-1f * (i - 1) * _positionListElementTemplate.GetComponent<RectTransform>().rect.height / 2);
newElement = createNewElementObject(-1f * (i - 1) * _ElementTemplate.GetComponent<RectTransform>().rect.height / 2);
_positionsList.Add(newElement);
@@ -47,19 +47,23 @@ public class PositionListScript : MonoBehaviour
{
case 0:
newElement.SetProperty("Name", "R6");
break;
newElement.SetProperty("A", "0");
break;
case 1:
newElement.SetProperty("Name", "C2");
break;
newElement.SetProperty("A", "90");
break;
case 2:
newElement.SetProperty("Name", "C1");
break;
newElement.SetProperty("A", "90");
break;
case 3:
newElement.SetProperty("Name", "LED3");
break;
newElement.SetProperty("A", "0");
break;
default:
break;
@@ -68,26 +72,32 @@ public class PositionListScript : MonoBehaviour
newElement.SetProperty("X", MachineCoordinatesMovementScript.CurrentProgram[i].x.ToString());
newElement.SetProperty("Y", MachineCoordinatesMovementScript.CurrentProgram[i].y.ToString());
newElement.SetProperty("Z", MachineCoordinatesMovementScript.CurrentProgram[i].z.ToString());
newElement.SetProperty("A", "1");
newElement.SetProperty("Val", "1");
newElement.SetProperty("Feeder", "B");
}
}
private PositionListElement createNewElementObject(float y_pos)
private UIListElement createNewElementObject(float y_pos)
{
GameObject newObject = Instantiate(_positionListElementTemplate.gameObject, _positionListElementTemplate.transform.parent);
GameObject newObject = Instantiate(_ElementTemplate.gameObject, _ElementTemplate.transform.parent);
newObject.GetComponent<RectTransform>().localPosition = new(0, y_pos, 0);
newObject.SetActive(true);
return newObject.GetComponent<PositionListElement>();
return newObject.GetComponent<UIListElement>();
}
private void OnStepUpdate(int step)
{
{
if (step == 0)
{
foreach (UIListElement element in _positionsList) { // Сброс на случай, если начата работа заново после остановки
element.SetProperty("State", "");
}
}
if (step % 2 == 0)
{
PositionListElement currentElement = _positionsList[step / 2];
UIListElement currentElement = _positionsList[step / 2];
currentElement.SetProperty("State", "Work");
@@ -95,7 +105,7 @@ public class PositionListScript : MonoBehaviour
if (step == 0) return;
PositionListElement prevElement = _positionsList[(step / 2) - 1];
UIListElement prevElement = _positionsList[(step / 2) - 1];
prevElement.SetProperty("State", "Ok");
@@ -3,7 +3,7 @@ using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PositionListElement : MonoBehaviour
public class UIListElement : MonoBehaviour
{
[SerializeField] private List<string> propertyTitle = new List<string>();
[SerializeField] private List<TextMeshProUGUI> propertyTextObject = new List<TextMeshProUGUI>();