コード例 #1
0
    public void    SpawnVehicle()
    {
        SanAndreasUnity.Behaviours.PlayerController cont =
            GameObject.FindObjectOfType <SanAndreasUnity.Behaviours.PlayerController> ();

        if (null == cont)
        {
            Debug.LogError("PlayerController component not found - failed to spawn vehicle.");
        }
        else
        {
            Vector3 pos = cont.transform.position + cont.transform.forward * this.spawnOffset.z + cont.transform.up * this.spawnOffset.y
                          + cont.transform.right * this.spawnOffset.x;
            Quaternion rotation = Quaternion.LookRotation(cont.transform.right, Vector3.up);

            //	SanAndreasUnity.Behaviours.Vehicles.VehicleSpawner.Create ();
            SanAndreasUnity.Behaviours.Vehicles.Vehicle v = SanAndreasUnity.Behaviours.Vehicles.Vehicle.Create(-1, null, pos, rotation);
            Debug.Log("Spawned vehicle with id" + v.Definition.Id);
        }
    }
コード例 #2
0
        public void EnterVehicle(Vehicle vehicle, Vehicle.SeatAlignment seatAlignment, bool immediate = false)
        {
            if (IsInVehicle) return;

            CurrentVehicle = vehicle;

            var timer = new Stopwatch();
            timer.Start();

            var seat = vehicle.GetSeat(seatAlignment);

            _controller.enabled = false;

            if (IsLocalPlayer) {
                Camera.transform.SetParent(seat.Parent, true);

                SendToServer(_lastPassengerState = new PlayerPassengerState {
                    Vechicle = vehicle,
                    SeatAlignment = (int) seatAlignment
                }, DeliveryMethod.ReliableOrdered, 1);
            }

            transform.SetParent(seat.Parent);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;

            if (IsLocalPlayer && seat.IsDriver) {
                vehicle.StartControlling();
            }

            PlayerModel.IsInVehicle = true;

            _currentVehicleSeatAlignment = seat.Alignment;

            StartCoroutine(EnterVehicleAnimation(seat, immediate));
        }
コード例 #3
0
 private void Awake()
 {
     _vehicle = GetComponent<Vehicle>();
 }
コード例 #4
0
        private IEnumerator EnterVehicleAnimation(Vehicle.Seat seat, bool immediate)
        {
            var animIndex = seat.IsLeftHand ? AnimIndex.GetInLeft : AnimIndex.GetInRight;

            PlayerModel.VehicleParentOffset = Vector3.Scale(PlayerModel.GetAnim(AnimGroup.Car, animIndex).RootEnd, new Vector3(-1, -1, -1));

            if (!immediate) {
                var animState = PlayerModel.PlayAnim(AnimGroup.Car, animIndex, PlayMode.StopAll);
                animState.wrapMode = WrapMode.Once;

                while (animState.enabled) {
                    yield return new WaitForEndOfFrame();
                }
            }

            if (seat.IsDriver) {
                IsDrivingVehicle = true;

                PlayerModel.PlayAnim(AnimGroup.Car, AnimIndex.Sit, PlayMode.StopAll);
            } else {
                PlayerModel.PlayAnim(AnimGroup.Car, AnimIndex.SitPassenger, PlayMode.StopAll);
            }

            IsInVehicleSeat = true;
        }