官术网_书友最值得收藏!

Time for action – Examining inheritance

  1. We can see an example of this by taking a look at the class tree in UnCodeX, under Actor | Inventory | Weapon | UDKWeapon. Expanding UTWeapon we can see the different types of weapons provided as examples in the UDK:
    Time for action – Examining inheritance

    We can see that UTBeamWeapon (like the plasma gun we start with when running the game), UTWeap_RocketLauncher , and UTWeap_ShockRifleBase are amongst our weaponry. Each of these behaves differently, but all of them have common functionality.

  2. Clicking on UTWeapon, we can see some of its variables.
    /** Initial ammo count if in weapon locker */
    var int LockerAmmoCount;
    
    /** Max ammo count */
    var int MaxAmmoCount;
    
    /** Holds the amount of ammo used for a given shot */
    var array<int> ShotCost;

What just happened?

Things like MaxAmmoCount and ShotCost are common to all of the weapons, so instead of having to duplicate the variables to all of the subclasses, they're declared in all of the weapons' parent class, UTWeapon. Indeed, if we look at UTWeapon's subclasses like UTWeap_RocketLauncher, we won't find MaxAmmoCount or any of UTWeapon's other variables declared in any of them.

Speaking of weapons, I think it's time we started having a little fun with our code. AwesomeActor has been good to us so far, but he doesn't really do a lot besides sit there and send out log messages. Let's make a weapon.

主站蜘蛛池模板: 美姑县| 通江县| 香格里拉县| 海原县| 改则县| 奇台县| 崇信县| 龙山县| 南投县| 铜梁县| 永安市| 哈密市| 西峡县| 江都市| 峨山| 辰溪县| 汉阴县| 宿州市| 于田县| 嵊州市| 类乌齐县| 徐州市| 珠海市| 防城港市| 定兴县| 鹰潭市| 上高县| 海丰县| 宁强县| 阿瓦提县| 临泉县| 南丰县| 上饶县| 平舆县| 新野县| 衢州市| 乌拉特后旗| 福建省| 南京市| 丰县| 涞水县|