Browse Source

Плавность

Виктор Шейко 5 years ago
parent
commit
45aa6b4baf

+ 7 - 1
.gitignore

@@ -337,4 +337,10 @@ ASALocalRun/
 .localhistory/
 
 # BeatPulse healthcheck temp database
-healthchecksdb
+healthchecksdb
+/Assets/Materials/RedLineX.mat
+/Assets/Resources
+/Assets/Scenes/SampleScene.unity
+/Library
+/ProjectSettings
+/Temp

File diff suppressed because it is too large
+ 663 - 0
Assembly-CSharp.csproj


+ 227 - 0
Assets/Scripts/Controllers/CameraController.cs

@@ -0,0 +1,227 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+
+public class CameraController : MonoBehaviour
+{
+    public enum RotationAxes { MouseXAndY, MouseX, MouseY, RelativeObject, KeyBoard }
+    public RotationAxes axes = RotationAxes.MouseXAndY;
+    public float sensitivityX = 2F;
+    public float sensitivityY = 2F;
+    public float minimumX = -360F;
+    public float maximumX = 360F;
+    public float minimumY = -90F;
+    public float maximumY = 90F;
+    float rotationY = -60F;
+
+    // For camera movement
+    //float CameraPanningSpeed = 10.0f;
+
+    // Target Rotate
+    public Transform target;
+    public Vector3 offset;
+    public float sensitivity = 3; // чувствительность мышки
+    public float limit = 90; // ограничение вращения по Y
+    public float zoom = 0.5f; // чувствительность при увеличении, колесиком мышки
+    public float zoomMax = 50; // макс. увеличение
+    public float zoomMin = 0.5f; // мин. увеличение
+    private float X, Y;
+
+
+    void Start()
+    {
+        limit = Mathf.Abs(limit);
+        if (limit > 90) limit = 90;
+        offset = new Vector3(offset.x, offset.y, offset.z/*-Mathf.Abs(zoomMax) / 2*/);
+        transform.position = target.position + offset;
+    }
+
+    void Update()
+    {        
+        if(axes == RotationAxes.KeyBoard)KeyboardsCommands();
+        else MouseInput();
+    }
+
+    void MouseInput()
+    {
+        if (EventSystem.current.IsPointerOverGameObject())
+        {
+            return;
+        }
+
+        if (Input.GetMouseButton(0))
+        {
+        }
+        else if (Input.GetMouseButton(1))
+        {
+            MouseRightClick();
+        }
+        else if (Input.GetMouseButton(2))
+        {
+            MouseMiddleButtonClicked();
+        }
+        else if (Input.GetMouseButtonUp(1))
+        {
+            ShowAndUnlockCursor();
+        }
+        else if (Input.GetMouseButtonUp(2))
+        {
+            ShowAndUnlockCursor();
+        }
+        else
+        {
+            MouseWheeling();
+        }
+    }
+
+    void ShowAndUnlockCursor()
+    {
+        Cursor.lockState = CursorLockMode.None;
+        Cursor.visible = true;
+    }
+
+    void HideAndLockCursor()
+    {
+        Cursor.lockState = CursorLockMode.Locked;
+        Cursor.visible = false;
+    }
+
+    void MouseMiddleButtonClicked()
+    {
+        HideAndLockCursor();
+        Vector3 NewPosition = new Vector3(Input.GetAxis("Mouse X"), 0, Input.GetAxis("Mouse Y"));
+        Vector3 pos = transform.position;
+        if (NewPosition.x > 0.0f)
+        {
+            pos += transform.right;
+        }
+        else if (NewPosition.x < 0.0f)
+        {
+            pos -= transform.right;
+        }
+        if (NewPosition.z > 0.0f)
+        {
+            pos += transform.forward;
+        }
+        if (NewPosition.z < 0.0f)
+        {
+            pos -= transform.forward;
+        }
+        pos.y = transform.position.y;
+        transform.position = pos;
+    }
+
+    void MouseRightClick()
+    {
+        HideAndLockCursor();
+        switch (axes)
+        {
+            case RotationAxes.MouseXAndY:
+
+
+                float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
+
+                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
+                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
+
+                transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
+                break;
+
+            case RotationAxes.MouseX:
+
+                transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
+                break;
+            case RotationAxes.RelativeObject:
+
+                /*if (Input.GetAxis("Mouse ScrollWheel") > 0) 
+                    offset.z += zoom;
+                else if (Input.GetAxis("Mouse ScrollWheel") < 0) 
+                    offset.z -= zoom;*/
+                //offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
+
+                X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
+                Y += Input.GetAxis("Mouse Y") * sensitivity;
+                Y = Mathf.Clamp(Y, -limit, limit);
+                transform.localEulerAngles = new Vector3(-Y, X, 0);
+                transform.position = transform.localRotation * offset + target.position;
+                break;
+                
+            default:
+                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
+                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
+
+                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
+                break;
+        }
+    }
+
+    void MouseWheeling()
+    {
+        /*Vector3 pos = transform.position;
+        if (Input.GetAxis("Mouse ScrollWheel") < 0)
+        {
+            pos = pos - transform.forward;
+            transform.position = pos;
+        }
+        if (Input.GetAxis("Mouse ScrollWheel") > 0)
+        {
+            pos = pos + transform.forward;
+            transform.position = pos;
+        }*/
+
+        if (Input.GetAxis("Mouse ScrollWheel") > 0)
+        {
+            offset.z += zoom;
+        }
+        else if (Input.GetAxis("Mouse ScrollWheel") < 0)
+            offset.z -= zoom; 
+        offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
+
+        transform.position = transform.localRotation * offset + target.position;
+    }
+
+    private Vector3 GetBaseInput()
+    { //returns the basic values, if it's 0 than it's not active.
+        Vector3 p_Velocity = new Vector3();
+        if (Input.GetKey(KeyCode.W))
+        {
+            p_Velocity += new Vector3(0, 0, 1);
+        }
+        if (Input.GetKey(KeyCode.S))
+        {
+            p_Velocity += new Vector3(0, 0, -1);
+        }
+        if (Input.GetKey(KeyCode.A))
+        {
+            p_Velocity += new Vector3(-1, 0, 0);
+        }
+        if (Input.GetKey(KeyCode.D))
+        {
+            p_Velocity += new Vector3(1, 0, 0);
+        }
+        return p_Velocity;
+    }
+
+    private void KeyboardsCommands()
+    {
+        //Keyboard commands
+        //float f = 0.0f;
+        Vector3 p = GetBaseInput();
+      
+
+        p = p * Time.deltaTime;
+        Vector3 newPosition = transform.position;
+        if (Input.GetKey(KeyCode.Space))
+        { //If player wants to move on X and Z axis only
+            transform.Translate(p);
+            newPosition.x = transform.position.x;
+            newPosition.z = transform.position.z;
+            transform.position = newPosition;
+        }
+        else
+        {
+            transform.Translate(p);
+        }
+    }
+}

