Reactor icon indicating copy to clipboard operation
Reactor copied to clipboard

Custom InnerNetObjects

Open D1GQ opened this issue 9 months ago • 4 comments

Introducing Custom InnerNetObjects


This PR introduces a set of improvements to make working with custom InnerNetObject easier, and more intuitive. The changes include:

  1. Comprehensive XML Documentation:

    • Added detailed documentation for key methods to improve code clarity and developer experience.
    • Examples and usage instructions are provided to help developers quickly integrate custom InnerNetObject prefabs.
  2. Utility Methods for Prefab Handling:

    • Added methods like GetNetObjPrefab<T>, SpawnNewNetObject<T>, and SpawnNetObject to simplify the process of retrieving, instantiating, and spawning custom InnerNetObject prefabs.

Key Changes:

1. GetNetObjPrefab<T>

  • Purpose: Retrieves the prefab for a custom InnerNetObject of type T.
  • Usage:
    var prefab = InnerNetObjectManager.GetNetObjPrefab<MyCustomObject>();
    

2. SpawnNewNetObject<T>

  • Purpose: Spawns a new InnerNetObject locally and on the network of type "T".
  • Usage:
    var newObject = InnerNetObjectManager.SpawnNewNetObject<MyCustomObject>(ownerId: 1, spawnFlags: SpawnFlags.None);
    

3. SpawnNetObject<T> (Extension Method)

  • Purpose: Spawns an existing InnerNetObject instance on the network.
  • Usage:
    var existingObject = new MyCustomObject();
    existingObject.SpawnNetObject(ownerId: 1, spawnFlags: SpawnFlags.None);
    

D1GQ avatar Mar 23 '25 00:03 D1GQ

i just dont get the InnerNetObject attribute, it seems really unecessary since this can be done by checking subtypes in the assembly

Pietrodjaowjao avatar Mar 23 '25 15:03 Pietrodjaowjao

I think example class should be an actual simple example of what you can do with this instead of just a stub.

Galster-dev avatar Mar 23 '25 16:03 Galster-dev

i just dont get the InnerNetObject attribute, it seems really unecessary since this can be done by checking subtypes in the assembly

The first reason is do to the issue with abstract monobehaviors and compiling it into il2cpp, second reason is I feel like it's more consistent using a attribute as the original class with Reactor, now I'm probably going to change the method of loading the prefab for it.

If y'all really want it to just be a custom subclass then I'll rework the logic.

D1GQ avatar Mar 23 '25 17:03 D1GQ

i just dont get the InnerNetObject attribute, it seems really unecessary since this can be done by checking subtypes in the assembly

I've added some changes.

D1GQ avatar Mar 23 '25 18:03 D1GQ