فهرست منبع

fix create zones

Виктор Шейко 4 سال پیش
والد
کامیت
2f824608e0

+ 47 - 86
Assets/Scenes/Player.unity

@@ -7295,18 +7295,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 307553993}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: CursorOff
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &307553993
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -11071,6 +11060,7 @@ GameObject:
   - component: {fileID: 472823652}
   - component: {fileID: 472823651}
   - component: {fileID: 472823650}
+  - component: {fileID: 472823655}
   m_Layer: 5
   m_Name: Tools
   m_TagString: Untagged
@@ -11128,6 +11118,8 @@ MonoBehaviour:
   ButtonBeacon: {fileID: 1259410722}
   ButtonZone: {fileID: 1581405531}
   ButtonBuild: {fileID: 2114201584}
+  ButtonRoom: {fileID: 1958858212}
+  ButtonWall: {fileID: 1207621654}
   GroundSettings: {fileID: 583944819}
   Grid: {fileID: 1140473727}
   BuildTools: {fileID: 1909596479}
@@ -11208,6 +11200,20 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 472823648}
   m_CullTransparentMesh: 0
+--- !u!114 &472823655
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 472823648}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: c0a1c39e1f26e524993f4e3b44ee2639, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  redo: {fileID: 942212489}
+  undo: {fileID: 307553992}
 --- !u!1 &476522313
 GameObject:
   m_ObjectHideFlags: 0
@@ -22050,18 +22056,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 942212490}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: CursorOff
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &942212490
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -23178,18 +23173,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 988350254}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: CursorOff
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &988350254
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -28408,18 +28392,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 1207621655}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: WallEdit
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &1207621655
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -43071,8 +43044,6 @@ MonoBehaviour:
   Dialog: {fileID: 3538187245544653792}
   ZonesScroll: {fileID: 1296382291}
   Player: {fileID: 995816062}
-  redo: {fileID: 942212489}
-  undo: {fileID: 307553992}
   mode: 4
 --- !u!1 &1765107640
 GameObject:
@@ -46729,18 +46700,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 1878095459}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: CursorOff
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &1878095459
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -49006,18 +48966,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 1958858213}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: RoomEdit
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &1958858213
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -52310,18 +52259,7 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 2089870262}
   m_OnClick:
     m_PersistentCalls:
-      m_Calls:
-      - m_Target: {fileID: 472823650}
-        m_MethodName: GridOnOff
-        m_Mode: 1
-        m_Arguments:
-          m_ObjectArgument: {fileID: 0}
-          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
-          m_IntArgument: 0
-          m_FloatArgument: 0
-          m_StringArgument: 
-          m_BoolArgument: 0
-        m_CallState: 2
+      m_Calls: []
 --- !u!114 &2089870262
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -62705,6 +62643,7 @@ GameObject:
   - component: {fileID: 8002323671399922968}
   - component: {fileID: 1761650666}
   - component: {fileID: 8002323671399922972}
+  - component: {fileID: 8002323671399922973}
   m_Layer: 0
   m_Name: WallCursor
   m_TagString: Untagged
@@ -62773,6 +62712,28 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   TrackMarker: 0
   UserId: 0
+--- !u!195 &8002323671399922973
+NavMeshAgent:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 8002323671399922969}
+  m_Enabled: 1
+  m_AgentTypeID: 0
+  m_Radius: 0.5
+  m_Speed: 3.5
+  m_Acceleration: 8
+  avoidancePriority: 50
+  m_AngularSpeed: 120
+  m_StoppingDistance: 0
+  m_AutoTraverseOffMeshLink: 1
+  m_AutoBraking: 1
+  m_AutoRepath: 1
+  m_Height: 1
+  m_BaseOffset: 0.5
+  m_WalkableMask: 4294967295
+  m_ObstacleAvoidanceType: 4
 --- !u!4 &8002323671399922981
 Transform:
   m_ObjectHideFlags: 0

+ 19 - 29
Assets/Scripts/Components/WallCreate.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
@@ -19,9 +18,7 @@ public class WallCreate : MonoBehaviour
     public GameObject ZonesScroll;
     public GameObject Player;
 
-    public Button redo;
-    public Button undo; // отмена
-    public List<History> histories = new List<History>();
+    //public Vector3 targetPos;
 
     public enum Mode { Wall, Room, Zone, Pole, Cursor };
     public Mode mode = Mode.Cursor;
@@ -38,11 +35,14 @@ public class WallCreate : MonoBehaviour
     private Vector3 curPosition;
 
     private Vector3 start_pos;
-    Vector3 Point;
+    //Vector3 Point;
 
     GameObject canvas;
     Text text;
 
+    MeshCollider meshCollider;
+    Ray ray;
+
     CompanyController company;
 
     private void Awake()
@@ -53,25 +53,28 @@ public class WallCreate : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
-       // gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
+        // gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
         //cursor_end = transform.GetChild(6).gameObject; 
-        Point = Camera.main.WorldToScreenPoint(gameObject.transform.position);
+        //Point = Camera.main.WorldToScreenPoint(gameObject.transform.position);
         canvas = transform.GetChild(0).gameObject;
         text = transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>();
         company = CompanyController.instance;
-
-        undo.onClick.AddListener(Undo);
     }
    
     // Update is called once per frame
     void Update()
     {
-        // if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
-        if (!Input.GetMouseButtonDown(0))
-        {           
-            transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Point.z));
-            if (transform.position.y != 0.5f) transform.position = new Vector3(transform.position.x, 0.5f, transform.position.z);
+        meshCollider = company.locations[company.locations_index[company.active_location]].plane.GetComponent<MeshCollider>();
+        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
+        RaycastHit hitData;
+
+        if (meshCollider.Raycast(ray, out hitData, 1000))
+        {
+            transform.position = hitData.point;
         }
