public override void OnSceneGUI(Vector3[] nodes, int nodesCount)
        {
            var currentEvent = Event.current;

            if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                var ray = NavigationEditorTools.GUIEventToRay(currentEvent);
                if (NavigationEditorTools.RayCastCells(ray, out int cellIndex, nodes, nodesCount))
                {
                    controller.SelectedCellIndex = cellIndex;
                }

                GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                Event.current.Use();
            }
        }
Exemple #2
0
        public override void OnSceneGUI(Vector3[] nodes, int nodesCount)
        {
            Ray  ray    = default;
            bool hasRay = false;

            var currentEvent = Event.current;

            if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                ray    = NavigationEditorTools.GUIEventToRay(currentEvent);
                hasRay = true;

                GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                Event.current.Use();
            }

            Vector3 selectedCellCenter = NavigationEditorTools.CalculateCellCenter(controller.SelectedCellIndex, nodes);

            int startNode = controller.SelectedCellIndex * NavigationInfo.NodesCount;

            for (int i = 0; i < NavigationInfo.NodesCount; i++)
            {
                Vector3 a = nodes[startNode + i];
                Vector3 b = nodes[startNode + ((i + 1) % NavigationInfo.NodesCount)];
                if (!EdgeContactAnyCellWithSelectedIgnored(a, b, nodes, nodesCount))
                {
                    Vector3 c    = nodes[startNode + ((i + 2) % NavigationInfo.NodesCount)];
                    Vector3 move = ((a + b) / 2) - c;
                    c += 2 * move;

                    var handlesColorCopy = Handles.color;
                    Handles.color = Color.yellow;
                    Handles.DrawLine(a, c);
                    Handles.DrawLine(b, c);

                    if (hasRay && NavigationEditorTools.RayCheckTriangle(ray, a, b, c))
                    {
                        controller.AddAndSelectCell(a, b, c);
                    }

                    Handles.color = handlesColorCopy;
                }
            }
        }
        private void Refresh()
        {
            var areas = new HashSet <IndexEdge> [NavigationSettings.AreasCount];

            for (int i = 0; i < NavigationSettings.AreasCount; i++)
            {
                areas[i] = new HashSet <IndexEdge>();
            }
            var vertices = new List <Vector3>();
            var centers  = new List <int>();
            var holders  = NavigationEditorTools.FindAllComponentsInActiveScene <FacesHolder>(includeInactive);

            foreach (var holder in holders)
            {
                int areaIndex = holder.AreaIndex;
                if (holder.LayerIndex == layerIndex && ((1 << areaIndex) & areaMask) != 0)
                {
                    var triangles       = holder.GetAllWorldNodes();
                    int trianglesLength = triangles.Length;
                    for (int i = 0; i < trianglesLength;)
                    {
                        int a      = FindVertexOrAdd(triangles[i++], vertices);
                        int b      = FindVertexOrAdd(triangles[i++], vertices);
                        int c      = FindVertexOrAdd(triangles[i++], vertices);
                        int center = FindVertexOrAdd((vertices[a] + vertices[b] + vertices[c]) / 3, vertices);

                        areas[areaIndex].Add(new IndexEdge(a, b));
                        areas[areaIndex].Add(new IndexEdge(b, c));
                        areas[areaIndex].Add(new IndexEdge(c, a));
                        centers.Add(center);
                    }
                }
            }

            this.vertices = vertices.ToArray();
            this.centers  = centers.ToArray();
            this.areas    = new IndexEdge[NavigationSettings.AreasCount][];
            for (int i = 0; i < NavigationSettings.AreasCount; i++)
            {
                this.areas[i] = areas[i].ToArray();
            }
            RefreshAreaColors();
        }