예제 #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);
            }
        }
예제 #2
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;
        }