+ 68 - 0
Assets/Scripts/Controllers/LocationController.cs

@@ -0,0 +1,68 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+public class LocationController : MonoBehaviour
+{
+    public List<GameObject> rooms;   
+    // Start is called before the first frame update
+    void Start()
+    {
+      
+
+        var rooms_0 = rooms.ElementAt(0);
+        Cube(rooms_0, new Vector3(6, 8, 1)); //x=6 y=8 h1
+        var rooms_1 = rooms.ElementAt(1);
+        Cube(rooms_1, new Vector3(2, 10, 1), new Vector2(6, 0));
+        var rooms_2 = rooms.ElementAt(2);
+        Cube(rooms_2, new Vector3(5, 4, 1), new Vector2(8, 5));
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+
+    public static void Cube(GameObject cube, Vector3 cube_size, Vector2 position = new Vector2())
+    {
+        //GameObject cube = GameObject.Find("Cube");
+        cube_size = new Vector3(cube_size.x, cube_size.y, cube_size.z);
+
+        Vector3 pos_cube = new Vector3(cube_size.x / 2f, cube_size.z / 2f, cube_size.y / 2f);
+        cube.transform.position = new Vector3(pos_cube.x + position.x, pos_cube.y, pos_cube.z + position.y);
+
+        // above
+        GameObject plane_a = cube.transform.GetChild(0).gameObject;
+        //plane_above.transform.localScale = cube_size;
+        plane_a.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
+        plane_a.transform.localPosition = new Vector3(0, pos_cube.y, 0);//y x=0
+
+        // front
+        GameObject plane_b = cube.transform.GetChild(1).gameObject;
+        plane_b.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.z);
+        plane_b.transform.localPosition = new Vector3(0, 0, -pos_cube.z);
+
+        // side
+        GameObject plane_c = cube.transform.GetChild(2).gameObject;
+        plane_c.transform.localScale = new Vector3(cube_size.y, 0.01f, cube_size.z);
+        plane_c.transform.localPosition = new Vector3(-pos_cube.x, 0, 0);
+
+        // низ 
+        GameObject plane_d = cube.transform.GetChild(3).gameObject;
+        plane_d.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
+        plane_d.transform.localPosition = new Vector3(0, -pos_cube.y, 0);
+
+        // зад 
+        GameObject plane_e = cube.transform.GetChild(4).gameObject;
+        plane_e.transform.localScale = new Vector3(cube_size.y, 0.01f, cube_size.z);
+        plane_e.transform.localPosition = new Vector3(pos_cube.x, 0, 0);       
+
+        // front 2
+        GameObject plane_f = cube.transform.GetChild(5).gameObject;
+        plane_f.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.z);
+        plane_f.transform.localPosition = new Vector3(0, 0, pos_cube.z);
+    }
+}

