Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 9fb8671

Browse files
committed
Add support for virtual RawDataAsset, saving it and editing Data property
(cherry picked from commit dc82233) # Conflicts: # FlaxEngine/API/Static/Content.cs
1 parent 8b4013f commit 9fb8671

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

FlaxEngine/API/BinaryAssets/RawDataAsset.Gen.cs

+28-4
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,37 @@ private RawDataAsset() : base()
2020
}
2121

2222
/// <summary>
23-
/// Gets the bytes array stored by this data container asset.
23+
/// Gets or sets the bytes array stored by this data container asset.
2424
/// </summary>
25-
/// <returns>The loaded bytes.</returns>
25+
[UnmanagedCall]
26+
public byte[] Data
27+
{
28+
#if UNIT_TEST_COMPILANT
29+
get; set;
30+
#else
31+
get { return Internal_GetData(unmanagedPtr); }
32+
set { Internal_SetData(unmanagedPtr, value); }
33+
#endif
34+
}
35+
36+
/// <summary>
37+
/// Saves asset to the file. It must be fully loaded.
38+
/// </summary>
39+
/// <remarks>
40+
/// Supported only in Editor.
41+
/// </remarks>
42+
/// <param name="path">The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate model asset.</param>
43+
/// <returns>True if cannot save data, otherwise false.</returns>
2644
#if UNIT_TEST_COMPILANT
2745
[Obsolete("Unit tests, don't support methods calls.")]
2846
#endif
2947
[UnmanagedCall]
30-
public byte[] GetData()
48+
public bool Save(string path = null)
3149
{
3250
#if UNIT_TEST_COMPILANT
3351
throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
3452
#else
35-
return Internal_GetData(unmanagedPtr);
53+
return Internal_Save(unmanagedPtr, path);
3654
#endif
3755
}
3856

@@ -41,6 +59,12 @@ public byte[] GetData()
4159
#if !UNIT_TEST_COMPILANT
4260
[MethodImpl(MethodImplOptions.InternalCall)]
4361
internal static extern byte[] Internal_GetData(IntPtr obj);
62+
63+
[MethodImpl(MethodImplOptions.InternalCall)]
64+
internal static extern void Internal_SetData(IntPtr obj, byte[] val);
65+
66+
[MethodImpl(MethodImplOptions.InternalCall)]
67+
internal static extern bool Internal_Save(IntPtr obj, string path);
4468
#endif
4569

4670
#endregion

FlaxEngine/API/Static/Content.cs

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public static T CreateVirtualAsset<T>() where T : Asset
229229
typeof(T) != typeof(IESProfile) &&
230230
typeof(T) != typeof(SkinnedModel) &&
231231
typeof(T) != typeof(CollisionData) &&
232+
typeof(T) != typeof(RawDataAsset) &&
232233
typeof(T) != typeof(Model))
233234
throw new InvalidOperationException("Asset type " + typeName + " does not support virtual assets.");
234235

0 commit comments

Comments
 (0)