Open NoTuxNoBux opened 3 years ago
Something that I also realized just now: currently I'm not sharing the behaviors with my stand-alone server - as they depend on Unity things and I don't need them -, but the behaviors contain the codes for the generated RPCs, which I then also lose.
I can call RPCs through their name, but that's already been deprecated. Thinking about this some more: wouldn't it be more logical if we move the constants to the generated network object instead of the behavior? I'm talking specifically about these lines:
public const byte RPC_YOUR_RPC_1 = 0 + 5;
public const byte RPC_YOUR_RPC_2 = 1 + 5;
This would fix the sharing problem, and it would also make more sense, since you invoke the RPCs on the network object anyway, and not the behavior - the behavior also doesn't use them for anything else.
Another option would be to generate a separate file (enum?) with these RPCs in, that could then be shared again.
The registration of the RPCs itself is another thing that would be interesting to move to the network object instead, as now the stand-alone server needs to manually register the same RPCs (in the same order), as it cannot reuse the behavior. They could fire events from the network object that are caught by the behavior in order to call the methods you have to overload.
I updated the pull request to use .NET's System.Numeric
types instead of custom types as suggested by @phalasz. This reduces the code Forge needs to maintain. I've also bound Quaternion
next to Vector4
, which uses Slerp
instead of Lerp
to fix interpolation issues.
The only downside so far is that System.Numeric is not a partial struct, so implicit operators to convert to Unity variants is no longer possible. I've introduced explicit extension methods to do this, instead.
Hello @MrWatts-Anorak, are you on the Forge discord? If so, please tag me at NFMynster#1588
This is a continuation of #310, as the original author is no longer interested in fixing the changes.
From the original PR:
I've processed some of the feedback on the pull request as well:
ToString
overrides were added for the new types for easy debugging.System.Numeric
types are now used instead of new custom types.UnityNear
was consolidated withNear
as the former already falls back to the latter, but the former doesn't work in stand-alone projects as it depends on Unity, and it was also used in network objects, which was also updated.StandAloneObjectMapper
are now part ofObjectMapper
as these new types don't conflict with the existing types and this prevents new users from being confused, as they would need to callStandAloneObjectMapper.Instance.UseAsDefault();
to get them recognized in network objects.Open questions:
FloatX
toSystem.Numerics.VectorX
, as suggested by @phalasz?~ Done.StandAloneObjectMapper
andUnityNear
are gone, we can have a single generated version that works both stand-alone and inside Unity, though dropping the Unity types above would make be required.