美文网首页
UE4对象系统_UProperty

UE4对象系统_UProperty

作者: 蛋求疼 | 来源:发表于2017-08-21 20:42 被阅读0次

UProperty(含其子类)实例描述了类的某个成员变量的反射信息。

  • UProperty类
//
// An UnrealScript variable.
// Property的名字在基类中
//
class COREUOBJECT_API UProperty : public UField
{
    DECLARE_CASTED_CLASS_INTRINSIC_NO_CTOR(UProperty, UField, CLASS_Abstract, TEXT("/Script/CoreUObject"), CASTCLASS_UProperty, NO_API)
    DECLARE_WITHIN(UField)  // 该对象实例只能在UField类对象中(Outer关系约束)。

    // Persistent variables.
    int32       ArrayDim;     // Property维度, 例如: int  a, 维度1;  int  a[20], 维度20.  
    int32       ElementSize;   // 数组元素大小
    uint64      PropertyFlags;   // 标记
    uint16      RepIndex;   // Replication时使用

    FName       RepNotifyFunc;  // 在network replication时,变量发生变化的通知回调函数名称。

private:
    // In memory variables (generated during Link()).
    int32       Offset_Internal;    // 类的成员变量在类内存布局中的偏移量

    ELifetimeCondition BlueprintReplicationCondition;

public:
    /** In memory only: Linked list of properties from most-derived to base **/
    UProperty*  PropertyLinkNext;
    /** In memory only: Linked list of object reference properties from most-derived to base **/
    UProperty*  NextRef;
    /** In memory only: Linked list of properties requiring destruction. Note this does not include things that will be destroyed byt he native destructor **/
    UProperty*  DestructorLinkNext;
    /** In memory only: Linked list of properties requiring post constructor initialization.**/
    UProperty*  PostConstructLinkNext;

  • UBoolProperty
//
// Describes a single bit flag variable residing in a 32-bit unsigned double word.
//
class COREUOBJECT_API UBoolProperty : public UProperty
{
    DECLARE_CASTED_CLASS_INTRINSIC_NO_CTOR(UBoolProperty, UProperty, 0, TEXT("/Script/CoreUObject"), CASTCLASS_UBoolProperty, NO_API)

    // Variables.
private:

    /** Size of the bitfield/bool property. Equal to ElementSize but used to check if the property has been properly initialized (0-8, where 0 means uninitialized). */
    uint8 FieldSize;
    /** Offset from the memeber variable to the byte of the property (0-7). */
    uint8 ByteOffset;
    /** Mask of the byte byte with the property value. */
    uint8 ByteMask;
    /** Mask of the field with the property value. Either equal to ByteMask or 255 in case of 'bool' type. */
    uint8 FieldMask;

public:

+UEnumProperty

class COREUOBJECT_API UEnumProperty : public UProperty
{
    DECLARE_CASTED_CLASS_INTRINSIC(UEnumProperty, UProperty, 0, TEXT("/Script/CoreUObject"), CASTCLASS_UEnumProperty)

public:
    UEnumProperty(const FObjectInitializer& ObjectInitializer, UEnum* InEnum);
    UEnumProperty(const FObjectInitializer& ObjectInitializer, ECppProperty, int32 InOffset, uint64 InFlags, UEnum* InEnum);

    // UObject interface
    virtual void Serialize( FArchive& Ar ) override;
    static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
    virtual void GetPreloadDependencies(TArray<UObject*>& OutDeps) override;
    // End of UObject interface

    // UField interface
    virtual void AddCppProperty(UProperty* Property) override;
    // End of UField interface

