void LocateBackLink(LinkScript link, bool allowCreate = false)
 {
     NodeInstance from = link.GetComponentInParent<NodeInstance>();
     NodeInstance to = link.to;
     link.backLink = to.GetComponentsInChildren<LinkScript>().ToList().FirstOrDefault(other => {
         if (other.to != from) {
             return false;
         }
         var testObject = new GameObject("TestObject").transform;
         var otherParent = other.transform.parent;
         testObject.SetParent(to.transform, worldPositionStays: false);
         other.transform.SetParent(testObject, worldPositionStays: true);
         testObject.SetParent(link.transform, worldPositionStays: false);
         var result = Extensions.Close(other.transform, from.transform);
         other.transform.SetParent(otherParent, worldPositionStays: false);
         DestroyImmediate(testObject.gameObject);
         return result;
     });
     if (link.backLink == null) {
         if (!allowCreate) {
             Debug.LogError(string.Format("No backlink detected: {0} {1}", from.name, link.name));
         } else {
             Debug.LogFormat(string.Format("No backlink detected: {0} {1}", from.name, link.name));
             var backlinkObject = new GameObject(GenerateLinkName(link.to, from) + " (backlink)");
             var backlink = backlinkObject.AddComponent<LinkScript>();
             backlink.to = from;
             backlinkObject.transform.SetParent(from.transform);
             backlinkObject.transform.Reset();
             backlinkObject.transform.SetParent(link.transform, worldPositionStays: true);
             var linkFolder = LinkFolder(link.to);
             backlinkObject.transform.SetParent(linkFolder, worldPositionStays: false);
             link.backLink = backlink;
             Debug.LogFormat("Backlink created: {0} {1} - {2} {3}", from.name, link.name, to.name, link.backLink.name);
             backlink.backLink = link;
             Debug.LogFormat("Backlink set: {0} {1} - {2} {3}", to.name, link.backLink.name, from.name, link.name);
         }
     } else {
         Debug.LogFormat("Backlink set: {0} {1} - {2} {3}", from.name, link.name, to.name, link.backLink.name);
     }
 }
예제 #2
0
 public void SetBackLink()
 {
     link.backLink = backLink.link;
     backLink = null;
 }
 bool AcceptableEditor(NodeInstance node, LinkScript link)
 {
     return node == link.to && Extensions.Close(node.transform, link.transform);
 }
예제 #4
0
 NodeInstance CreateNewNode(LinkScript link)
 {
     var newNode = link.link.to.NewNodeInstance();
     //Debug.LogFormat("New node created for {0}: {1}", link.transform.Path(), newNode);
     newNode.transform.SetParent(link.transform);
     newNode.transform.Reset();
     newNode.transform.SetParent(world, worldPositionStays: true);
     return newNode;
 }
예제 #5
0
 public static bool Acceptable(NodeInstance node, LinkScript link)
 {
     var closeTranform = Extensions.Close(node.transform, link.transform);
     return node.node == link.Node && closeTranform;
 }
예제 #6
0
 void HandleOverlap(NodeInstance from, NodeInstance overlap, LinkScript link)
 {
     var overlappedNode = overlap;
     if (Acceptable(overlappedNode, link)) {
         link.to = overlappedNode;
         overlappedNode.links[link.link.backLink].to = from;
     }
 }
예제 #7
0
    void FollowLink(Queue<NodeInstance> queue, NodeInstance from, LinkScript link)
    {
        var debug = false;
        //debug = from.name == "Node 8 (4) #2" && link.name == "Up";
        if (debug) {
            Debug.LogFormat("debug link: {0}", link.transform.Path());
        }

        if (bfsNodeCount >= MAX_NODES) {
            Debug.LogWarning("cnt >= MAX_NODES");
            return;
        }

        NodeInstance overlapNode = null;
        overlapNode = Overlapper.OverlapPoint(link.transform.position);
        if (overlapNode != null) {
            HandleOverlap(from, overlapNode, link);
            if (debug) {
                Debug.LogFormat("link {0}: overlapped by point with node {1}", link.transform.Path(), overlapNode);
            }
            return;
        }

        NodeInstance node = null;
        var oldNode = link.to;

        if (oldNode != null) {
            if (oldNode.IsOn()) {
                if (debug) {
                    Debug.LogFormat("link {0}: oldNode is on", link.transform.Path());
                }
                //link.AssertAcceptable();
                return;
            } else {
                node = oldNode;
            }
        } else {
            node = CreateNewNode(link);
            node.Off();
        }

        overlapNode = Overlapper.OverlapNode(node, reduction: 0.99f);
        if (overlapNode != null) {
            if (debug) {
                Debug.LogFormat("link {0}: overlapped with node: {1}", link.transform.Path(), overlapNode);
            }
            node.Disconnect();
            node.ReturnToPoolLight();
            HandleOverlap(from, overlapNode, link);
        } else {
            if (debug) {
                Debug.LogFormat("link {0}: set new node: {1}", link.transform.Path(), node);
            }
            node.On();
            node.distance = from.distance + 1;
            link.to = node;
            var nodeLinks = node.links;
            var backLinkSignature = link.link.backLink;
            var backLink = nodeLinks[backLinkSignature];
            backLink.to = from;
            //if (!link.AssertAcceptable()) {
            //    Debug.LogFormat("oldnode = {0}", oldNodeUsed);
            //}
            //backLink.AssertAcceptable();
            nodes.Add(node);
            queue.Enqueue(node);
            bfsNodeCount++;
        }
    }