Example #1
0
        /// <summary> Remove link data with target node. </summary>
        public void RemoveLinkData(int targetNodeIdx, MapNavBase map)
        {
            if (this.idx < 0)
            {
                Debug.LogError("This node is not a valid node. Link data should not be created with it.");
                return;
            }

            if (targetNodeIdx < 0 || targetNodeIdx >= map.grid.Length)
            {
                Debug.LogError("Target Node's index is invalid: " + targetNodeIdx);
                return;
            }

            if (map.grid[targetNodeIdx].idx < 0)
            {
                Debug.LogError("Target node is not a valid node. Link data should not be created with it.");
                return;
            }

            MapNavNodeLink data = GetLinkData(targetNodeIdx);

            if (data != null)
            {
                linkData.Remove(data);
            }

            data = map.grid[targetNodeIdx].GetLinkData(this.idx);
            if (data != null)
            {
                map.grid[targetNodeIdx].linkData.Remove(data);
            }
        }
        // ------------------------------------------------------------------------------------------------------------

        protected virtual void OnSceneGUI()
        {
            mapnav = target as MapNavBase;
            if (mapnav == null)
            {
                return;
            }

            if (mapnav._dev_show_nodes && debug_ShowLabels)
            {
                Handles.color = Color.cyan;
                float tz = mapnav.nodeSize * 3f;

                int idx = -1;
                for (int y = 0; y < mapnav.mapVerticalSize; y++)
                {
                    for (int x = 0; x < mapnav.mapHorizontalSize; x++)
                    {
                        idx++;
                        if (idx >= mapnav.grid.Length)
                        {
                            break;
                        }
                        if (!mapnav.grid[idx].isValid)
                        {
                            continue;
                        }

                        float sz = HandleUtility.GetHandleSize(mapnav.grid[idx].position);
                        if (sz > tz)
                        {
                            continue;
                        }
                        string l = mapnav.grid[idx].q + ", " + mapnav.grid[idx].r;
                        Handles.Label(mapnav.grid[idx].position, l);
                    }
                }
            }

            if (tool[1])
            {
                Tools.current = Tool.None;

                if (linkTool_MarkMode)
                {
                    DrawLinkToolMarkMode();
                }

                if (linkTool_DrawLinks)
                {
                    DrawLinks();
                }
            }

            // prevent selection of other objects while the map is active
            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(0);
            }
        }
Example #3
0
        /// <summary> This will update the link data with the target node or create the data if
        /// it does not yet exist. </summary>
        public void UpdateOrCreateLinkData(int targetNodeIdx, int data, MapNavBase map)
        {
            //Debug.Log(ToString() + " <-> " + map.grid[targetNodeIdx].ToString() + " = " + data);
            if (this.idx < 0)
            {
                Debug.LogError("This node is not a valid node. Link data should not be created with it.");
                return;
            }

            if (targetNodeIdx < 0 || targetNodeIdx >= map.grid.Length)
            {
                Debug.LogError("Target Node's index is invalid: " + targetNodeIdx);
                return;
            }

            if (map.grid[targetNodeIdx].idx < 0)
            {
                Debug.LogError("Target node is not a valid node. Link data should not be created with it.");
                return;
            }

            MapNavNodeLink d = GetLinkData(targetNodeIdx);

            if (d == null)
            {
                if (linkData == null)
                {
                    linkData = new List <MapNavNodeLink>();
                }
                d = new MapNavNodeLink()
                {
                    nodeIdx = targetNodeIdx
                };
                linkData.Add(d);
            }

            d.data = data;

            // make sure the other node has the same data
            d = map.grid[targetNodeIdx].GetLinkData(this.idx);
            if (d == null)
            {
                if (map.grid[targetNodeIdx].linkData == null)
                {
                    map.grid[targetNodeIdx].linkData = new List <MapNavNodeLink>();
                }
                d = new MapNavNodeLink()
                {
                    nodeIdx = this.idx
                };
                map.grid[targetNodeIdx].linkData.Add(d);
            }

            d.data = data;
        }
        // ------------------------------------------------------------------------------------------------------------

        protected virtual void OnEnable()
        {
            mapnav = target as MapNavBase;
            UpdateLinkCache();
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            if (GUI.changed)
            {
                EditorUtility.SetDirty(mapnav);
                GUI.changed = false;
            }

            InitUI();

            mapnav = target as MapNavBase;
            if (mapnav == null)
            {
                return;
            }

            EditorGUILayout.Space();
            GUILayout.Label("Tools");
            if (GUILayout.Button("Generate Grid"))
            {
                for (int i = 0; i < tool.Length; i++)
                {
                    tool[i] = false;
                }
                linkCache.Clear();
                col.Clear();
                linkTool_Nodes[0].Clear();
                linkTool_Nodes[1].Clear();

                mapnav.CreateGrid(NodeType);
                EditorUtility.SetDirty(mapnav);
            }
            if (GUILayout.Button("Lift Grid"))
            {
                mapnav.ChangeGridHeight(+1);
                EditorUtility.SetDirty(mapnav);
            }
            if (GUILayout.Button("Lower Grid"))
            {
                mapnav.ChangeGridHeight(-1);
                EditorUtility.SetDirty(mapnav);
            }
            if (GUILayout.Button("Smooth Out"))
            {
                mapnav.SmoothOut();
                EditorUtility.SetDirty(mapnav);
            }

            tool[0] = GUILayout.Toggle(tool[0], "Height Tool", GUI.skin.button);
            if (tool[0])
            {
                EditorGUILayout.BeginVertical(Toolbox_Style);
                heightTool_LayerMask      = MapNavEdUtil.GUILayout_LayerMaskField("Layer Mask", heightTool_LayerMask);
                heightTool_startHeight    = EditorGUILayout.FloatField("Start Height", heightTool_startHeight);
                heightTool_endHeight      = EditorGUILayout.FloatField("End Height", heightTool_endHeight);
                heightTool_markInvalids   = EditorGUILayout.Toggle("Mark Invalid", heightTool_markInvalids);
                heightTool_extraPrecision = (heightTool_extraPrecision_type)EditorGUILayout.EnumPopup("Extra Precision", heightTool_extraPrecision);
                if (MapNavEdUtil.GUILayout_LabelButton("", "Execute"))
                {
                    mapnav.AdjustToColliders(heightTool_LayerMask, heightTool_startHeight, linkTool_Data, heightTool_markInvalids, (int)heightTool_extraPrecision);
                    EditorUtility.SetDirty(mapnav);
                }
                EditorGUILayout.EndVertical();
            }

            EditorGUI.BeginChangeCheck();
            tool[1] = GUILayout.Toggle(tool[1], "NodeLink Tool", GUI.skin.button);
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }

            if (tool[1])
            {
                EditorGUILayout.BeginVertical(Toolbox_Style);
                DrawLinkTool();
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            GUILayout.Label("Debug");
            mapnav._dev_show_nodes = GUILayout.Toggle(mapnav._dev_show_nodes, "Show Nodes", GUI.skin.button);
            if (mapnav._dev_show_nodes)
            {
                EditorGUI.BeginChangeCheck();
                debug_ShowLabels = EditorGUILayout.Toggle("Show labels", debug_ShowLabels);
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }
            }
        }