/// <summary> /// Gets the name of the function when exposed to a scripting system (e.g. Python) /// </summary> public bool GetScriptName(string originalName, out string name) { string scriptFunctionName = originalName; bool hasScriptFunctionName = false; string scriptName = this.GetMetaData(MDFunc.ScriptName); if (!string.IsNullOrEmpty(scriptName)) { scriptFunctionName = scriptName; hasScriptFunctionName = true; } else { // Remove the K2_ prefix (do it in a loop just incase there are multiple K2_ prefixes) IntPtr ownerClass = Native_UField.GetOwnerClass(Address); if (ownerClass != IntPtr.Zero && Native_UClass.HasAnyClassFlags(ownerClass, EClassFlags.Native)) { while (scriptFunctionName.StartsWith("K2_")) { scriptFunctionName = scriptFunctionName.Substring(3); hasScriptFunctionName = true; } } } name = scriptFunctionName; return(hasScriptFunctionName); }
/// <summary> /// Clear any metadata associated with the key /// </summary> /// <param name="key"></param> public void RemoveMetaData(string key) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.RemoveMetaData == null) { return; } using (FStringUnsafe keyUnsafe = new FStringUnsafe(key)) { Native_UField.RemoveMetaData(Address, ref keyUnsafe.Array); } }
/// <summary> /// Replacement for Step that checks the for byte code, and if none exists, then PropertyChainForCompiledIn is used. /// </summary> public void StepCompiledIn(IntPtr result) { if (Code != IntPtr.Zero) { Step(Object, result); } else { IntPtr property = PropertyChainForCompiledIn; PropertyChainForCompiledIn = Native_UField.Get_Next(PropertyChainForCompiledIn); StepExplicitProperty(result, property); } }
/// <summary> /// Find the metadata value associated with the key /// and return float /// </summary> /// <param name="key">The key to lookup in the metadata</param> /// <returns>the float value stored in the metadata.</returns> public float GetFloatMetaData(string key) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetFLOATMetaData == null) { return(0); } using (FStringUnsafe keyUnsafe = new FStringUnsafe(key)) { return(Native_UField.GetFLOATMetaData(Address, ref keyUnsafe.Array)); } }
public UClass GetClassMetaData(string key) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetClassMetaData == null) { return(null); } using (FStringUnsafe keyUnsafe = new FStringUnsafe(key)) { return(GCHelper.Find <UClass>(Native_UField.GetClassMetaData(Address, ref keyUnsafe.Array))); } }
/// <summary> /// Find the metadata value associated with the key /// and return bool /// </summary> /// <param name="key">The key to lookup in the metadata</param> /// <returns>return true if the value was true (case insensitive)</returns> public bool GetBoolMetaData(string key) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetBoolMetaData == null) { return(false); } using (FStringUnsafe keyUnsafe = new FStringUnsafe(key)) { return(Native_UField.GetBoolMetaData(Address, ref keyUnsafe.Array)); } }
private static void LateAddMetaData(ManagedUnrealReflectionBase field, IntPtr nativeField, string key) { FName keyName = new FName(key); using (FStringUnsafe displayNameUnsafe = new FStringUnsafe()) { Native_UField.GetMetaDataF(nativeField, ref keyName, ref displayNameUnsafe.Array); string displayName = displayNameUnsafe.Value; if (!string.IsNullOrEmpty(displayName)) { LateAddMetaData(field.Path, keyName, displayName, false); } } }
/// <summary> /// Sets the metadata value associated with the key /// </summary> /// <param name="key">The key to lookup in the metadata</param> /// <param name="value">The value associated with the key</param> public void SetMetaData(string key, string value) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.SetMetaData == null) { return; } using (FStringUnsafe keyUnsafe = new FStringUnsafe(key)) using (FStringUnsafe valueUnsafe = new FStringUnsafe(value)) { Native_UField.SetMetaData(Address, ref keyUnsafe.Array, ref valueUnsafe.Array); } }
/// <summary> /// Find the metadata value associated with the key /// </summary> /// <param name="key">The key to lookup in the metadata</param> /// <returns>The value associated with the key</returns> public string GetMetaData(FName key) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetMetaDataF == null) { return(null); } using (FStringUnsafe resultUnsafe = new FStringUnsafe()) { Native_UField.GetMetaDataF(Address, ref key, ref resultUnsafe.Array); return(resultUnsafe.Value); } }
/// <summary> /// Finds the localized tooltip or native tooltip as a fallback. /// </summary> /// <param name="shortTooltip">Look for a shorter version of the tooltip (falls back to the long tooltip if none was specified)</param> /// <returns>The tooltip for this object.</returns> public string GetToolTip(bool shortTooltip = false) { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetToolTip == null) { return(null); } if (Native_UField.GetToolTip != null) { using (FStringUnsafe resultUnsafe = new FStringUnsafe()) { Native_UField.GetToolTip(Address, ref resultUnsafe.Array); return(resultUnsafe.Value); } } return(null); }
/// <summary> /// Gets the display name or native display name as a fallback. /// </summary> /// <returns>The display name for this object.</returns> public string GetDisplayName() { // WITH_EDITOR || HACK_HEADER_GENERATOR if (Native_UField.GetDisplayName == null) { return(null); } if (Native_UField.GetDisplayName != null) { using (FStringUnsafe resultUnsafe = new FStringUnsafe()) { Native_UField.GetDisplayName(Address, ref resultUnsafe.Array); return(resultUnsafe.Value); } } return(null); }
/// <summary> /// Create properties / functions and link the class /// </summary> public void Initialize() { Native_UStruct.Set_Children(StaticClass, IntPtr.Zero); BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (PropertyInfo property in Type.GetProperties(propertyBindingFlags)) { if (property.GetCustomAttribute <USharpPathAttribute>() != null) { CreateProperty(StaticClass, property); } } Native_UField.Bind(StaticClass); Native_UStruct.StaticLink(StaticClass, true); firstRun = false; }
public void Bind() { Native_UField.Bind(Address); }
public void AddCppProperty(UProperty property) { Native_UField.AddCppProperty(Address, property.Address); }
private IntPtr CreateProperty(IntPtr outer, Type type, string propertyName, EPropertyType propertyType, EPropertyType innerPropertyType1, EPropertyType innerPropertyType2) { propertyType = ManagedUnrealTypes.GetPropertyType(type, propertyType); IntPtr propertyClass = ManagedUnrealTypes.GetPropertyClass(propertyType); if (propertyClass == IntPtr.Zero) { return(IntPtr.Zero); } EObjectFlags objectFlags = EObjectFlags.Public | EObjectFlags.Transient | EObjectFlags.MarkAsNative; IntPtr property = NativeReflection.NewObject(outer, propertyClass, new FName(propertyName), objectFlags); Native_UProperty.SetPropertyFlags(property, EPropertyFlags.BlueprintVisible | EPropertyFlags.BlueprintAssignable | EPropertyFlags.Edit); // Set type specific information switch (propertyType) { case EPropertyType.Array: if (!firstRun) { Native_UArrayProperty.Set_Inner(property, CreateProperty(property, typeof(int), propertyName, innerPropertyType1)); } else { Native_UArrayProperty.Set_Inner(property, CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1)); } break; case EPropertyType.Set: Native_USetProperty.Set_ElementProp(property, CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1)); break; case EPropertyType.Map: Native_UMapProperty.Set_KeyProp(property, CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1)); Native_UMapProperty.Set_ValueProp(property, CreateProperty(property, type.GenericTypeArguments[1], propertyName, innerPropertyType2)); break; case EPropertyType.Class: Native_UClassProperty.SetMetaClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address); break; case EPropertyType.Object: var v1 = ManagedUnrealTypes.GetStaticClass(type); var v2 = ManagedUnrealTypes.GetStaticClass(typeof(UObject)); Native_UObjectPropertyBase.SetPropertyClass(property, v1 == IntPtr.Zero ? v2 : v1); break; case EPropertyType.LazyObject: case EPropertyType.WeakObject: case EPropertyType.SoftObject: Native_UObjectPropertyBase.SetPropertyClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address); break; case EPropertyType.SoftClass: Native_USoftClassProperty.SetMetaClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address); break; case EPropertyType.Enum: Native_UEnumProperty.SetEnum(property, ManagedUnrealTypes.GetEnum(type)); break; case EPropertyType.Delegate: //Native_UDelegateProperty.Set_SignatureFunction(property, ManagedUnrealTypes.GetSignatureFunction(type)); break; case EPropertyType.MulticastDelegate: //Native_UMulticastDelegateProperty.Set_SignatureFunction(property, ManagedUnrealTypes.GetSignatureFunction(type)); break; } Native_UField.AddCppProperty(outer, property); return(property); }