    // UProperty interface
    virtual FString GetCPPMacroType( FString& ExtendedTypeText ) const  override;
    virtual FString GetCPPType( FString* ExtendedTypeText, uint32 CPPExportFlags ) const override;
    virtual FString GetCPPTypeForwardDeclaration() const override;
    virtual void LinkInternal(FArchive& Ar) override;
    virtual bool Identical( const void* A, const void* B, uint32 PortFlags ) const override;
    virtual void SerializeItem( FArchive& Ar, void* Value, void const* Defaults ) const override;
    virtual bool NetSerializeItem( FArchive& Ar, UPackageMap* Map, void* Data, TArray<uint8> * MetaData = NULL ) const override;
    virtual void ExportTextItem( FString& ValueStr, const void* PropertyValue, const void* DefaultValue, UObject* Parent, int32 PortFlags, UObject* ExportRootScope ) const override;
    virtual const TCHAR* ImportText_Internal( const TCHAR* Buffer, void* Data, int32 PortFlags, UObject* OwnerObject, FOutputDevice* ErrorText ) const override;
    virtual int32 GetMinAlignment() const override;
    virtual bool SameType(const UProperty* Other) const override;
    virtual bool ConvertFromType(const FPropertyTag& Tag, FArchive& Ar, uint8* Data, UStruct* DefaultsStruct, bool& bOutAdvanceProperty) override;
    // End of UProperty interface

    /**
     * Returns a pointer to the UEnum of this property.
     */
    FORCEINLINE UEnum* GetEnum() const
    {
        return Enum;
    }

    /**
     * Returns the numeric property which represents the integral type of the enum.
     */
    FORCEINLINE UNumericProperty* GetUnderlyingProperty() const
    {
        return UnderlyingProp;
    }

private:
    virtual uint32 GetValueTypeHashInternal(const void* Src) const override;

    friend struct UE4EnumProperty_Private::FEnumPropertyFriend;
    
#if HACK_HEADER_GENERATOR
public:
#endif
    UNumericProperty* UnderlyingProp; // The property which represents the underlying type of the enum
    UEnum* Enum; // The enum represented by this property  所属的Enum类型
};
  • UNumericProperty
    数字属性类, 其子类有 int32, int64, uint32, uint64, float, double等其它具体类型数字的属性类。
class COREUOBJECT_API UNumericProperty : public UProperty
{
    DECLARE_CASTED_CLASS_INTRINSIC(UNumericProperty, UProperty, CLASS_Abstract, TEXT("/Script/CoreUObject"), CASTCLASS_UNumericProperty)

    UNumericProperty(ECppProperty, int32 InOffset, uint64 InFlags)
        : UProperty(FObjectInitializer::Get(), EC_CppProperty, InOffset, InFlags)
    {}

    UNumericProperty( const FObjectInitializer& ObjectInitializer, ECppProperty, int32 InOffset, uint64 InFlags )
        :   UProperty( ObjectInitializer, EC_CppProperty, InOffset, InFlags )
    {}

    // UProperty interface.
    virtual const TCHAR* ImportText_Internal( const TCHAR* Buffer, void* Data, int32 PortFlags, UObject* Parent, FOutputDevice* ErrorText ) const override;

    virtual void ExportTextItem( FString& ValueStr, const void* PropertyValue, const void* DefaultValue, UObject* Parent, int32 PortFlags, UObject* ExportRootScope ) const override;
    // End of UProperty interface

    // UNumericProperty interface.

    /** Return true if this property is for a floating point number **/
    virtual bool IsFloatingPoint() const;

    /** Return true if this property is for a integral or enum type **/
    virtual bool IsInteger() const;
};

  • UObjectProperty
    对象引用属性类。
//
// Describes a reference variable to another object which may be nil.
//
class COREUOBJECT_API UObjectProperty : public TUObjectPropertyBase<UObject*>
{
    DECLARE_CASTED_CLASS_INTRINSIC(UObjectProperty, TUObjectPropertyBase<UObject*>, 0, TEXT("/Script/CoreUObject"), CASTCLASS_UObjectProperty)

    UObjectProperty(ECppProperty, int32 InOffset, uint64 InFlags, UClass* InClass)
        : TUObjectPropertyBase(FObjectInitializer::Get(), EC_CppProperty, InOffset, InFlags, InClass)
    {
    }

    UObjectProperty( const FObjectInitializer& ObjectInitializer, ECppProperty, int32 InOffset, uint64 InFlags, UClass* InClass )
        : TUObjectPropertyBase(ObjectInitializer, EC_CppProperty, InOffset, InFlags, InClass)
    {
    }

