Ejemplo n.º 1
0
    public void SpawnVehicle(Vehicle vehiclePrefab, UniversePosition universePosition, Quaternion rotation)
    {
        _playVehicleInstance = ((GameObject)Instantiate(vehiclePrefab.gameObject, universePosition.CellLocalPosition, rotation)).GetComponent<Vehicle>();
        _playVehicleInstance.Controller = gameObject;
        _playVehicleInstance.Shiftable.SetShiftPosition(universePosition);
        _playVehicleInstance.GetComponent<Targetable>().Team = Team;

        var member = GetComponent<Fighter>();
        member.SetVehicleInstance(_playVehicleInstance);

        _playVehicleInstance.Initialize();

        var playerCurrent = Squadron.GetMember(Squadron.GetCurrentIndex()).GetComponent<ShipProfile>();

        if (playerCurrent.PrimaryWeapon != null)
            _playVehicleInstance.SetPrimaryWeapon(playerCurrent.PrimaryWeapon.gameObject);
        if (playerCurrent.SecondaryWeapon != null)
            _playVehicleInstance.SetSecondaryWeapon(playerCurrent.SecondaryWeapon.gameObject);

        _playVehicleInstance.UTurnPath = UTurnPath;
        _playVehicleInstance.UTurnDuration = UTurnDuration;
        //Destroy(_playVehicleInstance.GetComponent<Tracker>());

        Destroy(_playVehicleInstance.GetComponent<VehicleTracker>());
        var squadronTracker = _playVehicleInstance.gameObject.AddComponent<SquadronTracker>();
        squadronTracker.ArrowSprite = Squadron.ArrowSprite;
        //squadronTracker.TrackerSprite = Squadron.TrackerSprite;
        //squadronTracker.FarTrackerSprite = Squadron.FarTrackerSprite;
        //squadronTracker.VeryFarTrackerSprite = Squadron.VeryFarTrackerSprite;
        squadronTracker.LockingSprite = Squadron.LockingTrackerSprite;
        squadronTracker.LockedSprite = Squadron.LockedTrackerSprite;
        squadronTracker.CallSign = CallSign;
        squadronTracker.TrackerColor = TrackerColor;
        squadronTracker.LabelFont = Squadron.SquadronTrackerFont;
        squadronTracker.IsDisabled = true;

        var mapPin = VehicleInstance.gameObject.AddComponent<MapPin>();
        mapPin.ActivePin = PlayerPinPrefab;
        mapPin.InactivePin = Squadron.SquadronPinPrefab;

        _playVehicleInstance.gameObject.layer = LayerMask.NameToLayer("Player");

        _playVehicleInstance.Killable.OnDamage += PlayerController_OnDamage;
        _playVehicleInstance.Killable.OnDie += PlayerController_OnDie;

        // Apply power profile
        var powerProfile = GetComponent<ShipProfile>();
        _playVehicleInstance.Killable.MaxShield = powerProfile.GetShield();
        _playVehicleInstance.Killable.Shield = _playVehicleInstance.Killable.MaxShield;

        var shieldRegenerator = _playVehicleInstance.gameObject.GetComponent<ShieldRegenerator>();
        shieldRegenerator.RegenerationDelay = Squadron.ShieldRegenerateDelay;
        shieldRegenerator.RegenerationRate = Squadron.ShieldRegenerateRate;
        shieldRegenerator.OnRegenerate += PlayerController_OnRegenerate;
    }