public void SelectLink(TectonicFaultLine link)
        {
            Selection = SelectionState.SingleLink;

            SelectedLink          = link;
            SelectedLink.Material = FaultMaterialHighlighted;
        }
        public void AddLink(TectonicFaultLine faultLine)
        {
            ValidateLinkContainer();

            faultLine.name             = "Fault Line #" + LinkContainer.childCount.ToString().PadLeft(3, '0');
            faultLine.transform.parent = LinkContainer;

            FaultLines.Add(faultLine);
        }
        private TargetType GetMouseTarget(out RaycastHit hitData)
        {
            hitData = default;
            TargetType targetType = TargetType.Invalid;

            // See if the mouse is on/near anything important
            RaycastHit[] castHits = CastForTargets();

            // If anything was hit
            if (castHits.Length > 0)
            {
                for (int i = 0; i < castHits.Length; i++)
                {
                    hitData = castHits[i];

                    // Determine type of target hit
                    if (hitData.transform.tag == Tags.TectonicNode)
                    {
                        targetType = TargetType.Node;
                    }
                    else if (hitData.transform.tag == Tags.TectonicLink)
                    {
                        targetType = TargetType.Line;
                    }
                    else
                    {
                        continue;
                    }

                    return(targetType);
                }
                // did not find a layer of interest, must have been a base layer

                // Additional check for fault lines
                var links           = FaultMap.FaultLines;
                var selectionSphere = new Sphere(hitData.point, SelectionSphereRadius);
                foreach (TectonicFaultLine link in links)
                {
                    var linkLine = new Line(link.NodeA.CardinalPos, link.NodeB.CardinalPos);
                    if (Geometry.LineIntersectsSphere(linkLine, selectionSphere))
                    {
                        // Found a fault line
                        lastDetectedLink = link;
                        return(TargetType.Line);
                    }
                }

                return(TargetType.Empty);
            }
            // else must not have found any targets.
            else
            {
                return(targetType);
            }
        }
        public void DeselectLink()
        {
            Selection = SelectionState.Nothing;
            if (SelectedLink == null)
            {
                return;
            }

            SelectedLink.Material = FaultMaterialDefault;
            SelectedLink          = null;
        }
        public TectonicFaultLine[] FindLinks()
        {
            var links = new TectonicFaultLine[LinkContainer.childCount];

            for (int i = 0; i < links.Length; i++)
            {
                links[i] = LinkContainer.GetChild(i).GetComponent <TectonicFaultLine>();
            }

            return(links);
        }
        public void RemoveLink(TectonicFaultLine faultLine)
        {
            ValidateLinkContainer();

            for (int i = 0; i < LinkContainer.childCount; i++)
            {
                var thisLine = LinkContainer.GetChild(i).GetComponent <TectonicFaultLine>();
                if (thisLine == faultLine)
                {
                    thisLine.NodeA?.Links.Remove(thisLine);
                    thisLine.NodeB?.Links.Remove(thisLine);

                    FaultLines.Remove(thisLine);
                    Destroy(thisLine.gameObject);
                    break;
                }
            }
        }