Exemple #1
0
        public override void OnInspectorGUI()
        {
            ShowNodesArray(serializedObject.FindProperty("_nodes"), "Nodes list");

            void ShowNodesArray(SerializedProperty list, string label)
            {
                if (EditorGUILayout.DropdownButton(new GUIContent(label), FocusType.Passive))
                {
                    _nodesListShowed = !_nodesListShowed;
                }

                if (_nodesListShowed)
                {
                    for (int i = 0; i < list.arraySize; i++)
                    {
                        EditorGUI.indentLevel += 1;

                        var element = list.GetArrayElementAtIndex(i);

                        var node = element.objectReferenceValue as NavMeshGridNode;

                        EditorGUILayout.PropertyField(element,
                                                      new GUIContent($"Node \t{node.Index.Row}\t{node.Index.Column}"));
                        EditorGUI.indentLevel -= 1;
                    }
                }

                if (_selectedNode)
                {
                    for (int i = 0; i < list.arraySize; i++)
                    {
                        var element = list.GetArrayElementAtIndex(i);
                        var node    = element.objectReferenceValue as NavMeshGridNode;

                        if (node.Index == _selectedNode.Index)
                        {
                            EditorGUILayout.Space(20);
                            GUILayout.Label("Selected node:");

                            EditorGUILayout.PropertyField(element,
                                                          new GUIContent($"Node \t{node.Index.Row}\t{node.Index.Column}"));
                            EditorGUI.indentLevel -= 1;
                            EditorGUILayout.Space();

                            var resetCustomOffsetButtonClicked = GUILayout.Button("Reset custom offset");

                            if (resetCustomOffsetButtonClicked)
                            {
                                _selectedNode.SetCustomOffset(Vector2.zero, 1);
                                Grid.RefreshNodesPositions();
                            }

                            Repaint();
                            break;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void DrawNodeCustomOffsetHandle(NavMeshGridNode node)
        {
            if (!_showNodesCustomOffsetsHandles)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            Handles.color = Color.white;

            var buttonOffset = Vector2.down * 0.4f;
            var customOffset = Handles.FreeMoveHandle(node.Position + buttonOffset, Quaternion.identity, 0.1f, Vector3.zero, Handles.DotHandleCap);

            if (EditorGUI.EndChangeCheck())
            {
                node.SetCustomOffset((Vector2)customOffset - node.PositionWithoutOffset - buttonOffset, (Grid.NodesHorizontalOffset + Grid.NodesVerticalOffset).magnitude / 4f);
                Debug.Log(node.PositionWithoutOffset);
            }
        }