+
+        //transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Point.z));
+        //if (transform.position.y != 0.5f) transform.position = new Vector3(transform.position.x, 0.5f, transform.position.z);     
     }
 
     void OnMouseDown()
@@ -89,7 +92,7 @@ public class WallCreate : MonoBehaviour
             {
                 case Mode.Wall:
                     wall = AddWall(company, Vector3.zero);
-                    EventHistory(0, wall, null);
+                    HistoryController.instance.EventHistory(0, wall);
                     break;
                 case Mode.Room:
                     wall = AddRoom();
@@ -98,7 +101,7 @@ public class WallCreate : MonoBehaviour
                     wall = AddZone(Dialog, company, ZonesScroll);
 
                     var location_id = company.locations_index[company.active_location];
-                    EventHistory(0, wall, Zones[location_id].Last().buttons);
+                    HistoryController.instance.EventHistory(0, wall, Zones[location_id].Last().buttons);
                     break;
             }           
         }
@@ -332,17 +335,4 @@ public class WallCreate : MonoBehaviour
         var zone = Zones[location_id][num];
         return zone.id;
     }
-
-    void Undo()
-    {
-        var last = histories.Last();
-        last.obj.SetActive(false);
-        if(last.ButtonPanel != null) last.ButtonPanel.SetActive(false);
-        last.status = false;
-    }
-
-    public void EventHistory(uint id, GameObject gameObject, GameObject panel)
-    {
-        histories.Add(new History { id = id, obj = gameObject, ButtonPanel = panel, status = true });
-    }
 }

+ 1 - 1
Assets/Scripts/Controllers/EditorController.cs

@@ -102,7 +102,7 @@ public class EditorController : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        if (company.active_location >= 0)
+        if (company.active_location >= 0 && company.locations != null)
         {
             var l = company.locations[company.locations_index[company.active_location]];
             l.plane.GetComponent<TouchScript>().Resize = ToggleScalePanel.isOn;

+ 29 - 10
Assets/Scripts/Controllers/HistoryController.cs

@@ -9,17 +9,22 @@ using UnityEngine.UI;
 /// </summary>
 public class HistoryController : MonoBehaviour
 {
+    public static HistoryController instance;
+
     public Button redo;
     public Button undo; // отмена
     public List<History> histories = new List<History>();
-    
-   
 
+    private void Awake()
+    {
+        instance = this;
+    }
 
     // Start is called before the first frame update
     void Start()
     {
         undo.onClick.AddListener(Undo);
+        redo.onClick.AddListener(Redo);
     }
 
     // Update is called once per frame
@@ -27,16 +32,30 @@ public class HistoryController : MonoBehaviour
     {
 
     }
-
  
-    void Undo() {
-        var last = histories.Last();
-        last.obj.SetActive(false);
-        last.ButtonPanel.SetActive(false);
-        last.status = false;
+    public void Undo() {
+        var last = histories.Where(l => l.status).LastOrDefault();
+        if (last != null)
+        {
+            last.obj.SetActive(false);
+            if (last.ButtonPanel != null) last.ButtonPanel.SetActive(false);
+            last.status = false;
+        }
     }
-  
-    public void EventHistory(uint id, GameObject gameObject, GameObject panel)
+
+    public void Redo()
+    {
+        var last = histories.Where(l => !l.status).FirstOrDefault();
+        if (last != null)
+        {
+            last.obj.SetActive(true);
+            if(last.ButtonPanel != null) last.ButtonPanel.SetActive(true);
+            last.status = true;
+        }
+        histories.Remove(last);
+    }
+
+    public void EventHistory(uint id, GameObject gameObject, GameObject panel = null)
     {
         histories.Add(new History { id = id, obj = gameObject, ButtonPanel = panel, status = true });
     }

+ 9 - 13
Assets/Scripts/Controllers/ToolsController.cs

@@ -20,6 +20,8 @@ public class ToolsController : MonoBehaviour
     public Button ButtonBeacon;
     public Button ButtonZone;
     public Button ButtonBuild;
+    public Button ButtonRoom;
+    public Button ButtonWall;
     public GameObject GroundSettings;
     public GameObject Grid;
     public GameObject BuildTools;
@@ -40,7 +42,13 @@ public class ToolsController : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
-        
+        Mouse.onClick.AddListener(CursorOff);
+        Hammer.onClick.AddListener(CursorOff);
+        Undo.onClick.AddListener(CursorOff);
+        Redo.onClick.AddListener(CursorOff);
+        ButtonGrid.onClick.AddListener(GridOnOff);
+        ButtonRoom.onClick.AddListener(RoomEdit);
+        ButtonWall.onClick.AddListener(WallEdit);
     }
 
     // Update is called once per frame
@@ -180,18 +188,6 @@ public class ToolsController : MonoBehaviour
         old_btn_tools = Hammer;
     }
 
-    public void undo()
-    {
-        SelectButton(Undo, old_btn_tools);
-        old_btn_tools = Undo;
-    }
-
-    public void redo()
-    {
-        SelectButton(Redo, old_btn_tools);
-        old_btn_tools = Redo;
-    }
-
     public void OpenFileBrowser()
     {
        StartCoroutine(ShowLoadDialogCoroutine($"Выбор карты"));