    // UHT interface
    virtual FString GetCPPMacroType( FString& ExtendedTypeText ) const  override;
    virtual FString GetCPPTypeForwardDeclaration() const override;
    // End of UHT interface

    // UProperty interface
    virtual void SerializeItem( FArchive& Ar, void* Value, void const* Defaults ) const override;
    virtual void EmitReferenceInfo(UClass& OwnerClass, int32 BaseOffset, TArray<const UStructProperty*>& EncounteredStructProps) override;
    virtual const TCHAR* ImportText_Internal(const TCHAR* Buffer, void* Data, int32 PortFlags, UObject* OwnerObject, FOutputDevice* ErrorText) const override;
    virtual bool ConvertFromType(const FPropertyTag& Tag, FArchive& Ar, uint8* Data, UStruct* DefaultsStruct, bool& bOutAdvanceProperty) override;

private:
    virtual uint32 GetValueTypeHashInternal(const void* Src) const override;
public:
    // End of UProperty interface

    // UObjectPropertyBase interface
    virtual UObject* GetObjectPropertyValue(const void* PropertyValueAddress) const override;
    virtual void SetObjectPropertyValue(void* PropertyValueAddress, UObject* Value) const override;
    virtual FString GetCPPTypeCustom(FString* ExtendedTypeText, uint32 CPPExportFlags, const FString& InnerNativeTypeName)  const override;
    // End of UObjectPropertyBase interface
};
  • UArrayProperty
    动态数组成员变量属性, 对应C++中TArray<XXX>
//
// Describes a dynamic array.
//

// need to break this out a different type so that the DECLARE_CASTED_CLASS_INTRINSIC macro can digest the comma
typedef TProperty<FScriptArray, UProperty> UArrayProperty_Super;

class COREUOBJECT_API UArrayProperty : public UArrayProperty_Super
{
    DECLARE_CASTED_CLASS_INTRINSIC(UArrayProperty, UArrayProperty_Super, 0, TEXT("/Script/CoreUObject"), CASTCLASS_UArrayProperty)

    // Variables.
    UProperty* Inner;  // 描述数组元素的类型

public:
    typedef UArrayProperty_Super::TTypeFundamentals TTypeFundamentals;
    typedef TTypeFundamentals::TCppType TCppType;

    UArrayProperty(ECppProperty, int32 InOffset, uint64 InFlags)
        : UArrayProperty_Super(FObjectInitializer::Get(), EC_CppProperty, InOffset, InFlags)
    {
    }

    UArrayProperty( const FObjectInitializer& ObjectInitializer, ECppProperty, int32 InOffset, uint64 InFlags )
    :   UArrayProperty_Super( ObjectInitializer, EC_CppProperty, InOffset, InFlags)
    {
    }

    // UObject interface
    virtual void Serialize( FArchive& Ar ) override;
    static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
    virtual void GetPreloadDependencies(TArray<UObject*>& OutDeps) override;
    // End of UObject interface

    // UField interface
    virtual void AddCppProperty( UProperty* Property ) override;
    // End of UField interface

    // UProperty interface
    virtual FString GetCPPMacroType( FString& ExtendedTypeText ) const  override;
    virtual FString GetCPPType( FString* ExtendedTypeText, uint32 CPPExportFlags ) const override;
    virtual FString GetCPPTypeForwardDeclaration() const override;
    virtual void LinkInternal(FArchive& Ar) override;
    virtual bool Identical( const void* A, const void* B, uint32 PortFlags ) const override;
    virtual void SerializeItem( FArchive& Ar, void* Value, void const* Defaults ) const override;
    virtual bool NetSerializeItem( FArchive& Ar, UPackageMap* Map, void* Data, TArray<uint8> * MetaData = NULL ) const override;
    virtual void ExportTextItem( FString& ValueStr, const void* PropertyValue, const void* DefaultValue, UObject* Parent, int32 PortFlags, UObject* ExportRootScope ) const override;
    virtual const TCHAR* ImportText_Internal( const TCHAR* Buffer, void* Data, int32 PortFlags, UObject* OwnerObject, FOutputDevice* ErrorText ) const override;
    virtual void CopyValuesInternal( void* Dest, void const* Src, int32 Count  ) const override;
    virtual void ClearValueInternal( void* Data ) const override;
    virtual void DestroyValueInternal( void* Dest ) const override;
    virtual bool PassCPPArgsByRef() const override;
    virtual void InstanceSubobjects( void* Data, void const* DefaultData, UObject* Owner, struct FObjectInstancingGraph* InstanceGraph ) override;
    virtual bool ContainsObjectReference(TArray<const UStructProperty*>& EncounteredStructProps) const override;
    virtual bool ContainsWeakObjectReference() const override;
    virtual void EmitReferenceInfo(UClass& OwnerClass, int32 BaseOffset, TArray<const UStructProperty*>& EncounteredStructProps) override;
    virtual bool SameType(const UProperty* Other) const override;
    virtual bool ConvertFromType(const FPropertyTag& Tag, FArchive& Ar, uint8* Data, UStruct* DefaultsStruct, bool& bOutAdvanceProperty) override;
    // End of UProperty interface

