Tanoda
TaktTimeInitializer.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5
6public class TaktTimeInitializer : MonoBehaviour
7{
8 public static TaktTimeInitializer Instance { get; private set; }
9 void Start()
10 {
11 Instance = this;
12 }
13
14 // Update is called once per frame
15 void Update()
16 {
17
18 }
19
20 public void ShowTaktTimeWindow()
21 {
22 var currentUserValue = UserManager.instance.GetUserByName(SavedUser.instance.currentUser.Value.Username);
23 var currentTrainingName = SavedUser.instance.levelName;
24 List<UserManager.Training> currentTrainings = new List<UserManager.Training>();
25 var allTraining = currentUserValue.trainings;
26 foreach (var training in allTraining)
27 {
28 if (training.Name == currentTrainingName) currentTrainings.Add(training);
29
30 }
31 var lastTraining = currentTrainings[currentTrainings.Count - 1];
32 var taktTimeHelper = FindObjectOfType<TaktTimeHelper>(true);
33 var actions = lastTraining.Actions;
34 foreach (var action in actions)
35 {
36 if (!Blacklisted(action.actionType))
37 {
38 var actionObject = Controller.Instance.GetActionById(action.actionName);
39
40 var connections = Controller.Instance.GetConnectionsByEndPointId(actionObject.outPuts[0].name);
41 bool outputIsWaiter = false;
42 foreach (var c in connections)
43 {
44 var outputAction = Controller.Instance.GetActionByInOut(c.toId);
45 if (outputAction.action.Contains("Waiter")) outputIsWaiter = true;
46 }
47 GameObject cachedGO = null;
48 if (actionObject is ToolAction ta) cachedGO = ta.GetToolObject();
49 if (actionObject is PositionAction pa) cachedGO = pa.cachedGO;
50 //if (actionObject is HoldToolAction hta) cachedGO = hta.GetToolObject();
51 if (!outputIsWaiter)
52 {
53 var newRow = Instantiate(taktTimeHelper, taktTimeHelper.transform.parent);
54 newRow.actionObject = actionObject;
55 newRow.gameObject.SetActive(true);
56 if (cachedGO) newRow.actionName.text = action.actionType + "\n" + cachedGO.name;
57 else newRow.actionName.text = action.actionType;
58
59 //newRow.time.text = Mathf.FloorToInt(action.timeSpent / 60).ToString("D2") + ":" + (action.timeSpent % 60).ToString("00.00").Replace(',', '.');
60 newRow.GetComponentInChildren<ShowSelection>().actionName = action.actionName;
61 for (int i = 0; i < lastTraining.Actions.Count; i++)
62 {
63 if (lastTraining.Actions[i].actionName == actionObject.name)
64 {
65 //if (lastTraining.Actions[i].taktTime != 0)
66 //{
67 // newRow.time.text = lastTraining.Actions[i].taktTime.ToString();
68 //}
69 //else
70 //{
71 // newRow.time.text = "0";
72 //}
73 newRow.takt.text = actionObject.taktTime.ToString();
74 newRow.spent.text = actionObject.spentTimeOnAction.ToString();
75
76 }
77 }
78 if (actionObject.spentTimeOnAction > actionObject.taktTime)
79 {
80 newRow.takt.color = Color.red;
81 newRow.spent.color = Color.red;
82 newRow.actionName.color = Color.red;
83 }
84 //if (actionObject.taktTime != 0)
85 //{
86 // //actionObject.taktTime = float.Parse(newRow.time.text);
87 // newRow.time.text = actionObject.taktTime.ToString();
88 //}
89 //else
90 //{
91 // newRow.time.text = "0";
92 //}
93
94 }
95
96 }
97
98 }
99 if (taktTimeHelper.transform.parent.childCount < 4)
100 {
101 var children = taktTimeHelper.transform.parent.GetComponentsInChildren<OptimizationHelper>(true);
102 foreach (var child in children)
103 {
104 child.actionName.color = Color.red;
105 child.time.color = Color.red;
106 }
107 }
108 else
109 {
110 var children = taktTimeHelper.transform.parent.GetComponentsInChildren<OptimizationHelper>(true);
111 }
112 }
113
114
115 private bool Blacklisted(string action)
116 {
117 return action.Contains("Countdown") || action.Contains("GameObject") || action.Contains("Weld") ||
118 action.Contains("Led") || action.Contains("Start") || action.Contains("Sound") ||
119 action.Contains("Move") || action.Contains("Belt") || action.Contains("ShowHide") || action.Contains("Deactivate") || action.Contains("Script") || action.Contains("Voice") || action.Contains("Collector") || action.Contains("Finish");
120 }
121
122}
UnityEngine.Color Color
Definition: TestScript.cs:32
Connection[] GetConnectionsByEndPointId(string id)
Definition: Controller.cs:862
ActionObject GetActionByInOut(string id)
Definition: Controller.cs:925
ActionObject GetActionById(string id)
Definition: Controller.cs:950
static Controller Instance
Definition: Controller.cs:16
static TaktTimeInitializer Instance