Exemplo n.º 1
0
    public void GetOwnListRS()
    {
        if (rsComposition.CarComposition.IsOutside)
        {
            return;
        }
        ClearOwnListRS();
        count = 0;
        for (int i = 0; i < listComps.Length; i++)
        {
            tempComp = listComps [i];
            if (tempComp == null)
            {
                continue;
            }
            if (!tempComp.IsActive)
            {
                continue;
            }
            if (tempComp.IsOutside)
            {
                continue;
            }
            if (tempComp == rsComposition.CarComposition)
            {
                continue;
            }
            for (int j = engineRS.FirstTrackIndex; j <= engineRS.LastTrackIndex; j++)
            {
                if (engineRS.OwnPath[j] == tempComp.MainCar.OwnTrack)
                {
                    ownListComps [count] = tempComp;
                    count++;
                }
            }
        }

        leftCar       = null;
        rightCar      = null;
        tempDistLeft  = 100000;
        tempDistRight = 100000;

        tempLeftRS  = null;
        tempRightRS = null;

        for (int i = 0; i < ownListComps.Length; i++)
        {
            tempComp = ownListComps [i];
            if (tempComp == null)
            {
                return;
            }
            tempLeftRS  = tempComp.RightCar;
            tempRightRS = tempComp.LeftCar;

            // look for left car
            if (!engineRS.GetCoupledLeft() && engineT.position.x > tempLeftRS.GetPositionX())
            {
                if (GetDistanceToCar(tempLeftRS) < tempDistLeft)
                {
                    tempDistLeft = GetDistanceToCar(tempLeftRS);
                    leftCar      = tempLeftRS;
                }
            }
            else if (!engineRS.GetCoupledRight() && engineT.position.x < tempRightRS.GetPositionX())
            {
                if (GetDistanceToCar(tempRightRS) < tempDistRight)
                {
                    tempDistRight = GetDistanceToCar(tempRightRS);
                    rightCar      = tempRightRS;
                }
            }
        }
    }
Exemplo n.º 2
0
 private float GetDistanceToCar(RollingStock car)
 {
     return(Mathf.Abs(engineT.position.x - car.GetPositionX()));
 }