Beispiel #1
0
    public void InstallPart(VehicleClass _vehicle)
    {
        switch (partType)
        {
        case PartType.Drill:
            _vehicle.InstallPart((PartDrill)installedPart);
            break;

        case PartType.Cabin:
            _vehicle.InstallPart((PartCabin)installedPart);
            break;

        case PartType.Engine:
            _vehicle.InstallPart((PartEngine)installedPart);
            break;

        case PartType.Wheels:
            _vehicle.InstallPart((PartWheel)installedPart);
            break;

        case PartType.Upgrade:
            _vehicle.InstallPart((PartUpgrade)installedPart);
            break;
        }
    }
    public void FinalizeChanges()
    {
        PlayerController _player = FindObjectOfType <PlayerController>();

        foreach (VehicleEditorComponent _editorComponent in editorComponents)
        {
            switch (_editorComponent.partType)
            {
            case PartType.Drill:
                vehicle.GetPart(out PartDrill _drill);
                if (_drill == null || _drill != (PartDrill)_editorComponent.installedPart)
                {
                    if (_editorComponent.installedPart != null)     //if the part isn't just being removed, take it away from the player, then add the old part to the players inv
                    {
                        _player.AddPart(_drill);
                        _player.RemovePart(_editorComponent.installedPart);
                    }
                    vehicle.InstallPart((PartDrill)_editorComponent.installedPart);
                }
                break;

            case PartType.Cabin:
                vehicle.GetPart(out PartCabin _cabin);
                if (_cabin == null || _cabin != (PartCabin)_editorComponent.installedPart)
                {
                    if (_editorComponent.installedPart != null)     //if the part isn't just being removed, take it away from the player, then add the old part to the players inv
                    {
                        _player.AddPart(_cabin);
                        _player.RemovePart(_editorComponent.installedPart);
                    }
                    vehicle.InstallPart((PartCabin)_editorComponent.installedPart);
                    RefreshWorkerComponents();
                }
                break;

            case PartType.Engine:
                vehicle.GetPart(out PartEngine _engine);
                if (_engine == null || _engine != (PartEngine)_editorComponent.installedPart)
                {
                    if (_editorComponent.installedPart != null)     //if the part isn't just being removed, take it away from the player, then add the old part to the players inv
                    {
                        _player.AddPart(_engine);
                        _player.RemovePart(_editorComponent.installedPart);
                    }
                    vehicle.InstallPart((PartEngine)_editorComponent.installedPart);
                }
                break;

            case PartType.Wheels:
                vehicle.GetPart(out PartWheel _wheels);
                if (_wheels == null || _wheels != (PartWheel)_editorComponent.installedPart)
                {
                    if (_editorComponent.installedPart != null)     //if the part isn't just being removed, take it away from the player, then add the old part to the players inv
                    {
                        _player.AddPart(_wheels);
                        _player.RemovePart(_editorComponent.installedPart);
                    }
                    vehicle.InstallPart((PartWheel)_editorComponent.installedPart);
                }
                break;

            case PartType.Upgrade:
                vehicle.GetPart(out PartUpgrade _upgrade);
                if (_upgrade == null || _upgrade != (PartUpgrade)_editorComponent.installedPart)
                {
                    if (_editorComponent.installedPart != null)     //if the part isn't just being removed, take it away from the player, then add the old part to the players inv
                    {
                        _player.AddPart(_upgrade);
                        _player.RemovePart(_editorComponent.installedPart);
                    }
                    vehicle.InstallPart((PartUpgrade)_editorComponent.installedPart);
                }
                break;
            }
        }
        vehicle.VehicleGraphics.ReDraw();
    }