Open AustinSmith13 opened 4 years ago
Thank you for taking the time to write this up in such detail, and for the offer to create a PR to improve the project!
There are three ways that you can do this right now, but none is ideal:
This approach solves the problem by manually editing the bindings.
To add a new abstract method, property, or event:
public abstract void Foo();
(for example) to AbstractBaseBallScript
BaseBallScript
in Bindings.cs
public override void Foo() {}
To remove an existing abstract method, property, or event:
public abstract void Foo();
(for example) from AbstractBaseBallScript
BaseBallScript
in Bindings.cs
public override void Foo() {}
This approach solves the problem by temporarily making the abstract
method, property or event virtual
so overriding is optional.
To add a new abstract method, property, or event:
public virtual void Foo() {}
(for example) to AbstractBaseBallScript
BaseTypes
array:
{
"Name": "MyGame.AbstractBaseBallScript",
"BaseTypes": [
{
"BaseName": "MyGame.BaseBallScript",
"DerivedName": "MyGame.BallScript",
"OverrideMethods": [
{
"Name": "Foo",
"ParamTypes": []
}
]
}
]
}
public virtual void Foo() {}
to public abstract void Foo();
in AbstractBaseBallScript
OverrideMethods
in the JSON configTo remove an existing abstract method, property, or event:
public abstract void Foo();
to public virtual void Foo() {}
in AbstractBaseBallScript
public virtual void Foo() {}
This approach solves the problem by removing the bindings, making changes, then re-creating the bindings.
To add a new abstract method, property, or event:
AbstractBaseBallScript
from the JSON configpublic abstract void Foo();
(for example) to AbstractBaseBallScript
AbstractBaseBallScript
by undoing step 1 in the JSON configTo remove an existing abstract method, property, or event:
AbstractBaseBallScript
from the JSON configpublic abstract void Foo();
(for example) from AbstractBaseBallScript
AbstractBaseBallScript
by undoing step 1 in the JSON configThis "Manual Editing" approach requires manual editing and temporarily shows a compiler error, but it's extremely quick to do and always guided by double-clicking the compile error.
The "Temporary Virtual" approach requires no manual editing and never produces a compiler error. It does, however, involve more steps and a fair amount of typing into the JSON config for the addition part. These steps aren't guided by compiler errors and are likely harder to figure out for most users.
The "Delete and Re-create" approach is simple and straightforward, but requires the user to perform the steps in the right order since they will not work (as you point out) after the compiler error is already present. It's not quite as guided as the "Manual Editing" approach.
Your "Delete Bindings" approach seems closest to the "Delete and Re-create" approach, except that it deletes all bindings. That's simpler, but may cause errors for code relying on other bindings being present. If that's the case, deleting all bindings will cause compiler errors and, ironically, prevent generating bindings.
Let me know if you have any ideas for other approaches. I'll try to think of some, too.
I have an idea but it makes the problem worse, but I'll post it anyways because maybe it might spark other ideas.
Mono.CecilX construct dll's instead of generating readable code (Weaving). Just an idea, makes the problem worse as you can not read anything...
--Edit-- Actually I think it could work if you never directly reference anything and instead leave that up to the weaver to resolve those references and have the dll output part of the build pipeline.
The Issue
When you create a new Abstract type for example
AbstractBaseBallScript
and you generate the bindings you getBaseBallScript
In yourBindings.cs
. Switching back to unity editor triggers a compilation and no errors. Good.If you add some more abstract functions to your
AbstractBaseBallScript
and switch back to unity editor to re-build your bindings. Unity Editor will have some Errors for you, but this does not prevent you from clicking on Generate Bindings. If you do generate bindings againGenerateBindings
is accessing an older assembly without your changes toAbstractBaseBallScript
. ThusBindings.cs
will not have your new changes and will continue to give compilation errors.The only way to fix this is to manually clear out your
Bindings.cs
, compile your code with no errors, then clickGenerate Bindings
. This results with bindings that reflect your changes.One Potential Fix
The way I have fixed this currently is by adding a new editor option
NativeScript/Delete Bindings
. I callInjectBuilders
and have them clear out the bindings for me. Now I can delete the bindings and compile without errors. One problem that still persists is you still have to fix any other errors from referencing the bindings generated class from your code-base. In my case its just a factory function.I'm not sure if this is an already solved problem. I would like to know what your thoughts are on this.
If you think the Delete Bindings is a good idea I can create another pull request as well.