示例#1
0
        private void DrawHeaderPanel(SAP_GridSource grid, SAP_GraphDrawer drawer)
        {
            int    index         = pathfinder.GraphDrawers.IndexOf(drawer);
            string foldoutTxt    = grid.GridName;
            string foldoutName   = "grid_" + index;
            string textFieldName = "txtField_" + index;

            Rect r = EditorGUILayout.BeginHorizontal();

            if (gridToEditName == grid)
            {
                GUI.SetNextControlName(textFieldName);
                grid.GridName = EditorGUI.TextField(new Rect(r.x, r.y, r.width, 16), grid.GridName);
                foldoutTxt    = "";
                if (GUI.GetNameOfFocusedControl() != textFieldName)
                {
                    GUI.FocusControl(textFieldName);
                }
            }
            else
            {
                drawer.ShowGrid = EditorGUI.Toggle(new Rect(r.xMax - 30, r.y, 30, 30), drawer.ShowGrid);
                EditorGUI.LabelField(new Rect(r.xMax - 55, r.y, 35, 35), "[" + pathfinder.GraphDrawers.IndexOf(drawer) + "]");
            }
            GUI.SetNextControlName(foldoutName);
            drawer.ShowGridInfo = EditorGUILayout.Foldout(drawer.ShowGridInfo, foldoutTxt, true);

            EditorGUILayout.EndHorizontal();
        }
示例#2
0
        private void DeleteGridCallback()
        {
            SAP_GridSource  grid   = pathfinder.GetGrid(selectedGridIndex);
            SAP_GraphDrawer drawer = pathfinder.GraphDrawers[selectedGridIndex];

            pathfinder.RemoveGrid(grid);
            pathfinder.GraphDrawers.Remove(drawer);
        }
示例#3
0
        private void MoveGridUpCallback()
        {
            pathfinder.SwapGrids(selectedGridIndex, selectedGridIndex - 1);
            SAP_GraphDrawer drawerA = pathfinder.GraphDrawers[selectedGridIndex];
            SAP_GraphDrawer drawerB = pathfinder.GraphDrawers[selectedGridIndex - 1];

            pathfinder.GraphDrawers[selectedGridIndex]     = drawerB;
            pathfinder.GraphDrawers[selectedGridIndex - 1] = drawerA;
        }
示例#4
0
        private static void DrawGizmos(SAP2DPathfinder manager, GizmoType gizmoType)
        {
            if (manager.GraphDrawers == null)
            {
                return;
            }

            for (int i = 0; i < manager.GraphDrawers.Count; i++)
            {
                SAP_GraphDrawer drawer = manager.GraphDrawers[i];
                if (drawer.ShowGrid == false || SceneView.lastActiveSceneView.camera.orthographic == false)
                {
                    continue;
                }

                SAP_GridSource grid = manager.GetGrid(i);
                drawer.Draw(grid);
            }
        }
示例#5
0
        private void DrawHandles()
        {
            serializedObject.Update();
            for (int i = 0; i < pathfinder.gridsCount; i++)
            {
                SAP_GridSource  grid   = pathfinder.GetGrid(i);
                SAP_GraphDrawer drawer = pathfinder.GraphDrawers[i];

                if (drawer.ShowGrid == false)
                {
                    continue;
                }

                Vector3 gridPos = Handles.PositionHandle(grid.Position, Quaternion.identity);
                if (gridPos != grid.Position)
                {
                    grid.Position = gridPos;
                }
            }
        }
        private void OnSceneGUI(SceneView sceneView)
        {
            if (pathfinder == null)
            {
                return;
            }
            if (pathfinder.gridsCount == 0)
            {
                return;
            }
            if (EditorApplication.isPlaying == true)
            {
                return;
            }


            grid   = pathfinder.GetGrid(gridIndex);
            drawer = pathfinder.GraphDrawers[gridIndex];

            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

            switch (toolIndex)
            {
            case 0:
                PencilToolHandler();
                break;

            case 1:
                PencilToolHandler();
                break;

            case 2:
                RectangleToolHandler();
                break;
            }
            ShortcutsHandler();
            SceneView.RepaintAll();
        }
