当前位置: 首页>>代码示例>>C#>>正文


C# ObjectPool.GetObjectForType方法代码示例

本文整理汇总了C#中ObjectPool.GetObjectForType方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool.GetObjectForType方法的具体用法?C# ObjectPool.GetObjectForType怎么用?C# ObjectPool.GetObjectForType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectPool的用法示例。


在下文中一共展示了ObjectPool.GetObjectForType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SpawnThePlayer

    // HERO/PLAYER LOADING (Called by Resource Grid after Map has been initialized):
    public GameObject SpawnThePlayer(int posX, int posY)
    {
        resourceGrid = ResourceGrid.Grid;
        objPool = ObjectPool.instance;

        Vector3 playerPosition = new Vector3(posX, posY, 0.0f);
        GameObject Hero = objPool.GetObjectForType("Hero Rig", true, playerPosition);

        // After spawning the player Set up the Active Mission requirements and Enemies
        //SetUpMissionAndEnemies();

        /*
        HERE we need what Items the player chose to take with them to the surface.

        We'll need to know Equipped Items: Armor/Space Suit, Weapons, and Tools
        And all Consumable items.

        The correct set needs to be spawned as GameObjects and made children of the Hero GObj.

        We'll need to tell the Player_HeroAttackHandler how many weapons and tools the player has available and link
        the Weapon and Tool variables in that script to the corresponding child gameobjects.

        Default is 2 Weapons, 1 Tool

        Then for the weapons we need to tell its Gun base class to Upgrade any stats if the Weapon was upgraded...

        ...and finally, apply any upgrades to Tools.

        Hero base class.
        Armor.
        List of Weapons.
        List of Tools.
        List of consumables.
        List of abilities.

        upgradeWeapon function (type of upgrade U, type of weapon W){
            Weapons[w].upgrade(U);
        }

        In Weapons class:
        upgrade (type of upgrade U){
            switch(U){
                case attack rate type:
                weapon.stats.attackRate = U.attackRate;
                break;
            }
        }

        ** Solution:

        -Get the Weapon's Component from the name of the weapon ( from Hero class) for each weapon
        - The same for Tools
        - By default Weapon 1 should be active other weapons and tool gameobjects should be inactive

        */
        if (Hero)
        {
            // ***** FIX THIS! Right now this assumes that ALL weapons are guns and have gunstats. There should be a weapon type to
            // differentiate what a Melee weapon's component might need in terms of stats VS. what a gun gets for gunStats.

            // Get the Hero's attack handler.
            Player_HeroAttackHandler hero_attkHandler = Hero.GetComponent<Player_HeroAttackHandler>();

            // Spawn Weapons:

            // Get the first weapon by using the item's name. Name should match the gameobject pre-loaded by Object Pool
            GameObject wpn1 = ObjectPool.instance.GetObjectForType(theHero.weapons[0].itemName, true, Hero.transform.position);
            if (wpn1)
            {
                /* *** TRY THIS FOR ANIMATIONS: ****
                Once the weapon gets instantiated, parent it to the Front Rig's weapon Holder (this transform can be stored as a var on an EquipWeapon script on the Hero parent)
                since this is the default direction.
                Then when the animator goes to activate another rig, EquipWeapon would switch its parent to the correct direction's weapon holder. Since it itself will
                always have a Transform defaulted to 0 the weapon Holder should take care of giving it the correct rotation and position.

                Like so:
                wpn1.transform.SetParent(Hero.GetComponent<Equip_Weapon>().Weapon_Down);

                */

                // Use the method in Equip Weapon to set the default transform to down...
                Hero.GetComponent<Equip_Item>().SwitchRig(Equip_Item.EquipState.DOWN);

                // .. and set the sprite according to this weapon's name
                Hero.GetComponent<Equip_Item>().SwitchSprite(theHero.weapons[0].itemName);

                // Set the Wpn 1's transform to be a child of the Hero...
                wpn1.transform.SetParent(Hero.transform);

                // ... then shift it slightly into position.
                wpn1.transform.localPosition = new Vector3(-0.18f, 0.65f, 0);

                // Then through its Gun base class, set its stats (this will include any upgrades the Hero might have added)
               // wpn1.GetComponent<Player_GunBaseClass>().gunStats = theHero.weapons[0].gunStats;
                if (theHero.weapons[0].gunStats.shootsProjectiles)
                {
                    wpn1.GetComponent<Player_GunBaseClass>().gunStats = new GunStats(theHero.weapons[0].gunStats.startingFireRate,
                                                              theHero.weapons[0].gunStats.startingReloadSpeed,
                                                              theHero.weapons[0].gunStats.startingChamberAmmo,
//.........这里部分代码省略.........
开发者ID:cesarrac,项目名称:TheyRise-game,代码行数:101,代码来源:GameMaster.cs


注:本文中的ObjectPool.GetObjectForType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。