美文网首页
十二、RPGInventoryInterface.h & Int

十二、RPGInventoryInterface.h & Int

作者: 珏_Gray | 来源:发表于2019-06-18 10:39 被阅读0次

为了不使用cast,ActionRPG项目定义了一个背包接口类,让Controller继承并实现。

/**
 * Interface for actors that provide a set of RPGItems bound to ItemSlots
 * This exists so RPGCharacterBase can query inventory without doing hacky player controller casts
 * It is designed only for use by native classes
 */

在代码中定义接口主要有两个步骤:

  1. 定义继承自UInterface的接口类: 命名为 “U + 接口名”
  2. 定义名字为“I + 接口名”的类,在这个类中定义接口方法

更多关于Interface的信息,请查看:
Interfaces in C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "ActionRPG.h"
#include "RPGInventoryInterface.generated.h"

/**
 * Interface for actors that provide a set of RPGItems bound to ItemSlots
 * This exists so RPGCharacterBase can query inventory without doing hacky player controller casts
 * It is designed only for use by native classes
 */
UINTERFACE(MinimalAPI, meta = (CannotImplementInterfaceInBlueprint))
class URPGInventoryInterface : public UInterface
{
    GENERATED_BODY()
};

class ACTIONRPG_API IRPGInventoryInterface
{
    GENERATED_BODY()

public:
    /** Returns the map of items to data */
    virtual const TMap<URPGItem*, FRPGItemData>& GetInventoryDataMap() const = 0;

    /** Returns the map of slots to items */
    virtual const TMap<FRPGItemSlot, URPGItem*>& GetSlottedItemMap() const = 0;

    /** Gets the delegate for inventory item changes */
    virtual FOnInventoryItemChangedNative& GetInventoryItemChangedDelegate() = 0;

    /** Gets the delegate for inventory slot changes */
    virtual FOnSlottedItemChangedNative& GetSlottedItemChangedDelegate() = 0;

    /** Gets the delegate for when the inventory loads */
    virtual FOnInventoryLoadedNative& GetInventoryLoadedDelegate() = 0;
};

相关文章

网友评论

      本文标题:十二、RPGInventoryInterface.h & Int

      本文链接:https://www.haomeiwen.com/subject/zeuxqctx.html