Exemple #1
0
    // 建立武器
    public override IWeapon CreateWeapon(ENUM_Weapon emWeapon)
    {
        IWeapon pWeapon   = null;
        string  AssetName = "";
        int     AttrID    = 0;

        //根据武器类型建立
        switch (emWeapon)
        {
        case ENUM_Weapon.Knife:
            pWeapon   = new WeaponKnife();
            AssetName = "5";
            AttrID    = 1;
            break;

        default:
            Debug.LogWarning("创建[" + emWeapon + "]失败!!!");
            return(null);
        }

        // 加载武器资源
        IAssetFactory AssetFactory    = GameFactory.GetAssetFactory();
        Sprite        WeaponGameObjet = AssetFactory.LoadWeapon(AssetName);

        pWeapon.SetIWeapon(WeaponGameObjet);

        // 设置武器的威力
        IAttrFactory theAttrFactory = GameFactory.GetAttrFactory();
        WeaponAttr   theWeaponAttr  = theAttrFactory.GetWeaponAttr(AttrID);

        pWeapon.SetWeaponAttr(theWeaponAttr);

        return(pWeapon);
    }
Exemple #2
0
    // 建立武器
    public override IWeapon CreateWeapon(ENUM_Weapon emWeapon)
    {
        IWeapon pWeapon   = null;
        string  AssetName = "";         // Unity模型名称
        int     AttrID    = 0;          // 武器的能力值

        // 依武器
        switch (emWeapon)
        {
        case ENUM_Weapon.Gun:
            pWeapon   = new WeaponGun();
            AssetName = "WeaponGun";
            AttrID    = 1;
            break;

        case ENUM_Weapon.Rifle:
            pWeapon   = new WeaponRifle();
            AssetName = "WeaponRifle";
            AttrID    = 2;
            break;

        case ENUM_Weapon.Rocket:
            pWeapon   = new WeaponRocket();
            AssetName = "WeaponRocket";
            AttrID    = 3;
            break;

        default:
            Debug.LogWarning("CreateWeapon:无法建立[" + emWeapon + "]");
            return(null);
        }

        // 产生Asset
        IAssetFactory AssetFactory    = PBDFactory.GetAssetFactory();
        GameObject    WeaponGameObjet = AssetFactory.LoadWeapon(AssetName);

        pWeapon.SetGameObject(WeaponGameObjet);

        // 取得武器的威力
        IAttrFactory theAttrFactory = PBDFactory.GetAttrFactory();
        WeaponAttr   theWeaponAttr  = theAttrFactory.GetWeaponAttr(AttrID);

        // 设定武器的威力
        pWeapon.SetWeaponAttr(theWeaponAttr);

        return(pWeapon);
    }