Exemple #1
0
        public NestPathElementEdge(NestPathNode a, NestPathNode b)
        {
            if (a.Host == b.Host)
            {
                throw new ArgumentException("同じNestElementのNestPathNodeをNestElementEdgeで接続することはできません。");
            }
            if (!a.IsConnectable(b))
            {
                throw new ArgumentException("指定されたNestPathNodeどうしは接続を禁止しています。");
            }
            if (!b.IsConnectable(a))
            {
                throw new ArgumentException("指定されたNestPathNodeどうしは接続を禁止しています。");
            }
            A    = a;
            B    = b;
            Data = new NestPathElementEdgeData()
            {
                ElementGuidA = a.Host.Data.Guid,
                ElementGuidB = b.Host.Data.Guid,
                NodeNameA    = a.Name,
                NodeNameB    = b.Name
            };

            RegisterToNode();
        }
Exemple #2
0
        /// <summary>
        /// 自動スナップを行った際に吸引されるノードを取得する。
        /// </summary>
        /// <param name="target"></param>
        /// <param name="originNode"></param>
        /// <param name="targetNode"></param>
        /// <param name="distance"></param>
        public void GetSnappableNode(NestElement target, out NestPathNode originNode, out NestPathNode targetNode,
                                     out float distance)
        {
            var nodes = Host.NestElements.Where(e => e != target).SelectMany(e => e.GetNodes()).Where(n => n.IsExposed);

            NestPathNode argMinDistanceOrigin = null;
            NestPathNode argMinDistance       = null;
            float        minSqrDistance       = float.MaxValue;

            foreach (var n in target.GetNodes().Where(n => n.IsExposed))
            {
                var connectables = nodes.Where(other =>
                                               other.IsExposed && other.IsConnectable(n) && n.IsConnectable(other));
                foreach (var other in connectables)
                {
                    float sqrDistance = (other.WorldPosition - n.WorldPosition).sqrMagnitude;
                    if (sqrDistance < minSqrDistance)
                    {
                        argMinDistanceOrigin = n;
                        minSqrDistance       = sqrDistance;
                        argMinDistance       = other;
                    }
                }
            }

            originNode = argMinDistanceOrigin;
            targetNode = argMinDistance;
            distance   = Mathf.Sqrt(minSqrDistance);
        }
