示例#1
0
    public void LinkTo(ref Tunnel other, bool connectionOrder)
    {
        int thisEndIndex  = connectionOrder ? ceiling.Count - 1 : 0;
        int otherEndIndex = connectionOrder ? 0 : other.ceiling.Count - 1;

        Vector2 connectionPoint = other.GetEnd(connectionOrder);
        Vector2 position2D      = connectionOrder ? connectionPoint - segment : connectionPoint;

        transform.position = new Vector3(position2D.x, position2D.y, transform.position.z);

        bool noIntersections;

        Vector3[] intersections = Intersections(this, other, out noIntersections);

        if (noIntersections == false)
        {
            ceiling[thisEndIndex] = intersections[0] - transform.position;
            floor[thisEndIndex]   = intersections[1] - transform.position;

            other.ceiling[otherEndIndex] = intersections[0] - other.transform.position;
            other.floor[otherEndIndex]   = intersections[1] - other.transform.position;
        }
        else
        {
            if (thisEndIndex == 0)
            {
                ceiling.Insert(0, other.ceiling[otherEndIndex] + (Vector2)other.transform.position - (Vector2)transform.position);
                floor.Insert(0, other.floor[otherEndIndex] + (Vector2)other.transform.position - (Vector2)transform.position);
            }
            else
            {
                ceiling.Add(other.ceiling[otherEndIndex] + (Vector2)other.transform.position - (Vector2)transform.position);
                floor.Add(other.floor[otherEndIndex] + (Vector2)other.transform.position - (Vector2)transform.position);
            }
        }

        RefreshGameObject();
        other.RefreshGameObject();

        if (connectionOrder)
        {
            connections0.Add(other);
            other.connections1.Add(this);
        }
        else
        {
            connections1.Add(other);
            other.connections0.Add(this);
        }
    }