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

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.

主站蜘蛛池模板: 当阳市| 靖宇县| 寿光市| 东乌珠穆沁旗| 缙云县| 永康市| 巴林右旗| 高青县| 稷山县| 衡山县| 祁门县| 阳曲县| 蒙山县| 介休市| 北碚区| 中牟县| 临洮县| 辉县市| 岐山县| 长兴县| 应城市| 五原县| 新干县| 来凤县| 三门县| 阿拉善右旗| 郸城县| 咸阳市| 达州市| 盈江县| 绥江县| 青川县| 百色市| 文昌市| 鹰潭市| 巢湖市| 连云港市| 金溪县| 宁晋县| 武宣县| 阿拉善右旗|