void LoadPlayerModelAndEquipItems()  //Loads the players preview model and adds all of the currently equipped items
    //Clear old Playermodels
    {
        while (playerModelSpawnPosition.childCount > 0)
        {
            Destroy(playerModelSpawnPosition.GetChild(0).gameObject);
        }

        //Load Player Model Reference
        AssetReference playerModelRef = new AssetReference(playerData.playerCharacterAdress + "_MM");

        playerModelRef.LoadAssetAsync <GameObject>().Completed += output =>
        {
            //Spawn loaded Model and set new reference
            GameObject playerModel = Instantiate(output.Result, playerModelSpawnPosition);
            playerVisuals = playerModel.GetComponent <PlayerVisualsManager>();

            //Equip Items to new model
            LoadLookFromAdress(playerData.helmetSlotAdress, SlotType.Head);
            LoadLookFromAdress(playerData.chestArmorSlotAdress, SlotType.Chest);
            LoadLookFromAdress(playerData.gauntletSlotAdress, SlotType.Hands);
            LoadLookFromAdress(playerData.legArmorSlotAdress, SlotType.Legs);
            LoadLookFromAdress(playerData.footArmorSlotAdress, SlotType.Feet);
            LoadLookFromAdress(playerData.weaponSlotAdress, SlotType.Weapon);
        };
    }
예제 #2
0
    //Modifies the players stats according to the items data
    void InitItemData(ItemStats item, PlayerCharacter playerCharacter, PlayerVisualsManager playerVisuals)
    {
        playerCharacter.maxHealth     += item.healthMod;
        playerCharacter.totalSpeedMod += item.speedMod;
        playerCharacter.staggerWindow += item.staggerMod;
        playerCharacter.initialArmor  += item.armorMod;
        playerCharacter.attackDamage  += item.damageMod;

        playerVisuals.DisplayEquipment(item);
    }
예제 #3
0
    public async Task LoadRequiredAssets()
    {
        //Load required Data from Adressables
        PersistentPlayerState persistentPlayer = GameObject.FindGameObjectWithTag("PlayerState").GetComponent <PersistentPlayerState>();
        AssetReference        playerCharRef    = new AssetReference(persistentPlayer.playerCharacterAdress);
        GameObject            player           = await playerCharRef.InstantiateAsync(playerCharSpawnPos, Quaternion.identity).Task;

        PlayerStats     playerStats     = player.GetComponent <PlayerStats>();
        PlayerCharacter playerCharacter = player.GetComponent <PlayerCharacter>();

        PlayerVisualsManager playerVisuals = player.GetComponent <PlayerVisualsManager>();

        AssetReference worldRef = new AssetReference(persistentPlayer.worldSpawnerAdress);
        GameObject     world    = await worldRef.InstantiateAsync(worldSpawnerSpawnPos, Quaternion.identity).Task;

        if (persistentPlayer.helmetSlotAdress != "")
        {
            AssetReference helmetRef  = new AssetReference(persistentPlayer.helmetSlotAdress);
            ItemStats      helmetItem = await helmetRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(helmetItem, playerCharacter, playerVisuals);
        }

        if (persistentPlayer.chestArmorSlotAdress != "")
        {
            AssetReference chestRef  = new AssetReference(persistentPlayer.chestArmorSlotAdress);
            ItemStats      chestItem = await chestRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(chestItem, playerCharacter, playerVisuals);
        }

        if (persistentPlayer.gauntletSlotAdress != "")
        {
            AssetReference handRef      = new AssetReference(persistentPlayer.gauntletSlotAdress);
            ItemStats      gauntletItem = await handRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(gauntletItem, playerCharacter, playerVisuals);
        }

        if (persistentPlayer.legArmorSlotAdress != "")
        {
            AssetReference legRef  = new AssetReference(persistentPlayer.legArmorSlotAdress);
            ItemStats      legItem = await legRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(legItem, playerCharacter, playerVisuals);
        }

        if (persistentPlayer.footArmorSlotAdress != "")
        {
            AssetReference footRef  = new AssetReference(persistentPlayer.footArmorSlotAdress);
            ItemStats      footItem = await footRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(footItem, playerCharacter, playerVisuals);
        }

        if (persistentPlayer.weaponSlotAdress != "")
        {
            AssetReference weaponRef  = new AssetReference(persistentPlayer.weaponSlotAdress);
            ItemStats      weaponItem = await weaponRef.LoadAssetAsync <ItemStats>().Task;

            InitItemData(weaponItem, playerCharacter, playerVisuals);
        }

        //Once everything is loaded, setup the game and run
        playerStats.Initiate();
        world.GetComponent <WorldMover>().Initiate();
    }