Exemple #3
0
        public IEnumerable <IPathNode> FindRoute(NestPathNode from, NestPathNode to)
        {
            AStarSearcher searcher = new AStarSearcher(null);

            searcher.SearchRoute(from, to);
            return(searcher.Route);
        }
        public override bool IsConnectable(NestPathNode other)
        {
            //道のノードとだけ接続可能
            if (other is NestPathRoadNode)
            {
                if (this.Name.StartsWith("wild") || other.Name.StartsWith("wild"))
                {
                    return(true);
                }

                switch (other.Name)
                {
                case "right":
                    return(this.Name == "left");

                case "top":
                    return(this.Name == "bottom");

                case "left":
                    return(this.Name == "right");

                case "bottom":
                    return(this.Name == "top");

                default:
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
 public override bool IsConnectable(NestPathNode other)
 {
     if (!base.IsConnectable(other))
     {
         return(false);
     }
     return(true);
 }
Exemple #6
0
        public NestPathElementEdge ConnectElements(NestPathNode a, NestPathNode b)
        {
            var edge = new NestPathElementEdge(a, b);

            elementEdges.Add(edge);
            Data.Structure.ElementEdges.Add(edge.Data);
            return(edge);
        }
Exemple #7
0
 /// <summary>
 /// あるNestPathNodeとElementを越えた接続が可能であるか調べる。
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public virtual bool IsConnectable(NestPathNode other)
 {
     if (!IsExposed)
     {
         return(false);
     }
     return(true);
 }
Exemple #8
0
        /// <summary>
        /// 目的のNodeへの自動移動を開始する。
        /// </summary>
        /// <param name="node"></param>
        /// <param name="onArrived">ノードへ到着した際のコールバック。</param>
        /// <param name="onAborted">何らかの理由で移動が中止された際のコールバック。</param>
        public void StartForPathNode(NestPathNode node, Action onArrived = null, Action onAborted = null)
        {
            CancelMovement();

            OnAborted = onAborted;
            OnArrived = onArrived;

            CurrentTargetNode = node;
            UpdatePath();
        }
Exemple #9
0
        public override void StartStrategy(StrategyController <EnemyAntData> controller)
        {
            base.StartStrategy(controller);

            UpdateInterval = 1.0f;

            _targetNode = GetTargetPathNode();

            Controller.Ant.StartForPathNode(_targetNode, HandleArrived, HandleAborted);
        }
Exemple #10
0
        public NestPathLocalEdge(NestPathNode a, NestPathNode b)
        {
            if (a.Host != b.Host)
            {
                throw new ArgumentException("異なるNestElementに含まれるNestPathNodeどうしを接続することはできません。");
            }
            A = a;
            B = b;

            RegisterToNode();
        }
Exemple #11
0
        public NestPathElementEdge(IEnumerable <NestElement> elements, NestPathElementEdgeData data)
        {
            Data = data;
            NestElement elementA = null;
            NestElement elementB = null;

            foreach (var e in elements)
            {
                if (e.Data.Guid == data.ElementGuidA)
                {
                    elementA = e;
                }
                else if (e.Data.Guid == data.ElementGuidB)
                {
                    elementB = e;
                }
            }

            if (elementA == default || elementB == default)
            {
                throw new ArgumentException("指定されたNestElementが見つかりませんでした。");
            }

            var nodeA = elementA.GetNodes().Where(n => n.IsExposed).FirstOrDefault(n => n.Name == data.NodeNameA);

            if (nodeA == default)
            {
                throw new ArgumentException("指定されたNestPathNodeが見つかりませんでした。");
            }
            var nodeB = elementB.GetNodes().Where(n => n.IsExposed).FirstOrDefault(n => n.Name == data.NodeNameB);

            if (nodeB == default)
            {
                throw new ArgumentException("指定されたNestPathNodeが見つかりませんでした。");
            }

            if (!nodeA.IsConnectable(nodeB))
            {
                throw new ArgumentException("指定されたNestPathNodeどうしは接続を禁止しています。");
            }
            if (!nodeB.IsConnectable(nodeA))
            {
                throw new ArgumentException("指定されたNestPathNodeどうしは接続を禁止しています。");
            }

            A = nodeA;
            B = nodeB;

            RegisterToNode();
        }
Exemple #12
0
        private void UpdatePath()
        {
            //現在位置ノードが不明な場合や、既知のCurrentNodeが実際の現在位置から離れすぎている場合は、現在位置ノードを再計算
            if (CurrentNode == null || (CurrentNode.WorldPosition - (Vector2)transform.position).sqrMagnitude > 1f)
            {
                //現在位置が不明なので、検索
                float        minSqrDistance    = float.MaxValue;
                NestPathNode argMinSqrDistance = null;
                foreach (var node in NestSystem.Instance.NestPathNodes)
                {
                    float distance = (node.WorldPosition - (Vector2)transform.position).sqrMagnitude;
                    if (distance < minSqrDistance)
                    {
                        minSqrDistance    = distance;
                        argMinSqrDistance = node;
                    }
                }

                //とりあえず一番近いノードに移動
                NextNode = argMinSqrDistance ?? throw new NullReferenceException("巣にIPathNodeが見つかりませんでした。");
            }
            else
            {
                if (CurrentTargetNode == null)
                {
                    throw new NullReferenceException("ターゲットのノードを指定してください。");
                }
                var route = NestSystem.Instance.FindRoute(CurrentNode, CurrentTargetNode);
                if (route.Count() < 2)
                {
                    //ルート計算に失敗。接続されていない?
                    CurrentTargetNode = null;
                    var a = OnAborted;
                    OnArrived = null;
                    OnAborted = null;
                    a?.Invoke();
                    return;
                }

                if (route.ElementAt(1) is NestPathNode n)
                {
                    NextNode = n;
                }
                else
                {
                    throw new InvalidOperationException("ノードはNestPathNodeではない。");
                }
            }
        }
 public override bool IsConnectable(NestPathNode other)
 {
     return(true);
 }
Exemple #14
0
 /// <summary>
 /// このIPathNodeに接続されているNestPathNodeのうち、別のNestElementに属しているものをすべて取得する。
 /// </summary>
 /// <param name="target"></param>
 /// <param name="includeSuspendedEdge">CanGetThroughがfalseなedgeによる接続を含むか。</param>
 /// <returns></returns>
 public static IEnumerable <IPathNode> GetConnectedNodesForeign(this NestPathNode target,
                                                                bool includeSuspendedEdge = false)
 {
     return(target.Edges.Where(e => includeSuspendedEdge || e.CanGetThrough).OfType <NestPathElementEdge>()
            .Select(e => e.GetOtherNode(target)));
 }
Exemple #15
0
 public MoveStrategy(NestBuildableElement host, NestPathNode distNode) : base()
 {
     _distNode = distNode;
     _hostElem = host;
 }
Exemple #16
0
 /// <summary>
 /// あるNestPathNodeとElementを越えた接続が可能であるか調べる。
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public abstract bool IsConnectable(NestPathNode other);