OpenBve.TrainManager.OpenTrainDoors C# (CSharp) Method

OpenTrainDoors() static private method

Opens the left-hand or right-hand doors for the specified train
static private OpenTrainDoors ( Train Train, bool Left, bool Right ) : void
Train Train The train
Left bool Whether to open the left-hand doors
Right bool Whether to open the right-hand doors
return void
		internal static void OpenTrainDoors(Train Train, bool Left, bool Right)
		{
			bool sl = false, sr = false;
			for (int i = 0; i < Train.Cars.Length; i++)
			{
				if (Left & !Train.Cars[i].Specs.AnticipatedLeftDoorsOpened)
				{
					Train.Cars[i].Specs.AnticipatedLeftDoorsOpened = true;
					sl = true;
				}
				if (Right & !Train.Cars[i].Specs.AnticipatedRightDoorsOpened)
				{
					Train.Cars[i].Specs.AnticipatedRightDoorsOpened = true;
					sr = true;
				}
			}
			if (sl)
			{
				for (int i = 0; i < Train.Cars.Length; i++)
				{
					Sounds.SoundBuffer buffer = Train.Cars[i].Sounds.DoorOpenL.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[i].Sounds.DoorOpenL.Position;
						Sounds.PlaySound(buffer, Train.Cars[i].Specs.DoorOpenPitch, 1.0, pos, Train, i, false);
					}
					for (int j = 0; j < Train.Cars[i].Specs.Doors.Length; j++)
					{
						if (Train.Cars[i].Specs.Doors[j].Direction == -1)
						{
							Train.Cars[i].Specs.Doors[j].DoorLockDuration = 0.0;
						}
					}
				}
			}
			if (sr)
			{
				for (int i = 0; i < Train.Cars.Length; i++)
				{
					Sounds.SoundBuffer buffer = Train.Cars[i].Sounds.DoorOpenR.Buffer;
					if (buffer != null)
					{
						OpenBveApi.Math.Vector3 pos = Train.Cars[i].Sounds.DoorOpenR.Position;
						Sounds.PlaySound(buffer, Train.Cars[i].Specs.DoorClosePitch, 1.0, pos, Train, i, false);
					}
					for (int j = 0; j < Train.Cars[i].Specs.Doors.Length; j++)
					{
						if (Train.Cars[i].Specs.Doors[j].Direction == 1)
						{
							Train.Cars[i].Specs.Doors[j].DoorLockDuration = 0.0;
						}
					}
				}
			}
		}

Usage Example

Exemplo n.º 1
0
 /// <summary>
 /// open right door
 /// </summary>
 static public void RightDoorOpen()
 {
     try
     {
         TrainManager.OpenTrainDoors(TrainManager.PlayerTrain, false, true);
     }
     catch (Exception ex) { }
 }
All Usage Examples Of OpenBve.TrainManager::OpenTrainDoors