Facepunch/Facepunch.Steamworks

Ugc.Editor type

ZhangHuan0407 opened this issue · 0 comments

Describe the bug
Ugc.Editor is struct, not class type.

The code in the example is executable, but it is not a C# best practice.

To Reproduce
use Calling Code

Calling Code
Steamworks.Ugc.Editor

// The code you're using to call into Steamworks

using UgcEditor = Steamworks.Ugc.Editor;
UgcEditor ugcEditor;
if (xxxFlag)
    ugcEditor = UgcEditor.NewCommunityFile;
ugcEditor.WithTitle(title)
         .WithDescription("This is a description")
         //.WithContent(modDirectory)
         .WithContent("C:\\Users\\xxxx\\AppData\\LocalLow\\Company\\AppName\\Mods\\test1");
ProgressView progress = xxx;
progress.BindView(xxx);
ugcEditor.SubmitAsync(progress, null);

Expected behavior

Desktop (please complete the following information):

  • OS: Windows11 64bit
  • Unity: Unity 2021.3

Additional context
Add any other context about the problem here.

  1. When I invoke Withxxx function, C# will copy this data with 13 fields, and changed one of them(for example title).We only need one instance instead of re-copying it every time
  2. This is Microsoft suggest https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct
    Because structure types have value semantics, we recommend you define immutable structure types.
  3. Generally speaking, chain calls is class not struct. For example, DoTween.Sequence, C# StringBuilder.

I try to provide two solutions:

  1. Please warm this in ReadMe "Publish your own file" block, because this chain calls is not common...orz
using UgcEditor = Steamworks.Ugc.Editor;

            var result = UgcEditor.NewCommunityFile
                  .WithTitle("My New FIle")
                  .WithDescription("This is a description")
                  .WithContent("C:\\Users\\xxxx\\AppData\\LocalLow\\Company\\AppName\\Mods\\test1")
                  .SubmitAsync(null, (PublishResult pr) =>
                  {
                      Debug.Log(pr.Result);
                  });

// UgcEditor is struct
var ugcEditor = UgcEditor.NewCommunityFile;
var ugcEditor2 = ugcEditor.WithContent("directory path here");
// ugcEditor is not equal ugcEditor2,
// call ugcEditor.SubmitAsync() is not equal ugcEditor2.SubmitAsync()
  1. Change type to class, not struct. Or rename Steamworks.Ugc.Editor with Steamworks.Ugc.EditorStruct

People who have been bothered by this issue for 24 hours leave a message here

Same question
#722