/// <summary> /// Run through the mount points to ensure everything is connected to /// a valid object. This way we can clean up before we process. /// </summary> private void PreProcessPoints() { // Clean up mount points to ensure everything stays in synch MountPoint lPoint = mTarget.Point; // Ensure the mount point is still valid if (lPoint.Owner == null) { lPoint.ChildTo(null); lPoint.Owner = mTarget.gameObject; } // Ensure any parent we may have is valid else if (lPoint.ParentMountPoint != null && lPoint.ParentMountPoint.Owner == null) { lPoint.ChildTo(null); } // Process the mount point properties else { // We force it here so that if the owner changes scale, we can reset it lPoint.IgnoreParentScale = lPoint.IgnoreParentScale; // Ensure all the child mount points are valid. It's possible that the // owner of a child mount point has been deleted. We need to check for that first for (int j = lPoint.ChildMountPoints.Count - 1; j >= 0; j--) { MountPoint lChildPoint = lPoint.ChildMountPoints[j].MountPoint; if (lChildPoint == null || lChildPoint.Owner == null) { lPoint.ChildMountPoints.RemoveAt(j); mIsDirty = true; } } } }
private void OnMouseUp() { // Grab the closest point that doesn't belong to this object MountPoint lClosestMountPoint = MountPoints.GetClosestMountPoint(mMountPoints); if (lClosestMountPoint != null) { // Grab the closest point from this object to the just-found point Vector3 lTestPosition = lClosestMountPoint._Anchor.transform.position; MountPoint lThisMountPoint = mMountPoints.GetClosestMountPoint(lTestPosition); if (lThisMountPoint != null) { // Disconnect any existing parent for (int i = 0; i < mMountPoints.Points.Count; i++) { mMountPoints.Points[i].ChildTo(null); } // Check if we're in snap distance float lDistance = Vector3.Distance(lTestPosition, lThisMountPoint._Anchor.transform.position); if (lDistance < mSnapDistance) { // Connect this new one lThisMountPoint.ChildTo(lClosestMountPoint); } } } }
/// <summary> /// Breaks the connection between the child and parent mount points /// </summary> /// <param name="rChild">Child mount point to break</param> private void DisconnectMountPoints(MountPoint rChild, MountPoint rParent) { if (rChild == null) { return; } rChild.ChildTo(null); // Sanity check to ensure the child is removed from the parent if (rParent != null) { rParent.RemoveChild(rChild); } // Flag the list as needing updating mIsDirty = true; }
/// <summary> /// Manages the connection between two mount points (and thier owners) /// </summary> /// <param name="rChild"></param> /// <param name="rParent"></param> private void ConnectMountPoints(MountPoint rChild, MountPoint rParent) { if (rChild == null) { return; } if (!rChild.IsLocked) { return; } if (rParent != null && !rParent.AllowChildren) { return; } // Parent the two rChild.ChildTo(rParent); // Flag the list as needing updating mIsDirty = true; }