    FString GetCPPTypeCustom(FString* ExtendedTypeText, uint32 CPPExportFlags, const FString& InnerTypeText, const FString& InInnerExtendedTypeText) const;
};

  • UStructProperty
    描述结构体成员变量的属性。
//
// Describes a structure variable embedded in (as opposed to referenced by) 
// an object.
//
class COREUOBJECT_API UStructProperty : public UProperty
{
    DECLARE_CASTED_CLASS_INTRINSIC(UStructProperty, UProperty, 0, TEXT("/Script/CoreUObject"), CASTCLASS_UStructProperty)

    // Variables.
    class UScriptStruct* Struct;   // 该结构体类型的反射数据(元数据)
public:
    UStructProperty(ECppProperty, int32 InOffset, uint64 InFlags, UScriptStruct* InStruct);
    UStructProperty( const FObjectInitializer& ObjectInitializer, ECppProperty, int32 InOffset, uint64 InFlags, UScriptStruct* InStruct );

    // UObject interface
    virtual void Serialize( FArchive& Ar ) override;
    static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
    virtual void GetPreloadDependencies(TArray<UObject*>& OutDeps) override;
    // End of UObject interface
};

还有其它Property类,用于描述C++或蓝图的数据类型, TMap, TSet,Delegate等等。阅读源码的时候需要弄清各个字段的含义。

相关文章

  • UE4对象系统_UProperty

    UProperty(含其子类)实例描述了类的某个成员变量的反射信息。 UProperty类 UBoolProper...

  • 宏定义

    UE4入门-常见的宏-UPROPERTY[https://blog.csdn.net/u012793104/art...

  • UE4对象系统_前言

    概述 UE4的对象系统可以说是整个引擎的核心模块,其在引擎中的地位如下图: 该对象系统具有很强的扩展性,新增的类只...

  • unreal 属性宏 UPROPERTY

    关于UPROPERTY的介绍,官方是这么说的: UProperty变量通过标准C++语法及额外的描述符号进行声明,...

  • UE4对象系统_UFunction

    `UFunction UFunction对象描述了一个Object的成员函数,使之能够被脚本系统调用。UFunct...

  • UE4 Actor和Component

    UE4 Actor和Component 在UE4游戏场景中看到的所有对象皆是Actor,而Actor复杂的功能是由...

  • UE4垃圾回收

    UE4引擎为我们搭建了一套UObject对象系统,并且加入了垃圾回收机制,使我们用C++进行游戏开发时更加方便,而...

  • UE4对象系统_垃圾回收

    UE中的Object对象的回收不需要我们手动去delete,而是经过垃圾回收流程来销毁不再被引用的对象。GC使用的...

  • UE4对象系统_对象的创建和查找

    本篇文章通过调试代码进行跟踪对象的创建和查找,使用UE4 Example FirstPersonCPP工程。官方文...

  • UE4 宏

    UPROPERTY SpecifiersDescriptionsCategory指定属性在蓝图编辑器中显示的类别,...

网友评论

      本文标题:UE4对象系统_UProperty

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