+ 21 - 0
Assets/Scripts/Controllers/TimePickerController.cs

@@ -0,0 +1,21 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TimePickerController : MonoBehaviour
+{
+    public GameObject DayUp;
+    public GameObject MontUp;
+    public GameObject YearUp;
+    // Start is called before the first frame update
+    void Start()
+    {
+        
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+}

+ 194 - 0
Assets/Scripts/Controllers/WorkerController.cs

@@ -0,0 +1,194 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class WorkerController : MonoBehaviour
+{
+    List<Structure> structures = new List<Structure>();
+    public GameObject WorkersList;
+
+    // Start is called before the first frame update
+    void Start()
+    {
+        System.Random rnd = new System.Random();
+        for (int i = 0; i < 240; i++)
+        {          
+                var ts = new DateTime(2020, 03, 26, 10,Convert.ToInt32(i/60), i%60);
+            
+            //else ts = new DateTime(2020, 03, 26, 10, 17, i - 60);
+            structures.Add(new Structure
+            {
+                id = structures.Count + 1,
+                coord_x = rnd.Next(0, 13),
+                coord_y = rnd.Next(0, 10),
+                ts = ts,
+                acc_id = 356,
+                location_id = 22,
+                zone_id = 2
+            });
+            structures.Add(new Structure
+            {
+                id = structures.Count + 1,
+                coord_x = rnd.Next(0, 13),
+                coord_y = rnd.Next(0, 10),
+                ts = ts,
+                acc_id = 341,
+                location_id = 22,
+                zone_id = 2
+            });
+        }            
+
+        foreach(var s in structures.Select(s => s.acc_id).Distinct())
+        WorkerMarker(s);
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+       foreach (var m in markers)
+        m.marker.SetActive(m.toggle.isOn);
+
+    }
+
+    List<Marker> markers = new List<Marker>();
+    class Marker
+    {
+        public Toggle toggle { get; set; }
+        public GameObject marker { get; set; }
+        public int acc_id { get; set; }
+    }
+
+    /// <summary>
+    /// Создание маркера для сотрудника
+    /// </summary>
+    /// <param name="acc_id"></param>
+    void WorkerMarker(int acc_id)
+    {
+        var worker_toggle = Instantiate(Resources.Load("GameObjects/Toggle", typeof(Toggle))) as Toggle;
+        worker_toggle.name = acc_id.ToString();
+        worker_toggle.transform.GetChild(1).gameObject.GetComponent<Text>().text = acc_id.ToString();
+        worker_toggle.transform.SetParent(WorkersList.transform);
+
+var worker_marker = Instantiate(Resources.Load("GameObjects/Capsule", typeof(GameObject))) as GameObject;
+        worker_marker.name = "marker_" + acc_id.ToString();
+
+        worker_marker.GetComponent<Renderer>().material.color = UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
+
+        markers.Add(new Marker { acc_id = acc_id, marker = worker_marker, toggle = worker_toggle });
+    }
+
+   /// <summary>
+   /// Смена положения маркера 
+   /// </summary>
+   /// <param name="index"></param>
+   /// <param name="worker"></param>
+   /// <param name="worker_marker"></param>
+   /// <returns></returns>
+    static IEnumerator MarkerPostion(float pause, Vector3 pos, GameObject worker_marker)
+    {
+        yield return new WaitForSeconds(pause);
+        Debug.Log(pause);
+        worker_marker.transform.position = pos;         
+    }
+
+    /// <summary>
+    /// Запуск отрисовки
+    /// Остановить нельзя
+    /// </summary>
+    public void ButtonStart()
+    {
+        foreach (var m in markers)
+        {
+            if (m.toggle.isOn)
+            {
+                var worker = structures.Where(w => w.acc_id == m.acc_id).ToList();
+                for (int i = 0; i < worker.Count; i++)
+                {
+                    var w = worker.ElementAt(i);
+
+                    var z0 = m.marker.transform.position;
+                    var z1 = new Vector3(w.coord_x, 0.5f, w.coord_y);
+                    var x = z1.x - z0.x;
+                    var y = z1.y - z0.y;
+                    var z = Mathf.Sqrt(x * x + y * y);
+                    for (float zj = Mathf.Sqrt(x * x + y * y); z > 0; z--)
+                    {
+                        Debug.Log(z);
+                        var pos = new Vector3(w.coord_x + z, 0.5f, w.coord_y + z);
+                        StartCoroutine(MarkerPostion(i - z, pos, m.marker));
+                    }
+                }
+            }
+        }
+    }
+
+    /// <summary>
+    /// https://habr.com/ru/post/347904/
+    /// </summary>
+    /// <param name="vectorAngle"></param>
+    /// <param name="empty"></param>
+    void ChekingQuarterUp(Transform vectorAngle, ref Transform empty)
+    {
+        float zangle = 0;
+        float xangle = 0;
+        float zcoord = 0.0f;
+        float xcoord = 0.0f;
+
+        int normangle = Mathf.RoundToInt(vectorAngle.eulerAngles.y);
+
+        if (normangle >= 0 && normangle <= 90) // 1-ая четверть
+        {
+            zangle = 90 - normangle;
+            xangle = 0 - normangle;
+
+            xangle = (xangle < 0) ? xangle * -1 : xangle;
+            zangle = (zangle < 0) ? zangle * -1 : zangle;
+
+        }
+
+        if (normangle > 270 && normangle <= 360) // 2-ая четверть
+        {
+            xangle = 360 - normangle;
+            zangle = 270 - normangle;
+
+
+            xangle = (xangle > 0) ? xangle * -1 : xangle;
+            zangle = (zangle < 0) ? zangle * -1 : zangle;
+
+
+        }
+
+        if (normangle > 180 && normangle <= 270) // 3-ая четверть
+        {
+            xangle = 180 - normangle;
+            zangle = 270 - normangle;
+
+            xangle = (xangle > 0) ? xangle * -1 : xangle;
+            zangle = (zangle > 0) ? zangle * -1 : zangle;
+        }
+
+        if (normangle > 90 && normangle <= 180) // 4-ая четверть
+        {
+            zangle = 90 - normangle;
+            xangle = 180 - normangle;
+
+            zangle = (zangle > 0) ? zangle * -1 : zangle;
+            xangle = (xangle < 0) ? xangle * -1 : xangle;
+
+        }
+
+        zcoord = path * Mathf.Sin(zangle * Mathf.PI / 180);
+        xcoord = path * Mathf.Sin(xangle * Mathf.PI / 180);
+
+        float newpathx = empty.position.x + xcoord;
+        float newpathz = empty.position.z + zcoord;
+
+
+        empty.position = new Vector3(newpathx, empty.transform.position.y, newpathz);
+
+    }
+}
+

+ 15 - 0
Assets/Scripts/Models/Structure.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Structure
+{
+    public int id { get; set; }
+    public int acc_id { get; set; }
+    public int zone_id { get; set; }
+    public int location_id { get; set; }
+    public int coord_x { get; set; }
+    public int coord_y { get; set; }
+    public DateTime ts { get; set; }
+}

+ 23 - 0
Positioning.sln

@@ -0,0 +1,23 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(MonoDevelopProperties) = preSolution
+		StartupItem = Assembly-CSharp.csproj
+	EndGlobalSection
+EndGlobal