New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UrlReference attempt number 2 #564
Conversation
For the extension methods I did for The methods I am referring to are:
|
Thanks for working again on this feature! It might be good to also upgrade samples. I did a quick
|
You are welcome. It has been a bit of a challenge but worth it I think. I have been wanting this feature for quite some time. I should be able to upgrade the samples some time this week. Might not be until the weekend. Not sure about Regarding my proposed changes to |
Seems working well as far as I tested. No problem to add some more method in |
[DataStyle(DataStyle.Compact)] | ||
[ReferenceSerializer] | ||
[DataSerializer(typeof(UrlReferenceDataSerializer))] | ||
public class UrlReference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if it wouldn't be better as a struct
?
Especially since we also have to check for IsEmpty
so there is two ways to have invalid values currently (either the UrlReference
instance is not set, or IsEmpty
is true). That might be little bit annoying to tests those two things everytime.
This would also remove lot of null check as well.
Not sure if all the converters and editor code will like it, but might be worth a try don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttachedReferenceManager
requires objects
because it uses a ConditionalWeakTable
to attach references. Ideally the UrlReference
types would not have a default constructor so you could not instantiate "empty" ones. But various parts of the asset stuff and UI require a default constructor for them to work. It would require a lot more changes to accomplish this without default constructors.
I have created an interface and a base class so the UrlReference
and UrlReference<T>
types can both be sealed
. I have also tidied up a bunch of things:
- Fix some formatting (remove blank likes etc.)
- Fixed/added doc comments
- Fixed some exceptions being thrown (Had parameters around the wrong way).
- Removed/sorted using statements
- Added License notice to the tops of files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about attached reference, makes sense. Thanks!
Wondering, could we do it the other way around and forbid to use null/empty string then?
i.e. if not set in editor, UrlReference
instance itself is null. If instance is set, it has to have an actual valid Url
value?
This implies UrlReference
wouldn't have an empty constructor anymore too.
Note: if annoying/complex, no need to do that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did have a couple of solutions that didn't expose the default constructor that worked mostly. For example, make the default constructor internal
and change how instantiation code works. I had a couple of different versions of this that "worked" but I wasn't too happy with the bits I changed.
Though I might have just thought of an option....
But even still, doing it this way meant that using collection properties i.e. List<UrlReference>
don't work because the UI code cannot instantiate an instance without a default constructor. So would either have to leave this feature out or change the UI code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, let's keep it like this for now, thanks.
/// <typeparam name="T">The type off asset.</typeparam> | ||
[DataStyle(DataStyle.Compact)] | ||
[DataSerializer(typeof(UrlReferenceDataSerializer<>), Mode = DataSerializerGenericMode.GenericArguments)] | ||
public sealed class UrlReference<T> : UrlReference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for this (struct
).
Might need a IUrlReference
with Url
and IsEmpty
to act as common base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see reply above.
I have put details in review response instead. |
…implement associated methods for UrlReference.
… types allowing sealing of types.
As suggested I have updated some of the samples/templates. I have updated:
Updating the (I did not look at the CSharpBeginner tutorials.) I have noticed some strange behaviour. Using the In this example the "Pipe Set" Prefab is referenced as a url and it includes the "Pipe" Prefab. But is not being marked as green. |
@dfkeenan this is expected behavior. A prefab is typically design-time only since there's a full copy of it in the scene. |
OK. I just never played with Prefabs before I guess. I just tried a small test in 3.1 and it does this. So I didn't break it, or at least not as bad as I thought. I will change it to ready for review now. But I really should create unit tests. Have you had a chance to look at the documentation PR? I had a couple of questions in there. |
fd54344b6ac8b2ed232d62dc08820239: !GameMenu.SplashScript,GameMenu.Game | ||
Id: c7c92d4b-2c04-446f-b8c5-59e9d2b989cd | ||
NextSceneUrl: 9294c606-6173-4215-a8dc-0d5043d68333:MainScene | ||
2f704fab49b226562874d765af6b6918: !GameMenu.SplashScript,GameMenu.Game |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it's been added twice as mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure about that. Hope I haven't introduced some bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do kind of remember having some issues while updating the samples. Game Studio wasn't playing nice when I was changing code. Maybe I tried removing/adding the component while trying to do it. I would just remove it but you all ready merged the change.
Pretty cool how the samples now look, with automatic type inference in the |
…tride3d#390) # Conflicts: # samples/Tutorials/CSharpBeginner/CSharpBeginner/CSharpBeginner.Game/CSharpBeginner.Game.csproj # samples/Tutorials/CSharpBeginner/CSharpBeginner/CSharpBeginner.Game/CSharpBeginner.Game.xkpkg
PR Details
This is an attempt to implement #390. Replacing PR #391.
Description
Add new type
UrlReference
and related engine and Game Studio changes.Things to-do:
UrlReference
work.UrlReference
being treated as a real asset reference so asset gets included in build and things like renaming assets works the same as for existing asset functionality.Related Issue
#390
Motivation and Context
See #390.
Types of changes
Checklist