示例#7
0
        private void DrawGridsList()
        {
            if (pathfinder.gridsCount == 0)
            {
                EditorGUILayout.HelpBox("SAP2D Manager has't none grids." +
                                        "\nYou should create new grid by click right mouse button on inspector window and select 'Add New Grid'", MessageType.Info);
                return;
            }

            serializedObject.Update();

            for (int i = 0; i < pathfinder.gridsCount; i++)
            {
                SAP_GridSource  grid   = pathfinder.GetGrid(i);
                SAP_GraphDrawer drawer = pathfinder.GraphDrawers[i];

                SerializedProperty obstacleLayer = grids.GetArrayElementAtIndex(i).FindPropertyRelative("ObstaclesLayer");

                EditorGUILayout.BeginVertical("box");
                EditorGUI.indentLevel = 1;

                DrawHeaderPanel(grid, drawer);

                if (drawer.ShowGridInfo)
                {
                    #region GridParametersDrawing

                    EditorGUILayout.BeginVertical("box");
                    drawer.ShowGridParameters = EditorGUILayout.Foldout(drawer.ShowGridParameters, "Grid Parameters", true);
                    if (drawer.ShowGridParameters)
                    {
                        EditorGUI.indentLevel = 0;

                        EditorGUI.BeginChangeCheck();
                        int gridWidth = EditorGUILayout.IntField("Grid Width", grid.Width);
                        if (EditorGUI.EndChangeCheck())
                        {
                            grid.CreateGrid(gridWidth, grid.Height);
                            SceneView.RepaintAll();
                            if (grid.UserGridData != null)
                            {
                                grid.UserGridData.UnwalkableTiles.Clear();
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        int gridHeight = EditorGUILayout.IntField("Grid Height", grid.Height);
                        if (EditorGUI.EndChangeCheck())
                        {
                            grid.CreateGrid(grid.Width, gridHeight);
                            SceneView.RepaintAll();
                            if (grid.UserGridData != null)
                            {
                                grid.UserGridData.UnwalkableTiles.Clear();
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        float tileDiameter = EditorGUILayout.FloatField("Tile Diameter", grid.TileDiameter);
                        if (EditorGUI.EndChangeCheck())
                        {
                            grid.TileDiameter = tileDiameter;
                            SceneView.RepaintAll();
                        }

                        EditorGUI.BeginChangeCheck();
                        GridPivot pivot = (GridPivot)EditorGUILayout.EnumPopup("Grid Pivot", grid.GridPivot);
                        if (EditorGUI.EndChangeCheck())
                        {
                            grid.GridPivot = pivot;
                            SceneView.RepaintAll();
                        }

                        EditorGUI.BeginChangeCheck();
                        Vector3 gridPos = EditorGUILayout.Vector3Field("Grid Position", grid.Position);
                        if (EditorGUI.EndChangeCheck())
                        {
                            grid.Position = gridPos;
                            SceneView.RepaintAll();
                        }
                        EditorGUI.indentLevel = 1;
                    }
                    EditorGUILayout.EndVertical();

                    #endregion

                    #region PathfindingSettingsDrawing

                    EditorGUILayout.BeginVertical("box");
                    drawer.ShowPathfindingSettings = EditorGUILayout.Foldout(drawer.ShowPathfindingSettings, "Pathfinding Settings", true);
                    if (drawer.ShowPathfindingSettings)
                    {
                        EditorGUI.indentLevel = 0;
                        bool usePhysics2D = EditorGUILayout.Toggle("Use Physics 2D", grid.UsePhysics2D);
                        if (usePhysics2D != grid.UsePhysics2D)
                        {
                            grid.UsePhysics2D = usePhysics2D;
                            pathfinder.CalculateColliders();
                            SceneView.RepaintAll();
                        }
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(obstacleLayer);
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedObject.ApplyModifiedProperties();
                        }
                        EditorGUI.indentLevel = 1;
                    }
                    EditorGUILayout.EndVertical();

                    #endregion
                }
                EditorGUILayout.EndVertical();
            }
            if (GUILayout.Button("Calculate Colliders (All Grids)", GUILayout.Height(25)))
            {
                for (int i = 0; i < pathfinder.gridsCount; i++)
                {
                    SAP_GridSource grid = pathfinder.GetGrid(i);
                }
                pathfinder.CalculateColliders();
                SceneView.RepaintAll();
            }
        }