Esempio n. 1
0
void FGameplayAttribute::SetNumericValueChecked(float NewValue, class UAttributeSet* Dest) const
{
	UNumericProperty *NumericProperty = CastChecked<UNumericProperty>(Attribute);
	void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(Dest);
	Dest->PreAttributeChange(*this, NewValue);
	NumericProperty->SetFloatingPointPropertyValue(ValuePtr, NewValue);
}
void UARAttributeBaseComponent::SetFloatValue(float InValue, FName AttributeName)
{
	if (AttributeName.IsNone())
		return;

	UNumericProperty* NumericProperty = CastChecked<UNumericProperty>(GetAttribute(AttributeName));
	void* pValue = NumericProperty->ContainerPtrToValuePtr<void>(this);
	NumericProperty->SetFloatingPointPropertyValue(pValue, InValue);
}
void URPGAttributeComponent::SetNumericValue(float value, FName AttributeName)
{
	if (!AttributeName.IsNone())
	{
		UNumericProperty* NumericProperty = CastChecked<UNumericProperty>(GetAttribute(AttributeName, this->GetClass()));
		void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(this);
		NumericProperty->SetFloatingPointPropertyValue(ValuePtr, value);
		OnAttributeChange.Broadcast(AttributeName, value);
	}
}
float URPGAttributeComponent::GetNumericValue(FName AttributeName)
{
	if (!AttributeName.IsNone())
	{
		UNumericProperty* NumericProperty = CastChecked<UNumericProperty>(GetAttribute(AttributeName, this->GetClass()));
		void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(this);
		float tempVal = 0;
		tempVal = NumericProperty->GetFloatingPointPropertyValue(ValuePtr);
		return tempVal;
	}
	return 0;
}
void FGameplayAttribute::SetNumericValueChecked(float NewValue, class UAttributeSet* Dest) const
{
	UNumericProperty *NumericProperty = CastChecked<UNumericProperty>(Attribute);
	void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(Dest);
	float OldValue = *static_cast<float*>(ValuePtr);
	Dest->PreAttributeChange(*this, NewValue);
	NumericProperty->SetFloatingPointPropertyValue(ValuePtr, NewValue);

#if ENABLE_VISUAL_LOG
	// draw a graph of the changes to the attribute in the visual logger
	AActor* OwnerActor = Dest->GetOwningAbilitySystemComponent()->OwnerActor;
	if (OwnerActor)
	{
		ABILITY_VLOG_ATTRIBUTE_GRAPH(OwnerActor, Log, GetName(), OldValue, NewValue);
	}
#endif
}
Esempio n. 6
0
float UGAAttributesBase::GetFloatValue(const FGAAttribute& AttributeIn)
{
	if ((AttributeIn.AttributeName == LastAttributeName))
	{
		if (CachedFloatPropety)
		{
			const void* ValuePtr = CachedFloatPropety->ContainerPtrToValuePtr<void>(this);
			return CachedFloatPropety->GetFloatingPointPropertyValue(ValuePtr);
		}
	}
	//LastAttributeName = AttributeIn.AttributeName;
	UNumericProperty* NumericProperty = CastChecked<UNumericProperty>(FindProperty(AttributeIn));
	CachedFloatPropety = NumericProperty;
	const void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(this);
	return NumericProperty->GetFloatingPointPropertyValue(ValuePtr);

	return 0;
}
void UAttributeSet::InitFromMetaDataTable(const UDataTable* DataTable)
{
	static const FString Context = FString(TEXT("UAttribute::BindToMetaDataTable"));

	for( TFieldIterator<UProperty> It(GetClass(), EFieldIteratorFlags::IncludeSuper) ; It ; ++It )
	{
		UProperty* Property = *It;
		UNumericProperty *NumericProperty = Cast<UNumericProperty>(Property);
		if (NumericProperty)
		{
			FString RowNameStr = FString::Printf(TEXT("%s.%s"), *Property->GetOuter()->GetName(), *Property->GetName());
		
			FAttributeMetaData * MetaData = DataTable->FindRow<FAttributeMetaData>(FName(*RowNameStr), Context, false);
			if (MetaData)
			{
				void *Data = NumericProperty->ContainerPtrToValuePtr<void>(this);
				NumericProperty->SetFloatingPointPropertyValue(Data, MetaData->BaseValue);
			}
		}
	}

	PrintDebug();
}
float FGameplayAttribute::GetNumericValueChecked(const UAttributeSet* Src) const
{
	UNumericProperty* NumericProperty = CastChecked<UNumericProperty>(Attribute);
	const void* ValuePtr = NumericProperty->ContainerPtrToValuePtr<void>(Src);
	return NumericProperty->GetFloatingPointPropertyValue(ValuePtr);
}