Beispiel #1
0
    private EdgeCollider2D NewCollider(Rail.Segment first)
    {
        var edgeCollider = new GameObject(first.IsWall() ? "Wall" : "Rail Part", typeof(EdgeCollider2D))
                           .GetComponent <EdgeCollider2D>();

        edgeCollider.transform.SetParent(transform, false);
        if (OverrideLayer != 0)
        {
            edgeCollider.gameObject.layer = OverrideLayer;
        }
        else
        {
            edgeCollider.gameObject.layer = LayerMask.NameToLayer(first.IsWall() ? Layers.Wall : Layers.Ground);
        }

        if (this.GetInterfaceComponent <IMoving>() != null)
        {
            edgeCollider.gameObject.tag = Tags.Moving;
        }

        // ReSharper disable once RedundantExplicitArrayCreation
        edgeCollider.points = new Vector2[]
        { first.From - (Vector2)transform.position, first.To - (Vector2)transform.position };
        return(edgeCollider);
    }
Beispiel #2
0
    private static void DrawLine(Rail.Segment segment, bool dotted = false)
    {
        var color = GroundColor;

        if (segment.IsWall())
        {
            color = WallColor;
        }
        else if (segment.Slope > Rail.SlopeLimit)
        {
            color = HighSlopeColor;
        }

        using (new Handles.DrawingScope(color))
        {
            Style.normal.textColor = Handles.color;

            if (dotted)
            {
                Handles.DrawDottedLine(segment.From, segment.To, DottedLinesSpace);
            }
            else
            {
                Handles.DrawLine(segment.From, segment.To);
            }

            var label = segment.Length.ToString("F1");
            if (!segment.IsWall())
            {
                label += " | " + segment.Slope.ToString("F0") + "°";
            }

            var labelPos    = segment.Center + segment.Normal * -0.6f;
            var labelSize   = GUI.skin.label.CalcSize(new GUIContent(label));
            var adjustedPos = HandleUtility
                              .GUIPointToWorldRay(HandleUtility.WorldToGUIPoint(labelPos) - 0.5f * labelSize).origin;
            Handles.Label(adjustedPos, label, Style);
        }
    }