|
@@ -2,11 +2,13 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Threading;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
public class WorkerController : MonoBehaviour
|
|
|
{
|
|
|
+ public static Dictionary<uint, List<Structure>> Workers = new Dictionary<uint, List<Structure>>();
|
|
|
List<Structure> structures = new List<Structure>();
|
|
|
public static List<Structure> TestStructures = new List<Structure>();
|
|
|
List<DateTime> dates = new List<DateTime>();
|
|
@@ -15,24 +17,35 @@ public class WorkerController : MonoBehaviour
|
|
|
public GameObject WorkersList;
|
|
|
public Dropdown DropdownLocation;
|
|
|
public Dropdown DropdownData;
|
|
|
+ public InputField inputField_date;
|
|
|
+ public InputField inputField_location;
|
|
|
public GameObject StartHour;
|
|
|
public GameObject StartMin;
|
|
|
public GameObject StartSec;
|
|
|
public GameObject EndHour;
|
|
|
public GameObject EndMin;
|
|
|
public GameObject EndSec;
|
|
|
- public GameObject StartStop;
|
|
|
+ public GameObject StartStopButton;
|
|
|
|
|
|
static Client client = new Client();
|
|
|
|
|
|
+ public List<GameObject> maps;
|
|
|
+ static List<bool> starting = new List<bool>();
|
|
|
+ public static Dictionary<uint, bool> end_send = new Dictionary<uint, bool>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
void Start()
|
|
|
{
|
|
|
- System.Random rnd = new System.Random();
|
|
|
+ WorkerMarker(4);
|
|
|
+ WorkerMarker(356);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -56,31 +69,48 @@ public class WorkerController : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
|
|
- foreach(var s in structures.Select(s => s.acc_id).Distinct())
|
|
|
- WorkerMarker(s);
|
|
|
+ foreach (var s in structures.Select(s => s.acc_id).Distinct())
|
|
|
+ WorkerMarker(s);
|
|
|
|
|
|
foreach (var s in structures.Select(s => s.ts.Date).Distinct())
|
|
|
{
|
|
|
dates.Add(s);
|
|
|
- DropdownData.options.Add(new Dropdown.OptionData(s.ToString("dd/MM/yyyy")));
|
|
|
+ DropdownData.options.Add(new Dropdown.OptionData(s.ToString("dd.MM.yyyy")));
|
|
|
}
|
|
|
|
|
|
- foreach (var s in structures.Select(s => s.location_id).Distinct())
|
|
|
- {
|
|
|
- locations.Add(s);
|
|
|
- DropdownLocation.options.Add(new Dropdown.OptionData($"{s}"));
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DropdownLocation.options.Add(new Dropdown.OptionData("22 Офис Ижевск"));
|
|
|
+ DropdownLocation.options.Add(new Dropdown.OptionData("25"));
|
|
|
+ inputField_date.text = DateTime.Now.ToString("dd.MM.yyyy");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ int active_location = 0;
|
|
|
|
|
|
void Update()
|
|
|
{
|
|
|
- foreach (var m in markers)
|
|
|
- m.marker.SetActive(m.toggle.isOn);
|
|
|
+ if (active_location != DropdownLocation.value)
|
|
|
+ {
|
|
|
+ maps.ElementAt(active_location).SetActive(false);
|
|
|
+ maps.ElementAt(DropdownLocation.value).SetActive(true);
|
|
|
+ active_location = DropdownLocation.value;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var m in markers)
|
|
|
+ {
|
|
|
+ m.marker.SetActive(m.toggle.isOn);
|
|
|
+ if (m.toggle.isOn && Workers.ContainsKey(m.acc_id) && starting.Last() && end_send[m.acc_id])
|
|
|
+ {
|
|
|
+ end_send[m.acc_id] = false;
|
|
|
+ StartingAccPositiong(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- List<Marker> markers = new List<Marker>();
|
|
|
- class Marker
|
|
|
+ public static List<Marker> markers = new List<Marker>();
|
|
|
+ public class Marker
|
|
|
{
|
|
|
public Toggle toggle { get; set; }
|
|
|
public GameObject marker { get; set; }
|
|
@@ -115,33 +145,40 @@ public class WorkerController : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
|
|
- static IEnumerator MarkerPostion(float pause,float step, Vector3 start_pos, Vector3 end_pos, GameObject worker_marker, Toggle toggle, Structure w)
|
|
|
+ static IEnumerator MarkerPostion(float pause,float step, Vector3 start_pos, Vector3 end_pos, GameObject worker_marker, Toggle toggle, Structure w, int count)
|
|
|
{
|
|
|
yield return new WaitForSeconds(pause);
|
|
|
-
|
|
|
- if (worker_marker.activeSelf == true && start)
|
|
|
+ if (worker_marker.activeSelf == true && start && starting.ElementAt(count))
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
var x_position = Mathf.Lerp(start_pos.x, end_pos.x, step);
|
|
|
var y_position = Mathf.Lerp(start_pos.z, end_pos.z, step);
|
|
|
|
|
|
worker_marker.transform.position = new Vector3(x_position, 0.5f, y_position);
|
|
|
toggle.transform.GetChild(1).gameObject.GetComponent<Text>().text = $"{w.acc_id} {w.ts.ToString("hh:mm:ss")}";
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static IEnumerator RequestPostion(long ts, long te, uint loc)
|
|
|
+ void Position(float pause, float step, Vector3 end_pos, GameObject worker_marker, Toggle toggle, Structure w, int count)
|
|
|
{
|
|
|
- client.CoordinatesRequest(ts, te, 1, loc);
|
|
|
- yield return new WaitForSeconds(5);
|
|
|
- foreach (var t in TestStructures)
|
|
|
- Debug.Log(t);
|
|
|
+ if (worker_marker.activeSelf == true && starting.ElementAt(count))
|
|
|
+ {
|
|
|
+ var start_pos = worker_marker.transform.position;
|
|
|
+ var x_position = Mathf.Lerp(start_pos.x, end_pos.x, 0.1f);
|
|
|
+ var y_position = Mathf.Lerp(start_pos.z, end_pos.z, 0.1f);
|
|
|
+
|
|
|
+ worker_marker.transform.position = new Vector3(x_position, 0.5f, y_position);
|
|
|
+ toggle.transform.GetChild(1).gameObject.GetComponent<Text>().text = $"{w.acc_id} {w.ts.ToString("hh:mm:ss")}";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
static bool start = false;
|
|
|
|
|
|
|
|
@@ -152,53 +189,62 @@ public class WorkerController : MonoBehaviour
|
|
|
start = !start;
|
|
|
if (start)
|
|
|
{
|
|
|
- StartStop.transform.GetChild(0).GetComponent<Text>().text = "Остановить";
|
|
|
- var time_start = new DateTime(2020, 03, 26);
|
|
|
+ StartStopButton.transform.GetChild(0).GetComponent<Text>().text = "Остановить";
|
|
|
+ starting.Add(true);
|
|
|
+ var time_start = DateTime.Parse(inputField_date.text);
|
|
|
time_start = time_start.AddHours(int.Parse(StartHour.GetComponent<InputField>().text));
|
|
|
time_start = time_start.AddMinutes(int.Parse(StartMin.GetComponent<InputField>().text));
|
|
|
time_start = time_start.AddSeconds(int.Parse(StartSec.GetComponent<InputField>().text));
|
|
|
|
|
|
|
|
|
|
|
|
- var time_end = new DateTime(2020, 03, 26);
|
|
|
-
|
|
|
+ var time_end = DateTime.Parse(inputField_date.text);
|
|
|
time_end = time_end.AddHours(int.Parse(EndHour.GetComponent<InputField>().text));
|
|
|
time_end = time_end.AddMinutes(int.Parse(EndMin.GetComponent<InputField>().text));
|
|
|
time_end = time_end.AddSeconds(int.Parse(EndSec.GetComponent<InputField>().text));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- StartCoroutine(RequestPostion(time_start.Ticks, time_end.Ticks, 1));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- } else
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var m in markers)
|
|
|
+ {
|
|
|
+ if (m.toggle.isOn)
|
|
|
+ {
|
|
|
+ client.CoordinatesRequest(time_start.Ticks, time_end.Ticks, 1, uint.Parse(inputField_location.text), m.acc_id);
|
|
|
+ end_send[m.acc_id] = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- StartStop.transform.GetChild(0).GetComponent<Text>().text = "Отобразить";
|
|
|
+ StartStopButton.transform.GetChild(0).GetComponent<Text>().text = "Отобразить";
|
|
|
+ starting[starting.Count - 1] = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void StartingAccPositiong(Marker m)
|
|
|
+ {
|
|
|
+ var worker = Workers[m.acc_id].OrderBy(wr => wr.ts).ToList();
|
|
|
+ if (Workers.Any())
|
|
|
+ {
|
|
|
+ var offset = 0.1f;
|
|
|
+ for (int i = 0; i < worker.Count; i++)
|
|
|
+ {
|
|
|
+ var w = worker.ElementAt(i);
|
|
|
+ var start_pos = m.marker.transform.position;
|
|
|
+ if (i != 0) start_pos = new Vector3(worker.ElementAt(i - 1).coord_x, 0.5f, worker.ElementAt(i - 1).coord_y);
|
|
|
+ var end_pos = new Vector3(w.coord_x, 0.5f, w.coord_y);
|
|
|
+ for (float j = 0; j <= 1.1f; j += 0.1f)
|
|
|
+ {
|
|
|
+ StartCoroutine(MarkerPostion(i + offset + j, j, start_pos, end_pos, m.marker, m.toggle, w, starting.Count - 1));
|
|
|
+
|
|
|
+ }
|
|
|
+ offset += 0.1f;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|