Пример #1
0
    private void GenerateSegment()
    {
        var generatedSegment = Instantiate(segmentPrefabs[Random.Range(0, segmentPrefabs.Count)],
                                           Vector3.forward * -100, Quaternion.identity, transform).GetComponent <Segment>();
        var       selectedJointToSnap = generatedSegment.joints[Random.Range(0, generatedSegment.joints.Count)];
        Transform jointToSnap;

        var lastSegment = generatedSegments[generatedSegments.Count - 1];

        if (generatedSegments.Count > 1)
        {
            var prevSegment = generatedSegments[generatedSegments.Count - 2];

            jointToSnap = lastSegment.joints.FirstOrDefault(j =>
                                                            !prevSegment.joints.Any(jj => Vector3.Distance(j.transform.position, jj.transform.position) < 0.1f));
        }
        else
        {
            jointToSnap = lastSegment.joints[0];
        }

        SegmentUtility.SnapJoints(generatedSegment.transform, selectedJointToSnap, jointToSnap);

        generatedSegments.Add(generatedSegment);
    }
Пример #2
0
    public void AddWagon(Wagon wagon)
    {
        wagon.transform.SetParent(transform);
        wagon.transform.localPosition = Vector3.zero;

        if (Wagons.Count > 0)
        {
            SegmentUtility.SnapJoints(wagon.transform, wagon.StartJoint.transform,
                                      Wagons[Wagons.Count - 1].EndJoint.transform);
        }

        Wagons.Add(wagon);

        SaveVehicleProgress();
    }